Search in sources :

Example 1 with Configurable

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

the class TestDefaultGobblinInstanceDriverImpl method testScheduling.

@Test
public void testScheduling() throws Exception {
    final Logger log = LoggerFactory.getLogger(getClass().getName() + ".testScheduling");
    final Optional<Logger> loggerOpt = Optional.of(log);
    InMemoryJobCatalog jobCatalog = new InMemoryJobCatalog(loggerOpt);
    JobSpecScheduler scheduler = Mockito.mock(JobSpecScheduler.class);
    JobExecutionLauncher jobLauncher = Mockito.mock(JobExecutionLauncher.class);
    Configurable sysConfig = DefaultConfigurableImpl.createFromConfig(ConfigFactory.empty());
    final DefaultGobblinInstanceDriverImpl driver = new StandardGobblinInstanceDriver("testScheduling", sysConfig, jobCatalog, scheduler, jobLauncher, Optional.<MetricContext>absent(), loggerOpt, Collections.<GobblinInstancePluginFactory>emptyList(), SharedResourcesBrokerFactory.createDefaultTopLevelBroker(ConfigFactory.empty(), GobblinScopeTypes.GLOBAL.defaultScopeInstance()));
    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();
    driver.startAsync().awaitRunning(1000, TimeUnit.MILLISECONDS);
    long startTimeMs = System.currentTimeMillis();
    Assert.assertTrue(driver.isRunning());
    Assert.assertTrue(driver.isInstrumentationEnabled());
    Assert.assertNotNull(driver.getMetricContext());
    jobCatalog.put(js1_1);
    AssertWithBackoff awb = AssertWithBackoff.create().backoffFactor(1.5).maxSleepMs(100).timeoutMs(1000).logger(log);
    awb.assertTrue(new Predicate<Void>() {

        @Override
        public boolean apply(Void input) {
            log.debug("upFlag=" + driver.getMetrics().getUpFlag().getValue().intValue());
            return driver.getMetrics().getUpFlag().getValue().intValue() == 1;
        }
    }, "upFlag==1");
    jobCatalog.put(js2);
    jobCatalog.put(js1_2);
    jobCatalog.remove(js2.getUri());
    Mockito.when(scheduler.scheduleJob(Mockito.eq(js1_1), Mockito.any(DefaultGobblinInstanceDriverImpl.JobSpecRunnable.class))).thenReturn(DefaultJobSpecScheduleImpl.createNoSchedule(js1_1, null));
    Mockito.when(scheduler.scheduleJob(Mockito.eq(js2), Mockito.any(DefaultGobblinInstanceDriverImpl.JobSpecRunnable.class))).thenReturn(DefaultJobSpecScheduleImpl.createNoSchedule(js2, null));
    Mockito.when(scheduler.scheduleJob(Mockito.eq(js1_2), Mockito.any(DefaultGobblinInstanceDriverImpl.JobSpecRunnable.class))).thenReturn(DefaultJobSpecScheduleImpl.createNoSchedule(js1_2, null));
    Mockito.verify(scheduler).scheduleJob(Mockito.eq(js1_1), Mockito.any(DefaultGobblinInstanceDriverImpl.JobSpecRunnable.class));
    Mockito.verify(scheduler).scheduleJob(Mockito.eq(js2), Mockito.any(DefaultGobblinInstanceDriverImpl.JobSpecRunnable.class));
    Mockito.verify(scheduler).scheduleJob(Mockito.eq(js1_2), Mockito.any(DefaultGobblinInstanceDriverImpl.JobSpecRunnable.class));
    Mockito.verify(scheduler).unscheduleJob(Mockito.eq(js2.getUri()));
    final long elapsedMs = System.currentTimeMillis() - startTimeMs;
    awb.assertTrue(new Predicate<Void>() {

        @Override
        public boolean apply(Void input) {
            long uptimeMs = driver.getMetrics().getUptimeMs().getValue().longValue();
            return uptimeMs >= elapsedMs;
        }
    }, "uptime > elapsedMs");
    long uptimeMs = driver.getMetrics().getUptimeMs().getValue().longValue();
    Assert.assertTrue(uptimeMs <= 2 * elapsedMs, "uptime=" + uptimeMs + " elapsedMs=" + elapsedMs);
    driver.stopAsync();
    driver.awaitTerminated(100, TimeUnit.MILLISECONDS);
    Assert.assertEquals(driver.state(), State.TERMINATED);
    Assert.assertEquals(driver.getMetrics().getUpFlag().getValue().intValue(), 0);
    // Need an assert with retries because Guava service container notifications are async
    awb.assertTrue(new Predicate<Void>() {

        @Override
        public boolean apply(Void input) {
            log.debug("upTimeMs=" + driver.getMetrics().getUptimeMs().getValue().longValue());
            return driver.getMetrics().getUptimeMs().getValue().longValue() == 0;
        }
    }, "upTimeMs==0");
}
Also used : JobSpecScheduler(org.apache.gobblin.runtime.api.JobSpecScheduler) Configurable(org.apache.gobblin.runtime.api.Configurable) Logger(org.slf4j.Logger) InMemoryJobCatalog(org.apache.gobblin.runtime.job_catalog.InMemoryJobCatalog) AssertWithBackoff(org.apache.gobblin.testing.AssertWithBackoff) JobSpec(org.apache.gobblin.runtime.api.JobSpec) JobExecutionLauncher(org.apache.gobblin.runtime.api.JobExecutionLauncher) Test(org.testng.annotations.Test)

Aggregations

Configurable (org.apache.gobblin.runtime.api.Configurable)1 JobExecutionLauncher (org.apache.gobblin.runtime.api.JobExecutionLauncher)1 JobSpec (org.apache.gobblin.runtime.api.JobSpec)1 JobSpecScheduler (org.apache.gobblin.runtime.api.JobSpecScheduler)1 InMemoryJobCatalog (org.apache.gobblin.runtime.job_catalog.InMemoryJobCatalog)1 AssertWithBackoff (org.apache.gobblin.testing.AssertWithBackoff)1 Logger (org.slf4j.Logger)1 Test (org.testng.annotations.Test)1