use of org.apache.samza.runtime.ProcessorLifecycleListener in project samza by apache.
the class TestStreamProcessor method testCoordinatorStopShouldStopTheStreamProcessor.
@Test
public void testCoordinatorStopShouldStopTheStreamProcessor() {
JobCoordinator mockJobCoordinator = Mockito.mock(JobCoordinator.class);
ProcessorLifecycleListener lifecycleListener = Mockito.mock(ProcessorLifecycleListener.class);
MapConfig config = new MapConfig(ImmutableMap.of("task.shutdown.ms", "0"));
StreamProcessor streamProcessor = new StreamProcessor("TestProcessorId", config, new HashMap<>(), null, Optional.empty(), Optional.empty(), Optional.empty(), sp -> lifecycleListener, mockJobCoordinator, Mockito.mock(MetadataStore.class));
streamProcessor.state = State.RUNNING;
streamProcessor.jobCoordinatorListener.onCoordinatorStop();
assertEquals(State.STOPPED, streamProcessor.state);
Mockito.verify(lifecycleListener).afterStop();
}
use of org.apache.samza.runtime.ProcessorLifecycleListener in project samza by apache.
the class TestStreamProcessor method testOnNewJobModelShouldResultInValidStateTransitions.
@Test
public void testOnNewJobModelShouldResultInValidStateTransitions() throws Exception {
JobCoordinator mockJobCoordinator = Mockito.mock(JobCoordinator.class);
ProcessorLifecycleListener lifecycleListener = Mockito.mock(ProcessorLifecycleListener.class);
SamzaContainer mockSamzaContainer = Mockito.mock(SamzaContainer.class);
MapConfig config = new MapConfig(ImmutableMap.of("task.shutdown.ms", "0"));
StreamProcessor streamProcessor = new TestableStreamProcessor(config, new HashMap<>(), null, lifecycleListener, mockJobCoordinator, mockSamzaContainer);
streamProcessor.state = State.IN_REBALANCE;
Mockito.doNothing().when(mockSamzaContainer).run();
streamProcessor.jobCoordinatorListener.onNewJobModel("TestProcessorId", new JobModel(new MapConfig(), new HashMap<>()));
Mockito.verify(mockSamzaContainer, Mockito.times(1)).setContainerListener(any());
Mockito.verify(mockSamzaContainer, Mockito.atMost(1)).run();
}
Aggregations