use of org.apache.gobblin.runtime.api.JobExecutionResult in project incubator-gobblin by apache.
the class TestStandardGobblinInstanceLauncher method checkLaunchJob.
private void checkLaunchJob(StandardGobblinInstanceLauncher instanceLauncher, JobSpec js1, GobblinInstanceDriver instance) throws TimeoutException, InterruptedException, ExecutionException {
JobExecutionDriver jobDriver = instance.getJobLauncher().launchJob(js1);
new Thread(jobDriver).run();
JobExecutionResult jobResult = jobDriver.get(5, TimeUnit.SECONDS);
Assert.assertTrue(jobResult.isSuccessful());
instanceLauncher.stopAsync();
instanceLauncher.awaitTerminated(5, TimeUnit.SECONDS);
Assert.assertEquals(instance.getMetrics().getUpFlag().getValue().intValue(), 0);
Assert.assertEquals(instance.getMetrics().getUptimeMs().getValue().longValue(), 0);
}
use of org.apache.gobblin.runtime.api.JobExecutionResult in project incubator-gobblin by apache.
the class TestStandardGobblinInstanceLauncher method testDirectToScheduler.
@Test
public /**
* Test running of a job when submitted directly to the scheduler
*/
void testDirectToScheduler() throws Exception {
StandardGobblinInstanceLauncher.Builder instanceLauncherBuilder = StandardGobblinInstanceLauncher.builder().withInstanceName("testDirectToScheduler");
instanceLauncherBuilder.driver();
StandardGobblinInstanceLauncher instanceLauncher = instanceLauncherBuilder.build();
instanceLauncher.startAsync();
instanceLauncher.awaitRunning(5, TimeUnit.SECONDS);
JobSpec js1 = JobSpec.builder().withConfig(ConfigFactory.parseResources("gobblin/runtime/instance/SimpleHelloWorldJob.jobconf")).build();
final StandardGobblinInstanceDriver instance = (StandardGobblinInstanceDriver) instanceLauncher.getDriver();
final ArrayBlockingQueue<JobExecutionDriver> jobDrivers = new ArrayBlockingQueue<>(1);
JobLifecycleListener js1Listener = new FilteredJobLifecycleListener(JobSpecFilter.eqJobSpecURI(js1.getUri()), new DefaultJobLifecycleListenerImpl(instance.getLog()) {
@Override
public void onJobLaunch(JobExecutionDriver jobDriver) {
super.onJobLaunch(jobDriver);
try {
jobDrivers.offer(jobDriver, 5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
instance.getLog().error("Offer interrupted.");
}
}
});
instance.registerWeakJobLifecycleListener(js1Listener);
JobSpecRunnable js1Runnable = instance.createJobSpecRunnable(js1);
instance.getJobScheduler().scheduleOnce(js1, js1Runnable);
JobExecutionDriver jobDriver = jobDrivers.poll(10, TimeUnit.SECONDS);
Assert.assertNotNull(jobDriver);
JobExecutionResult jobResult = jobDriver.get(5, TimeUnit.SECONDS);
Assert.assertTrue(jobResult.isSuccessful());
instanceLauncher.stopAsync();
instanceLauncher.awaitTerminated(5, TimeUnit.SECONDS);
}
use of org.apache.gobblin.runtime.api.JobExecutionResult in project incubator-gobblin by apache.
the class CustomTaskTest method testCustomTask.
@Test
public void testCustomTask() throws Exception {
String eventBusId = UUID.randomUUID().toString();
EventBusPublishingTaskFactory.EventListener listener = new EventBusPublishingTaskFactory.EventListener();
EventBus eventBus = TestingEventBuses.getEventBus(eventBusId);
eventBus.register(listener);
JobExecutionResult result = new EmbeddedGobblin("testJob").setConfiguration(ConfigurationKeys.SOURCE_CLASS_KEY, EventBusPublishingTaskFactory.Source.class.getName()).setConfiguration(EventBusPublishingTaskFactory.Source.NUM_TASKS_KEY, "10").setConfiguration(EventBusPublishingTaskFactory.EVENTBUS_ID_KEY, eventBusId).run();
Assert.assertTrue(result.isSuccessful());
SetMultimap<String, Integer> seenEvents = HashMultimap.create();
Set<Integer> expected = Sets.newHashSet(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
for (EventBusPublishingTaskFactory.Event event : listener.getEvents()) {
seenEvents.put(event.getType(), event.getId());
}
Assert.assertEquals(seenEvents.get("run"), expected);
Assert.assertEquals(seenEvents.get("commit"), expected);
Assert.assertEquals(seenEvents.get("publish"), expected);
}
use of org.apache.gobblin.runtime.api.JobExecutionResult in project incubator-gobblin by apache.
the class CustomTaskTest method testTaskFailsWithException.
@Test(timeOut = 30000)
public void testTaskFailsWithException() throws Exception {
// Test that the job runner fails with a reasonable amount of time if a custom task throws an exception
JobExecutionResult result = new EmbeddedGobblin("alwaysThrowsJob").setConfiguration(ConfigurationKeys.SOURCE_CLASS_KEY, FailsWithExceptionTaskFactory.Source.class.getName()).run();
Assert.assertFalse(result.isSuccessful());
}
use of org.apache.gobblin.runtime.api.JobExecutionResult in project incubator-gobblin by apache.
the class CustomTaskTest method testStatePersistence.
@Test
public void testStatePersistence() throws Exception {
File stateStore = Files.createTempDir();
stateStore.deleteOnExit();
String eventBusId = UUID.randomUUID().toString();
EventBusPublishingTaskFactory.EventListener listener = new EventBusPublishingTaskFactory.EventListener();
EventBus eventBus = TestingEventBuses.getEventBus(eventBusId);
eventBus.register(listener);
EmbeddedGobblin embeddedGobblin = new EmbeddedGobblin("testJob").setConfiguration(EventBusPublishingTaskFactory.EVENTBUS_ID_KEY, eventBusId).setConfiguration(ConfigurationKeys.SOURCE_CLASS_KEY, EventBusPublishingTaskFactory.Source.class.getName()).setConfiguration(EventBusPublishingTaskFactory.Source.NUM_TASKS_KEY, "2").setConfiguration(ConfigurationKeys.STATE_STORE_ENABLED, Boolean.toString(true)).setConfiguration(ConfigurationKeys.STATE_STORE_ROOT_DIR_KEY, stateStore.getAbsolutePath());
JobExecutionResult result = embeddedGobblin.run();
Assert.assertTrue(result.isSuccessful());
SetMultimap<String, Integer> seenEvents = HashMultimap.create();
for (EventBusPublishingTaskFactory.Event event : listener.getEvents()) {
seenEvents.put(event.getType(), event.getId());
}
Assert.assertEquals(seenEvents.get("previousState").size(), 0);
result = embeddedGobblin.run();
Assert.assertTrue(result.isSuccessful());
seenEvents = HashMultimap.create();
for (EventBusPublishingTaskFactory.Event event : listener.getEvents()) {
seenEvents.put(event.getType(), event.getId());
}
Assert.assertEquals(seenEvents.get("previousState"), Sets.newHashSet(0, 1));
}
Aggregations