Search in sources :

Example 6 with JobLifecycleListener

use of org.apache.gobblin.runtime.api.JobLifecycleListener in project incubator-gobblin by apache.

the class TestStandardGobblinInstanceLauncher method testSubmitWithTemplate.

@Test
public void testSubmitWithTemplate() throws Exception {
    StandardGobblinInstanceLauncher.Builder instanceLauncherBuilder = StandardGobblinInstanceLauncher.builder().withInstanceName("testSubmitWithTemplate");
    instanceLauncherBuilder.driver();
    StandardGobblinInstanceLauncher instanceLauncher = instanceLauncherBuilder.build();
    instanceLauncher.startAsync();
    instanceLauncher.awaitRunning(5, TimeUnit.SECONDS);
    JobSpec js1 = JobSpec.builder().withConfig(ConfigFactory.parseMap(ImmutableMap.of("numHellos", "5"))).withTemplate(new URI("resource:///gobblin/runtime/instance/SimpleHelloWorldJob.template")).build();
    ResolvedJobSpec js1Resolved = new ResolvedJobSpec(js1);
    final String eventBusId = js1Resolved.getConfig().getString(GobblinTestEventBusWriter.FULL_EVENTBUSID_KEY);
    TestingEventBusAsserter asserter = new TestingEventBusAsserter(eventBusId);
    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);
    instance.getMutableJobCatalog().put(js1);
    JobExecutionDriver jobDriver = jobDrivers.poll(10, TimeUnit.SECONDS);
    Assert.assertNotNull(jobDriver);
    JobExecutionResult jobResult = jobDriver.get(5, TimeUnit.SECONDS);
    Assert.assertTrue(jobResult.isSuccessful());
    instanceLauncher.stopAsync();
    final int numHellos = js1Resolved.getConfig().getInt(HelloWorldSource.NUM_HELLOS_FULL_KEY);
    ArrayList<String> expectedEvents = new ArrayList<>();
    for (int i = 1; i <= numHellos; ++i) {
        expectedEvents.add(HelloWorldSource.ExtractorImpl.helloMessage(i));
    }
    asserter.assertNextValuesEq(expectedEvents);
    asserter.close();
    instanceLauncher.awaitTerminated(5, TimeUnit.SECONDS);
}
Also used : ArrayList(java.util.ArrayList) DefaultJobLifecycleListenerImpl(org.apache.gobblin.runtime.std.DefaultJobLifecycleListenerImpl) URI(java.net.URI) JobExecutionResult(org.apache.gobblin.runtime.api.JobExecutionResult) TestingEventBusAsserter(org.apache.gobblin.writer.test.TestingEventBusAsserter) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) FilteredJobLifecycleListener(org.apache.gobblin.runtime.std.FilteredJobLifecycleListener) JobLifecycleListener(org.apache.gobblin.runtime.api.JobLifecycleListener) ResolvedJobSpec(org.apache.gobblin.runtime.job_spec.ResolvedJobSpec) 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)

Aggregations

JobLifecycleListener (org.apache.gobblin.runtime.api.JobLifecycleListener)6 Test (org.testng.annotations.Test)6 JobExecutionDriver (org.apache.gobblin.runtime.api.JobExecutionDriver)5 JobSpec (org.apache.gobblin.runtime.api.JobSpec)5 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)4 JobExecutionResult (org.apache.gobblin.runtime.api.JobExecutionResult)4 DefaultJobLifecycleListenerImpl (org.apache.gobblin.runtime.std.DefaultJobLifecycleListenerImpl)4 FilteredJobLifecycleListener (org.apache.gobblin.runtime.std.FilteredJobLifecycleListener)4 ResolvedJobSpec (org.apache.gobblin.runtime.job_spec.ResolvedJobSpec)3 TestingEventBusAsserter (org.apache.gobblin.writer.test.TestingEventBusAsserter)3 ArrayList (java.util.ArrayList)2 JobExecutionState (org.apache.gobblin.runtime.api.JobExecutionState)2 Config (com.typesafe.config.Config)1 URI (java.net.URI)1 JobCatalogListenersContainer (org.apache.gobblin.runtime.api.JobCatalogListenersContainer)1 JobSpecSchedulerListenersContainer (org.apache.gobblin.runtime.api.JobSpecSchedulerListenersContainer)1 JobSpecRunnable (org.apache.gobblin.runtime.instance.DefaultGobblinInstanceDriverImpl.JobSpecRunnable)1 StandardGobblinInstanceDriver (org.apache.gobblin.runtime.instance.StandardGobblinInstanceDriver)1 StandardGobblinInstanceLauncher (org.apache.gobblin.runtime.instance.StandardGobblinInstanceLauncher)1 TestingEventBuses (org.apache.gobblin.writer.test.TestingEventBuses)1