You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@edgent.apache.org by vd...@apache.org on 2016/03/21 21:29:51 UTC

incubator-quarks git commit: JobRegistry unit test

Repository: incubator-quarks
Updated Branches:
  refs/heads/master 3076fc011 -> 3f95e5d8f


JobRegistry unit test


Project: http://git-wip-us.apache.org/repos/asf/incubator-quarks/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-quarks/commit/3f95e5d8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-quarks/tree/3f95e5d8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-quarks/diff/3f95e5d8

Branch: refs/heads/master
Commit: 3f95e5d8f76d32b59ea9a3f24926ac8659130f67
Parents: 3076fc0
Author: Victor Dogaru <vd...@apache.org>
Authored: Mon Mar 21 13:06:02 2016 -0700
Committer: Victor Dogaru <vd...@apache.org>
Committed: Mon Mar 21 13:06:02 2016 -0700

----------------------------------------------------------------------
 .../runtime/jobregistry/JobRegistryTest.java    | 161 +++++++++++++++++++
 1 file changed, 161 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-quarks/blob/3f95e5d8/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java
----------------------------------------------------------------------
diff --git a/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java b/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java
new file mode 100644
index 0000000..31c74af
--- /dev/null
+++ b/runtime/jobregistry/src/test/java/quarks/test/runtime/jobregistry/JobRegistryTest.java
@@ -0,0 +1,161 @@
+package quarks.test.runtime.jobregistry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import org.junit.Test;
+
+import quarks.execution.Job;
+import quarks.execution.services.job.JobRegistryService;
+import quarks.execution.services.job.JobRegistryService.EventType;
+import quarks.function.BiConsumer;
+import quarks.runtime.jobregistry.JobRegistry;
+
+public class JobRegistryTest {
+
+    @Test
+    public void testGetJob() {
+        JobRegistryService service = new JobRegistry();
+        Job job1 = new JobImpl("Job_1");
+        Job job2 = new JobImpl("Job_2");
+        service.addJob(job1);
+        service.addJob(job2);
+        
+        assertSame(job1, service.getJob("Job_1"));
+        assertSame(job2, service.getJob("Job_2"));
+    }
+
+    @Test
+    public void testAddJob() {
+        JobRegistryService service = new JobRegistry();
+        
+        service.addJob(new JobImpl("Job_1"));
+        service.addListener((et, j) ->
+            {
+                assertEquals(JobRegistryService.EventType.ADD, et);
+                assertEquals("Job_1", j.getId());
+            });
+    }
+    
+    @Test
+    public void testAddJob2() {
+        JobRegistryService service = new JobRegistry();
+        
+        service.addListener((et, j) -> {
+                assertEquals(JobRegistryService.EventType.ADD, et);
+                assertEquals("Job_1", j.getId());
+            });
+        service.addJob(new JobImpl("Job_1"));
+    }
+
+    @Test
+    public void testRemoveJob() {
+        JobRegistryService service = new JobRegistry();
+        service.addJob(new JobImpl("Job_1"));
+        service.addJob(new JobImpl("Job_2"));
+        
+        service.addListener(new JobHandler(JobRegistryService.EventType.REMOVE));
+        service.removeJob("Job_1");
+        service.removeJob("Job_2");
+    }
+
+    @Test
+    public void testUpdateJob() {
+        JobRegistryService service = new JobRegistry();
+        service.addJob(new JobImpl("Job_1"));
+        service.addJob(new JobImpl("Job_2"));
+        
+        service.addListener(new JobHandler(JobRegistryService.EventType.UPDATE));
+        service.updateJob(service.getJob("Job_1"));
+        service.updateJob(service.getJob("Job_2"));
+    }
+
+    private static class JobHandler implements BiConsumer<JobRegistryService.EventType, Job> {
+        private static final long serialVersionUID = 1L;
+        private int eventCount = 0;
+        private final JobRegistryService.EventType eventType;
+        
+        JobHandler(JobRegistryService.EventType et) {
+            this.eventType = et;
+        }
+
+        @Override
+        public void accept(EventType et, Job j) {
+            eventCount++;
+            switch (eventCount) {
+            case 1:
+            case 2:
+                assertEquals(JobRegistryService.EventType.ADD, et);
+                break;
+            case 3:
+                assertEquals(eventType, et);
+                assertEquals("Job_1", j.getId());
+                break;
+            case 4:
+                assertEquals(eventType, et);
+                assertEquals("Job_2", j.getId());
+                break;
+            }
+        }
+    }
+
+    private static class JobImpl implements Job {
+
+        private String id;
+        
+        JobImpl(String id) {
+            this.id = id;
+        }
+
+        @Override
+        public State getCurrentState() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public State getNextState() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void stateChange(Action action) throws IllegalArgumentException {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public Health getHealth() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public String getLastError() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public String getName() {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public String getId() {
+            return id;
+        }
+
+        @Override
+        public void complete() throws ExecutionException, InterruptedException {
+            throw new UnsupportedOperationException();
+        }
+
+        @Override
+        public void complete(long timeout, TimeUnit unit)
+                throws ExecutionException, InterruptedException, TimeoutException {
+            throw new UnsupportedOperationException();
+        }
+        
+    }
+}