Search in sources :

Example 1 with JobExecutionStateListener

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

the class TestJobExecutionStateListeners method testHappyPath.

@Test
public void testHappyPath() {
    final Logger log = LoggerFactory.getLogger(getClass() + ".testHappyPath");
    JobExecutionStateListeners listeners = new JobExecutionStateListeners(log);
    JobSpec js1 = JobSpec.builder("gobblin:test/job").withConfig(ConfigFactory.empty().withValue(ConfigurationKeys.JOB_NAME_KEY, ConfigValueFactory.fromAnyRef("myJob"))).build();
    JobExecutionUpdatable je1 = JobExecutionUpdatable.createFromJobSpec(js1);
    JobExecutionStateListener l1 = Mockito.mock(JobExecutionStateListener.class);
    JobExecutionStateListener l2 = Mockito.mock(JobExecutionStateListener.class);
    JobExecutionStateListener l3 = Mockito.mock(JobExecutionStateListener.class);
    listeners.registerStateListener(l1);
    JobExecutionState state = new JobExecutionState(js1, je1, Optional.<JobExecutionStateListener>of(listeners));
    state.setRunningState(RunningState.PENDING);
    state.setRunningState(RunningState.RUNNING);
    listeners.registerStateListener(l2);
    listeners.registerStateListener(l3);
    state.setStage("Stage1");
    listeners.unregisterStateListener(l2);
    listeners.onMetadataChange(state, "key", "oldValue", "newValue");
    Mockito.verify(l1).onStatusChange(Mockito.eq(state), Mockito.eq((RunningState) null), Mockito.eq(RunningState.PENDING));
    Mockito.verify(l1).onStatusChange(Mockito.eq(state), Mockito.eq(RunningState.PENDING), Mockito.eq(RunningState.RUNNING));
    Mockito.verify(l1).onStageTransition(Mockito.eq(state), Mockito.eq(JobExecutionState.UKNOWN_STAGE), Mockito.eq("Stage1"));
    Mockito.verify(l1).onMetadataChange(Mockito.eq(state), Mockito.eq("key"), Mockito.eq("oldValue"), Mockito.eq("newValue"));
    Mockito.verify(l2).onStageTransition(Mockito.eq(state), Mockito.eq(JobExecutionState.UKNOWN_STAGE), Mockito.eq("Stage1"));
    Mockito.verify(l3).onStageTransition(Mockito.eq(state), Mockito.eq(JobExecutionState.UKNOWN_STAGE), Mockito.eq("Stage1"));
    Mockito.verify(l3).onMetadataChange(Mockito.eq(state), Mockito.eq("key"), Mockito.eq("oldValue"), Mockito.eq("newValue"));
    Mockito.verifyNoMoreInteractions(l1);
    Mockito.verifyNoMoreInteractions(l2);
    Mockito.verifyNoMoreInteractions(l3);
}
Also used : RunningState(org.apache.gobblin.runtime.JobState.RunningState) JobExecutionState(org.apache.gobblin.runtime.api.JobExecutionState) JobSpec(org.apache.gobblin.runtime.api.JobSpec) Logger(org.slf4j.Logger) JobExecutionStateListener(org.apache.gobblin.runtime.api.JobExecutionStateListener) Test(org.testng.annotations.Test)

Aggregations

RunningState (org.apache.gobblin.runtime.JobState.RunningState)1 JobExecutionState (org.apache.gobblin.runtime.api.JobExecutionState)1 JobExecutionStateListener (org.apache.gobblin.runtime.api.JobExecutionStateListener)1 JobSpec (org.apache.gobblin.runtime.api.JobSpec)1 Logger (org.slf4j.Logger)1 Test (org.testng.annotations.Test)1