use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.
the class TestZkJobCoordinator method testShouldStopPartitionCountMonitorOnSessionExpiration.
@Test
public void testShouldStopPartitionCountMonitorOnSessionExpiration() {
when(zkUtils.getJobModel(TEST_JOB_MODEL_VERSION)).thenReturn(new JobModel(new MapConfig(), new HashMap<>()));
ScheduleAfterDebounceTime mockDebounceTimer = Mockito.mock(ScheduleAfterDebounceTime.class);
ZkJobCoordinator zkJobCoordinator = Mockito.spy(new ZkJobCoordinator(PROCESSOR_ID, new MapConfig(), new NoOpMetricsRegistry(), zkUtils, zkMetadataStore, coordinatorStreamStore));
StreamPartitionCountMonitor monitor = Mockito.mock(StreamPartitionCountMonitor.class);
zkJobCoordinator.debounceTimer = mockDebounceTimer;
zkJobCoordinator.streamPartitionCountMonitor = monitor;
ZkSessionStateChangedListener zkSessionStateChangedListener = zkJobCoordinator.new ZkSessionStateChangedListener();
zkSessionStateChangedListener.handleStateChanged(Watcher.Event.KeeperState.Expired);
Mockito.verify(monitor).stop();
}
use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.
the class TestStaticResourceJobCoordinator method testSameDeploymentWithNewJobModel.
@Test
public void testSameDeploymentWithNewJobModel() throws IOException {
Config jobModelConfig = mock(Config.class);
JobModel jobModel = setupJobModel(jobModelConfig);
StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
StreamRegexMonitor streamRegexMonitor = setupStreamRegexMonitor(jobModel, jobModelConfig);
setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.of(JobMetadataChange.JOB_MODEL), true);
setUpDiagnosticsManager(jobModel);
this.staticResourceJobCoordinator.start();
verifyStartLifecycle();
verify(this.jobRestartSignal).restartJob();
assertNull(this.staticResourceJobCoordinator.getJobModel());
verifyNoSideEffects(streamPartitionCountMonitor, streamRegexMonitor);
}
use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.
the class TestStaticResourceJobCoordinator method testStopMissingOptionalComponents.
@Test
public void testStopMissingOptionalComponents() {
this.staticResourceJobCoordinator = spy(new StaticResourceJobCoordinator(PROCESSOR_ID, this.jobModelHelper, this.jobModelServingContext, this.coordinatorCommunication, this.jobCoordinatorMetadataManager, this.streamPartitionCountMonitorFactory, this.streamRegexMonitorFactory, Optional.empty(), this.changelogStreamManager, this.jobRestartSignal, this.metrics, this.systemAdmins, Optional.empty(), Optional.empty(), this.config));
Config jobModelConfig = mock(Config.class);
JobModel jobModel = setupJobModel(jobModelConfig);
StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
when(this.streamRegexMonitorFactory.build(any(), any(), any())).thenReturn(Optional.empty());
setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.copyOf(Arrays.asList(JobMetadataChange.values())), false);
doReturn(Optional.empty()).when(this.staticResourceJobCoordinator).buildDiagnosticsManager(JOB_NAME, JOB_ID, jobModel, CoordinationConstants.JOB_COORDINATOR_CONTAINER_NAME, Optional.empty(), Optional.empty(), this.config);
metadataResourceUtil(jobModel);
// call start in order to set up monitors
this.staticResourceJobCoordinator.start();
this.staticResourceJobCoordinator.stop();
verify(streamPartitionCountMonitor).stop();
verify(this.coordinatorCommunication).stop();
verify(this.systemAdmins).stop();
verifyZeroInteractions(this.jobCoordinatorListener);
}
use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.
the class TestStaticResourceJobCoordinator method testStreamRegexChange.
@Test
public void testStreamRegexChange() throws IOException {
Config jobModelConfig = mock(Config.class);
JobModel jobModel = setupJobModel(jobModelConfig);
StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
StreamRegexMonitor streamRegexMonitor = mock(StreamRegexMonitor.class);
ArgumentCaptor<StreamRegexMonitor.Callback> callbackArgumentCaptor = ArgumentCaptor.forClass(StreamRegexMonitor.Callback.class);
when(this.streamRegexMonitorFactory.build(eq(jobModel), eq(jobModelConfig), callbackArgumentCaptor.capture())).thenReturn(Optional.of(streamRegexMonitor));
JobCoordinatorMetadata newMetadata = setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.of(JobMetadataChange.NEW_DEPLOYMENT, JobMetadataChange.JOB_MODEL), true);
setUpDiagnosticsManager(jobModel);
MetadataResourceUtil metadataResourceUtil = metadataResourceUtil(jobModel);
this.staticResourceJobCoordinator.start();
verifyStartLifecycle();
verify(this.staticResourceJobCoordinator).doSetLoggingContextConfig(jobModelConfig);
verify(this.diagnosticsManager).start();
verifyPrepareWorkerExecutionAndMonitor(jobModel, metadataResourceUtil, streamPartitionCountMonitor, streamRegexMonitor, newMetadata, SINGLE_SSP_FANOUT);
// call the callback from the monitor
callbackArgumentCaptor.getValue().onInputStreamsChanged(ImmutableSet.of(SYSTEM_STREAM), ImmutableSet.of(SYSTEM_STREAM, new SystemStream("system", "stream1")), ImmutableMap.of("system", Pattern.compile("stream.*")));
verify(this.jobRestartSignal).restartJob();
}
use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.
the class TestStaticResourceJobCoordinator method testNewDeploymentNewJobModel.
@Test
public void testNewDeploymentNewJobModel() throws IOException {
Config jobModelConfig = mock(Config.class);
JobModel jobModel = setupJobModel(jobModelConfig);
StreamPartitionCountMonitor streamPartitionCountMonitor = setupStreamPartitionCountMonitor(jobModelConfig);
StreamRegexMonitor streamRegexMonitor = setupStreamRegexMonitor(jobModel, jobModelConfig);
JobCoordinatorMetadata newMetadata = setupJobCoordinatorMetadata(jobModel, jobModelConfig, ImmutableSet.of(JobMetadataChange.NEW_DEPLOYMENT, JobMetadataChange.JOB_MODEL), true);
setUpDiagnosticsManager(jobModel);
MetadataResourceUtil metadataResourceUtil = metadataResourceUtil(jobModel);
this.staticResourceJobCoordinator.start();
assertEquals(jobModel, this.staticResourceJobCoordinator.getJobModel());
verifyStartLifecycle();
verify(this.staticResourceJobCoordinator).doSetLoggingContextConfig(jobModelConfig);
verify(this.diagnosticsManager).start();
verifyPrepareWorkerExecutionAndMonitor(jobModel, metadataResourceUtil, streamPartitionCountMonitor, streamRegexMonitor, newMetadata, SINGLE_SSP_FANOUT);
verify(this.jobCoordinatorListener).onNewJobModel(PROCESSOR_ID, jobModel);
}
Aggregations