Search in sources :

Example 11 with JobExecutionResult

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);
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver)

Example 12 with JobExecutionResult

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);
}
Also used : DefaultJobLifecycleListenerImpl(org.apache.gobblin.runtime.std.DefaultJobLifecycleListenerImpl) JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) JobSpecRunnable(org.apache.gobblin.runtime.instance.DefaultGobblinInstanceDriverImpl.JobSpecRunnable) FilteredJobLifecycleListener(org.apache.gobblin.runtime.std.FilteredJobLifecycleListener) JobLifecycleListener(org.apache.gobblin.runtime.api.JobLifecycleListener) JobSpec(org.apache.gobblin.runtime.api.JobSpec) ResolvedJobSpec(org.apache.gobblin.runtime.job_spec.ResolvedJobSpec) JobExecutionDriver(org.apache.gobblin.runtime.api.JobExecutionDriver) FilteredJobLifecycleListener(org.apache.gobblin.runtime.std.FilteredJobLifecycleListener) Test(org.testng.annotations.Test)

Example 13 with JobExecutionResult

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);
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) EventBus(com.google.common.eventbus.EventBus) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) Test(org.testng.annotations.Test)

Example 14 with JobExecutionResult

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());
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) Test(org.testng.annotations.Test)

Example 15 with JobExecutionResult

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));
}
Also used : JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) EventBus(com.google.common.eventbus.EventBus) EmbeddedGobblin(org.apache.gobblin.runtime.embedded.EmbeddedGobblin) File(java.io.File) Test(org.testng.annotations.Test)

Aggregations

JobExecutionResult (org.apache.gobblin.runtime.api.JobExecutionResult)21 Test (org.testng.annotations.Test)18 EmbeddedGobblin (org.apache.gobblin.runtime.embedded.EmbeddedGobblin)12 File (java.io.File)9 JobExecutionDriver (org.apache.gobblin.runtime.api.JobExecutionDriver)8 GenericRecord (org.apache.avro.generic.GenericRecord)7 JobSpec (org.apache.gobblin.runtime.api.JobSpec)5 TestingEventBusAsserter (org.apache.gobblin.writer.test.TestingEventBusAsserter)5 ArrayList (java.util.ArrayList)4 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)4 JobLifecycleListener (org.apache.gobblin.runtime.api.JobLifecycleListener)4 ResolvedJobSpec (org.apache.gobblin.runtime.job_spec.ResolvedJobSpec)4 DefaultJobLifecycleListenerImpl (org.apache.gobblin.runtime.std.DefaultJobLifecycleListenerImpl)4 FilteredJobLifecycleListener (org.apache.gobblin.runtime.std.FilteredJobLifecycleListener)4 EventBus (com.google.common.eventbus.EventBus)3 StandardGobblinInstanceDriver (org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver)2 Path (org.apache.hadoop.fs.Path)2 Config (com.typesafe.config.Config)1 IOException (java.io.IOException)1 URI (java.net.URI)1