Search in sources :

Example 11 with ProcessorLifecycleListener

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();
}
Also used : MetadataStore(org.apache.samza.metadatastore.MetadataStore) JobCoordinator(org.apache.samza.coordinator.JobCoordinator) MapConfig(org.apache.samza.config.MapConfig) ProcessorLifecycleListener(org.apache.samza.runtime.ProcessorLifecycleListener) Test(org.junit.Test)

Example 12 with ProcessorLifecycleListener

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();
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) JobCoordinator(org.apache.samza.coordinator.JobCoordinator) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) ProcessorLifecycleListener(org.apache.samza.runtime.ProcessorLifecycleListener) SamzaContainer(org.apache.samza.container.SamzaContainer) Test(org.junit.Test)

Aggregations

MapConfig (org.apache.samza.config.MapConfig)12 JobCoordinator (org.apache.samza.coordinator.JobCoordinator)12 ProcessorLifecycleListener (org.apache.samza.runtime.ProcessorLifecycleListener)12 Test (org.junit.Test)11 MetadataStore (org.apache.samza.metadatastore.MetadataStore)7 SamzaContainer (org.apache.samza.container.SamzaContainer)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 StreamTaskFactory (org.apache.samza.task.StreamTaskFactory)5 ExecutorService (java.util.concurrent.ExecutorService)4 TimeoutException (java.util.concurrent.TimeoutException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 SamzaException (org.apache.samza.SamzaException)4 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Config (org.apache.samza.config.Config)3 TaskConfig (org.apache.samza.config.TaskConfig)3 RunLoop (org.apache.samza.container.RunLoop)3 JobModel (org.apache.samza.job.model.JobModel)3 StreamTask (org.apache.samza.task.StreamTask)3 ImmutableMap (com.google.common.collect.ImmutableMap)2