Search in sources :

Example 11 with StreamPartitionCountMonitor

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();
}
Also used : NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) HashMap(java.util.HashMap) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) ZkSessionStateChangedListener(org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener) Test(org.junit.Test)

Example 12 with StreamPartitionCountMonitor

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);
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) Test(org.junit.Test)

Example 13 with StreamPartitionCountMonitor

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);
}
Also used : MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) Test(org.junit.Test)

Example 14 with StreamPartitionCountMonitor

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();
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor) JobCoordinatorMetadata(org.apache.samza.job.JobCoordinatorMetadata) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) SystemStream(org.apache.samza.system.SystemStream) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) MetadataResourceUtil(org.apache.samza.coordinator.MetadataResourceUtil) Test(org.junit.Test)

Example 15 with StreamPartitionCountMonitor

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);
}
Also used : StreamRegexMonitor(org.apache.samza.coordinator.StreamRegexMonitor) JobCoordinatorMetadata(org.apache.samza.job.JobCoordinatorMetadata) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) JobConfig(org.apache.samza.config.JobConfig) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) JobModel(org.apache.samza.job.model.JobModel) MetadataResourceUtil(org.apache.samza.coordinator.MetadataResourceUtil) Test(org.junit.Test)

Aggregations

StreamPartitionCountMonitor (org.apache.samza.coordinator.StreamPartitionCountMonitor)16 MapConfig (org.apache.samza.config.MapConfig)14 Test (org.junit.Test)14 JobModel (org.apache.samza.job.model.JobModel)12 Config (org.apache.samza.config.Config)11 JobConfig (org.apache.samza.config.JobConfig)11 StreamRegexMonitor (org.apache.samza.coordinator.StreamRegexMonitor)8 MetadataResourceUtil (org.apache.samza.coordinator.MetadataResourceUtil)6 JobCoordinatorMetadata (org.apache.samza.job.JobCoordinatorMetadata)5 HashMap (java.util.HashMap)3 NoOpMetricsRegistry (org.apache.samza.util.NoOpMetricsRegistry)3 Partition (org.apache.samza.Partition)2 ApplicationConfig (org.apache.samza.config.ApplicationConfig)2 CoordinatorStreamSystemProducer (org.apache.samza.coordinator.stream.CoordinatorStreamSystemProducer)2 MetricsRegistry (org.apache.samza.metrics.MetricsRegistry)2 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 JobModelMonitors (org.apache.samza.coordinator.JobModelMonitors)1 SystemStream (org.apache.samza.system.SystemStream)1 ZkSessionStateChangedListener (org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener)1