Search in sources :

Example 1 with StreamPartitionCountMonitor

use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.

the class TestClusterBasedJobCoordinator method testPartitionCountMonitorWithDurableStates.

@Test
public void testPartitionCountMonitorWithDurableStates() {
    configMap.put("stores.mystore.changelog", "mychangelog");
    configMap.put(JobConfig.JOB_CONTAINER_COUNT, "1");
    when(CoordinatorStreamUtil.readConfigFromCoordinatorStream(anyObject())).thenReturn(new MapConfig(configMap));
    Config config = new MapConfig(configMap);
    // mimic job runner code to write the config to coordinator stream
    CoordinatorStreamSystemProducer producer = new CoordinatorStreamSystemProducer(config, mock(MetricsRegistry.class));
    producer.writeConfig("test-job", config);
    ClusterBasedJobCoordinator clusterCoordinator = ClusterBasedJobCoordinatorRunner.createFromMetadataStore(config);
    // change the input system stream metadata
    MockSystemFactory.MSG_QUEUES.put(new SystemStreamPartition("kafka", "topic1", new Partition(1)), new ArrayList<>());
    StreamPartitionCountMonitor monitor = clusterCoordinator.getPartitionMonitor();
    monitor.updatePartitionCountMetric();
    assertEquals(clusterCoordinator.getAppStatus(), SamzaApplicationState.SamzaAppStatus.FAILED);
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) MetricsRegistry(org.apache.samza.metrics.MetricsRegistry) JobConfig(org.apache.samza.config.JobConfig) ApplicationConfig(org.apache.samza.config.ApplicationConfig) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) MapConfig(org.apache.samza.config.MapConfig) CoordinatorStreamSystemProducer(org.apache.samza.coordinator.stream.CoordinatorStreamSystemProducer) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with StreamPartitionCountMonitor

use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.

the class TestClusterBasedJobCoordinator method testPartitionCountMonitorWithoutDurableStates.

@Test
public void testPartitionCountMonitorWithoutDurableStates() {
    configMap.put(JobConfig.JOB_CONTAINER_COUNT, "1");
    when(CoordinatorStreamUtil.readConfigFromCoordinatorStream(anyObject())).thenReturn(new MapConfig(configMap));
    Config config = new MapConfig(configMap);
    // mimic job runner code to write the config to coordinator stream
    CoordinatorStreamSystemProducer producer = new CoordinatorStreamSystemProducer(config, mock(MetricsRegistry.class));
    producer.writeConfig("test-job", config);
    ClusterBasedJobCoordinator clusterCoordinator = ClusterBasedJobCoordinatorRunner.createFromMetadataStore(config);
    // change the input system stream metadata
    MockSystemFactory.MSG_QUEUES.put(new SystemStreamPartition("kafka", "topic1", new Partition(1)), new ArrayList<>());
    StreamPartitionCountMonitor monitor = clusterCoordinator.getPartitionMonitor();
    monitor.updatePartitionCountMetric();
    assertEquals(clusterCoordinator.getAppStatus(), SamzaApplicationState.SamzaAppStatus.UNDEFINED);
}
Also used : SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) Partition(org.apache.samza.Partition) MetricsRegistry(org.apache.samza.metrics.MetricsRegistry) JobConfig(org.apache.samza.config.JobConfig) ApplicationConfig(org.apache.samza.config.ApplicationConfig) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor) MapConfig(org.apache.samza.config.MapConfig) CoordinatorStreamSystemProducer(org.apache.samza.coordinator.stream.CoordinatorStreamSystemProducer) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with StreamPartitionCountMonitor

use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.

the class TestZkJobCoordinator method testShouldStartPartitionCountMonitorOnBecomingLeader.

@Test
public void testShouldStartPartitionCountMonitorOnBecomingLeader() {
    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;
    doReturn(monitor).when(zkJobCoordinator).getPartitionCountMonitor();
    ZkJobCoordinator.LeaderElectorListenerImpl listener = zkJobCoordinator.new LeaderElectorListenerImpl();
    listener.onBecomingLeader();
    Mockito.verify(monitor).start();
}
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) Test(org.junit.Test)

Example 4 with StreamPartitionCountMonitor

use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.

the class TestStaticResourceJobCoordinator method testSameJobModelAsPrevious.

@Test
public void testSameJobModelAsPrevious() 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(), 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, null, null);
    verify(this.jobCoordinatorListener).onNewJobModel(PROCESSOR_ID, jobModel);
}
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) MetadataResourceUtil(org.apache.samza.coordinator.MetadataResourceUtil) Test(org.junit.Test)

Example 5 with StreamPartitionCountMonitor

use of org.apache.samza.coordinator.StreamPartitionCountMonitor in project samza by apache.

the class TestStaticResourceJobCoordinator method setupStreamPartitionCountMonitor.

/**
 * Set up {@link StreamPartitionCountMonitorFactory} to return a mock {@link StreamPartitionCountMonitor}.
 */
private StreamPartitionCountMonitor setupStreamPartitionCountMonitor(Config config) {
    StreamPartitionCountMonitor streamPartitionCountMonitor = mock(StreamPartitionCountMonitor.class);
    when(this.streamPartitionCountMonitorFactory.build(eq(config), any())).thenReturn(streamPartitionCountMonitor);
    return streamPartitionCountMonitor;
}
Also used : StreamPartitionCountMonitor(org.apache.samza.coordinator.StreamPartitionCountMonitor)

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