Search in sources :

Example 1 with RunningState

use of org.apache.gobblin.runtime.JobState.RunningState 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)

Example 2 with RunningState

use of org.apache.gobblin.runtime.JobState.RunningState in project incubator-gobblin by apache.

the class JobExecutionState method doRunningStateChange.

// This must be called only when holding changeLock
private void doRunningStateChange(RunningState newState) {
    RunningState oldState = null;
    JobExecutionStateListener stateListener = null;
    this.changeLock.lock();
    try {
        // verify transition
        if (null == this.runningState) {
            Preconditions.checkState(RunningState.PENDING == newState);
        } else {
            Preconditions.checkState(EXPECTED_PRE_TRANSITION_STATES.get(newState).contains(this.runningState), "unexpected state transition " + this.runningState + " --> " + newState);
        }
        oldState = this.runningState;
        this.runningState = newState;
        if (this.listener.isPresent()) {
            stateListener = this.listener.get();
        }
        this.runningStateChanged.signalAll();
    } finally {
        this.changeLock.unlock();
    }
    if (null != stateListener) {
        stateListener.onStatusChange(this, oldState, newState);
    }
}
Also used : RunningState(org.apache.gobblin.runtime.JobState.RunningState)

Aggregations

RunningState (org.apache.gobblin.runtime.JobState.RunningState)2 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