use of org.apache.gobblin.runtime.api.JobCatalogListener in project incubator-gobblin by apache.
the class TestMutableCachingJobCatalog method test.
@Test
public void test() throws Exception {
InMemoryJobCatalog baseCat = new InMemoryJobCatalog(Optional.<Logger>of(LoggerFactory.getLogger("baseCat")));
baseCat.startAsync();
baseCat.awaitRunning(2, TimeUnit.SECONDS);
MutableCachingJobCatalog cachedCat = new MutableCachingJobCatalog(baseCat, Optional.<Logger>of(LoggerFactory.getLogger("cachedCat")));
JobCatalogListener l = Mockito.mock(JobCatalogListener.class);
cachedCat.addListener(l);
cachedCat.startAsync();
cachedCat.awaitRunning(10, TimeUnit.SECONDS);
JobSpec js1_1 = JobSpec.builder("test:job1").withVersion("1").build();
JobSpec js1_2 = JobSpec.builder("test:job1").withVersion("2").build();
JobSpec js1_3 = JobSpec.builder("test:job1").withVersion("3").build();
URI jsURI = new URI("test:job1");
baseCat.put(js1_1);
JobSpec res = cachedCat.getJobSpec(new URI("test:job1"));
Assert.assertEquals(res, js1_1);
baseCat.put(js1_2);
res = cachedCat.getJobSpec(jsURI);
Assert.assertEquals(res, js1_2);
baseCat.remove(jsURI);
try {
cachedCat.getJobSpec(jsURI);
Assert.fail("Expected JobSpecNotFoundException");
} catch (JobSpecNotFoundException e) {
Assert.assertEquals(e.getMissingJobSpecURI(), jsURI);
}
cachedCat.removeListener(l);
cachedCat.put(js1_3);
res = cachedCat.getJobSpec(jsURI);
Assert.assertEquals(res, js1_3);
res = baseCat.getJobSpec(jsURI);
Assert.assertEquals(res, js1_3);
cachedCat.remove(jsURI);
try {
cachedCat.getJobSpec(jsURI);
Assert.fail("Expected JobSpecNotFoundException");
} catch (JobSpecNotFoundException e) {
Assert.assertEquals(e.getMissingJobSpecURI(), jsURI);
}
try {
baseCat.getJobSpec(jsURI);
Assert.fail("Expected JobSpecNotFoundException");
} catch (JobSpecNotFoundException e) {
Assert.assertEquals(e.getMissingJobSpecURI(), jsURI);
}
Mockito.verify(l).onAddJob(Mockito.eq(js1_1));
Mockito.verify(l).onUpdateJob(Mockito.eq(js1_2));
Mockito.verify(l).onDeleteJob(Mockito.eq(js1_2.getUri()), Mockito.eq(js1_2.getVersion()));
Mockito.verifyNoMoreInteractions(l);
cachedCat.stopAsync();
cachedCat.awaitTerminated(10, TimeUnit.SECONDS);
baseCat.stopAsync();
baseCat.awaitTerminated(2, TimeUnit.SECONDS);
}
use of org.apache.gobblin.runtime.api.JobCatalogListener in project incubator-gobblin by apache.
the class TestNonObservingFSJobCatalog method testCallbacks.
@Test
public void testCallbacks() throws Exception {
this.jobConfigDir = java.nio.file.Files.createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName())).toFile();
this.jobConfigDirPath = new Path(this.jobConfigDir.getPath());
try (PrintWriter printWriter = new PrintWriter(new Path(jobConfigDirPath, "job3.template").toString(), "UTF-8")) {
printWriter.println("param1 = value1");
printWriter.println("param2 = value2");
}
Properties properties = new Properties();
properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.jobConfigDir.getPath());
NonObservingFSJobCatalog cat = new NonObservingFSJobCatalog(ConfigUtils.propertiesToConfig(properties));
cat.startAsync();
cat.awaitRunning(10, TimeUnit.SECONDS);
final Map<URI, JobSpec> specs = new Hashtable<>();
JobCatalogListener l = Mockito.mock(JobCatalogListener.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
JobSpec spec = (JobSpec) invocation.getArguments()[0];
specs.put(spec.getUri(), spec);
return null;
}
}).when(l).onAddJob(Mockito.any(JobSpec.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
JobSpec spec = (JobSpec) invocation.getArguments()[0];
specs.put(spec.getUri(), spec);
return null;
}
}).when(l).onUpdateJob(Mockito.any(JobSpec.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
URI uri = (URI) invocation.getArguments()[0];
specs.remove(uri);
return null;
}
}).when(l).onDeleteJob(Mockito.any(URI.class), Mockito.anyString());
JobSpec js1_1 = JobSpec.builder("test_job1").withVersion("1").build();
JobSpec js1_2 = JobSpec.builder("test_job1").withVersion("2").build();
JobSpec js2 = JobSpec.builder("test_job2").withVersion("1").build();
JobSpec js3 = JobSpec.builder("test_job3").withVersion("1").withTemplate(new URI("FS:///job3.template")).withConfig(ConfigBuilder.create().addPrimitive("job.template", "FS:///job3.template").build()).build();
cat.addListener(l);
cat.put(js1_1);
Assert.assertTrue(specs.containsKey(js1_1.getUri()));
JobSpec js1_1_notified = specs.get(js1_1.getUri());
Assert.assertTrue(ConfigUtils.verifySubset(js1_1_notified.getConfig(), js1_1.getConfig()));
Assert.assertEquals(js1_1.getVersion(), js1_1_notified.getVersion());
cat.put(js1_2);
Assert.assertTrue(specs.containsKey(js1_2.getUri()));
JobSpec js1_2_notified = specs.get(js1_2.getUri());
Assert.assertTrue(ConfigUtils.verifySubset(js1_2_notified.getConfig(), js1_2.getConfig()));
Assert.assertEquals(js1_2.getVersion(), js1_2_notified.getVersion());
cat.put(js2);
Assert.assertTrue(specs.containsKey(js2.getUri()));
JobSpec js2_notified = specs.get(js2.getUri());
Assert.assertTrue(ConfigUtils.verifySubset(js2_notified.getConfig(), js2.getConfig()));
Assert.assertEquals(js2.getVersion(), js2_notified.getVersion());
cat.remove(js2.getUri());
Assert.assertFalse(specs.containsKey(js2.getUri()));
cat.put(js3);
Assert.assertTrue(specs.containsKey(js3.getUri()));
JobSpec js3_notified = specs.get(js3.getUri());
Assert.assertTrue(ConfigUtils.verifySubset(js3_notified.getConfig(), js3.getConfig()));
Assert.assertEquals(js3.getVersion(), js3_notified.getVersion());
ResolvedJobSpec js3_resolved = new ResolvedJobSpec(js3_notified, cat);
Assert.assertEquals(js3_resolved.getConfig().getString("param1"), "value1");
Assert.assertEquals(js3_resolved.getConfig().getString("param2"), "value2");
cat.stopAsync();
cat.awaitTerminated(10, TimeUnit.SECONDS);
}
use of org.apache.gobblin.runtime.api.JobCatalogListener in project incubator-gobblin by apache.
the class TestFSJobCatalog method testCallbacks.
@Test
public void testCallbacks() throws Exception {
this.jobConfigDir = java.nio.file.Files.createTempDirectory(String.format("gobblin-test_%s_job-conf", this.getClass().getSimpleName())).toFile();
this.jobConfigDirPath = new Path(this.jobConfigDir.getPath());
try (PrintWriter printWriter = new PrintWriter(new Path(jobConfigDirPath, "job3.template").toString(), "UTF-8")) {
printWriter.println("param1 = value1");
printWriter.println("param2 = value2");
}
Properties properties = new Properties();
properties.setProperty(ConfigurationKeys.JOB_CONFIG_FILE_GENERAL_PATH_KEY, this.jobConfigDir.getPath());
PathAlterationObserver observer = new PathAlterationObserver(this.jobConfigDirPath);
/* Exposed the observer so that checkAndNotify can be manually invoked. */
FSJobCatalog cat = new FSJobCatalog(ConfigUtils.propertiesToConfig(properties), observer);
cat.startAsync();
cat.awaitRunning(10, TimeUnit.SECONDS);
final Map<URI, JobSpec> specs = new Hashtable<>();
JobCatalogListener l = Mockito.mock(JobCatalogListener.class);
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
JobSpec spec = (JobSpec) invocation.getArguments()[0];
specs.put(spec.getUri(), spec);
return null;
}
}).when(l).onAddJob(Mockito.any(JobSpec.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
JobSpec spec = (JobSpec) invocation.getArguments()[0];
specs.put(spec.getUri(), spec);
return null;
}
}).when(l).onUpdateJob(Mockito.any(JobSpec.class));
Mockito.doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
URI uri = (URI) invocation.getArguments()[0];
specs.remove(uri);
return null;
}
}).when(l).onDeleteJob(Mockito.any(URI.class), Mockito.anyString());
JobSpec js1_1 = JobSpec.builder("test_job1").withVersion("1").build();
JobSpec js1_2 = JobSpec.builder("test_job1").withVersion("2").build();
JobSpec js2 = JobSpec.builder("test_job2").withVersion("1").build();
JobSpec js3 = JobSpec.builder("test_job3").withVersion("1").withTemplate(new URI("FS:///job3.template")).withConfig(ConfigBuilder.create().addPrimitive("job.template", "FS:///job3.template").build()).build();
cat.addListener(l);
observer.initialize();
cat.put(js1_1);
// enough time for file creation.
observer.checkAndNotify();
Assert.assertTrue(specs.containsKey(js1_1.getUri()));
JobSpec js1_1_notified = specs.get(js1_1.getUri());
Assert.assertTrue(ConfigUtils.verifySubset(js1_1_notified.getConfig(), js1_1.getConfig()));
Assert.assertEquals(js1_1.getVersion(), js1_1_notified.getVersion());
// Linux system has too large granularity for the modification time.
Thread.sleep(1000);
cat.put(js1_2);
// enough time for file replacement.
observer.checkAndNotify();
Assert.assertTrue(specs.containsKey(js1_2.getUri()));
JobSpec js1_2_notified = specs.get(js1_2.getUri());
Assert.assertTrue(ConfigUtils.verifySubset(js1_2_notified.getConfig(), js1_2.getConfig()));
Assert.assertEquals(js1_2.getVersion(), js1_2_notified.getVersion());
Thread.sleep(1000);
cat.put(js2);
observer.checkAndNotify();
Assert.assertTrue(specs.containsKey(js2.getUri()));
JobSpec js2_notified = specs.get(js2.getUri());
Assert.assertTrue(ConfigUtils.verifySubset(js2_notified.getConfig(), js2.getConfig()));
Assert.assertEquals(js2.getVersion(), js2_notified.getVersion());
Thread.sleep(1000);
cat.remove(js2.getUri());
// enough time for file deletion.
observer.checkAndNotify();
Assert.assertFalse(specs.containsKey(js2.getUri()));
Thread.sleep(1000);
cat.put(js3);
observer.checkAndNotify();
Assert.assertTrue(specs.containsKey(js3.getUri()));
JobSpec js3_notified = specs.get(js3.getUri());
Assert.assertTrue(ConfigUtils.verifySubset(js3_notified.getConfig(), js3.getConfig()));
Assert.assertEquals(js3.getVersion(), js3_notified.getVersion());
ResolvedJobSpec js3_resolved = new ResolvedJobSpec(js3_notified, cat);
Assert.assertEquals(js3_resolved.getConfig().getString("param1"), "value1");
Assert.assertEquals(js3_resolved.getConfig().getString("param2"), "value2");
cat.stopAsync();
cat.awaitTerminated(10, TimeUnit.SECONDS);
}
use of org.apache.gobblin.runtime.api.JobCatalogListener in project incubator-gobblin by apache.
the class TestInMemoryJobCatalog method testCallbacks.
@Test
public void testCallbacks() throws Exception {
InMemoryJobCatalog cat = new InMemoryJobCatalog();
cat.startAsync();
cat.awaitRunning(1, TimeUnit.SECONDS);
JobCatalogListener l = Mockito.mock(JobCatalogListener.class);
JobSpec js1_1 = JobSpec.builder("test:job1").withVersion("1").build();
JobSpec js1_2 = JobSpec.builder("test:job1").withVersion("2").build();
JobSpec js1_3 = JobSpec.builder("test:job1").withVersion("3").build();
JobSpec js2 = JobSpec.builder("test:job2").withVersion("1").build();
cat.put(js1_1);
cat.addListener(l);
cat.put(js1_2);
cat.put(js2);
cat.put(js1_3);
cat.remove(js2.getUri());
cat.remove(new URI("test:dummy_job"));
cat.removeListener(l);
cat.remove(js1_3.getUri());
Mockito.verify(l).onAddJob(Mockito.eq(js1_1));
Mockito.verify(l).onUpdateJob(Mockito.eq(js1_2));
Mockito.verify(l).onAddJob(Mockito.eq(js2));
Mockito.verify(l).onUpdateJob(Mockito.eq(js1_3));
Mockito.verify(l).onDeleteJob(Mockito.eq(js2.getUri()), Mockito.eq(js2.getVersion()));
Mockito.verifyNoMoreInteractions(l);
cat.stopAsync();
cat.awaitTerminated(1, TimeUnit.SECONDS);
}
use of org.apache.gobblin.runtime.api.JobCatalogListener in project incubator-gobblin by apache.
the class TestJobCatalogListenersList method testCalls.
@Test
public void testCalls() {
JobCatalogListenersList ll = new JobCatalogListenersList();
JobSpec js1_1 = JobSpec.builder("test:job1").build();
JobSpec js1_2 = JobSpec.builder("test:job1").withVersion("2").build();
JobSpec js2 = JobSpec.builder("test:job2").build();
JobCatalogListener l1 = Mockito.mock(JobCatalogListener.class);
Mockito.doThrow(new RuntimeException("injected l1 failure")).when(l1).onDeleteJob(Mockito.eq(js2.getUri()), Mockito.eq(js2.getVersion()));
JobCatalogListener l2 = Mockito.mock(JobCatalogListener.class);
Mockito.doThrow(new RuntimeException("injected l2 failure")).when(l2).onUpdateJob(Mockito.eq(js1_2));
JobCatalogListener l3 = Mockito.mock(JobCatalogListener.class);
Mockito.doThrow(new RuntimeException("injected l3 failure")).when(l3).onAddJob(Mockito.eq(js2));
ll.addListener(l1);
ll.addListener(l2);
ll.addListener(l3);
ll.onAddJob(js1_1);
ll.onAddJob(js2);
ll.onUpdateJob(js1_2);
ll.onDeleteJob(js2.getUri(), js2.getVersion());
Mockito.verify(l1).onAddJob(Mockito.eq(js1_1));
Mockito.verify(l1).onAddJob(Mockito.eq(js2));
Mockito.verify(l1).onUpdateJob(Mockito.eq(js1_2));
Mockito.verify(l1).onDeleteJob(Mockito.eq(js2.getUri()), Mockito.eq(js2.getVersion()));
Mockito.verify(l2).onAddJob(Mockito.eq(js1_1));
Mockito.verify(l2).onAddJob(Mockito.eq(js2));
Mockito.verify(l2).onUpdateJob(Mockito.eq(js1_2));
Mockito.verify(l2).onDeleteJob(Mockito.eq(js2.getUri()), Mockito.eq(js2.getVersion()));
Mockito.verify(l3).onAddJob(Mockito.eq(js1_1));
Mockito.verify(l3).onAddJob(Mockito.eq(js2));
Mockito.verify(l3).onUpdateJob(Mockito.eq(js1_2));
Mockito.verify(l3).onDeleteJob(Mockito.eq(js2.getUri()), Mockito.eq(js2.getVersion()));
Mockito.verifyNoMoreInteractions(l1, l2, l3);
}
Aggregations