Search in sources :

Example 1 with ZkSessionStateChangedListener

use of org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener in project samza by apache.

the class TestZkJobCoordinator method testShouldRemoveBufferedEventsInDebounceQueueOnSessionExpiration.

@Test
public void testShouldRemoveBufferedEventsInDebounceQueueOnSessionExpiration() {
    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));
    zkJobCoordinator.debounceTimer = mockDebounceTimer;
    zkJobCoordinator.zkSessionMetrics = new ZkSessionMetrics(new MetricsRegistryMap());
    final ZkSessionStateChangedListener zkSessionStateChangedListener = zkJobCoordinator.new ZkSessionStateChangedListener();
    zkSessionStateChangedListener.handleStateChanged(Watcher.Event.KeeperState.Expired);
    verify(zkUtils).incGeneration();
    verify(mockDebounceTimer).cancelAllScheduledActions();
    verify(mockDebounceTimer).scheduleAfterDebounceTime(eq("ZK_SESSION_EXPIRED"), eq(0L), Mockito.any(Runnable.class));
    Assert.assertEquals(1, zkJobCoordinator.zkSessionMetrics.zkSessionExpirations.getCount());
}
Also used : NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) HashMap(java.util.HashMap) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) ZkSessionStateChangedListener(org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Test(org.junit.Test)

Example 2 with ZkSessionStateChangedListener

use of org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener in project samza by apache.

the class TestZkJobCoordinator method testZookeeperSessionMetricsAreUpdatedCorrectly.

@Test
public void testZookeeperSessionMetricsAreUpdatedCorrectly() {
    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));
    zkJobCoordinator.debounceTimer = mockDebounceTimer;
    zkJobCoordinator.zkSessionMetrics = new ZkSessionMetrics(new MetricsRegistryMap());
    final ZkSessionStateChangedListener zkSessionStateChangedListener = zkJobCoordinator.new ZkSessionStateChangedListener();
    zkSessionStateChangedListener.handleStateChanged(Watcher.Event.KeeperState.Disconnected);
    zkSessionStateChangedListener.handleStateChanged(Watcher.Event.KeeperState.SyncConnected);
    zkSessionStateChangedListener.handleStateChanged(Watcher.Event.KeeperState.AuthFailed);
    Assert.assertEquals(1, zkJobCoordinator.zkSessionMetrics.zkSessionErrors.getCount());
    zkSessionStateChangedListener.handleSessionEstablishmentError(new SamzaException("Test exception"));
    Assert.assertEquals(1, zkJobCoordinator.zkSessionMetrics.zkSessionDisconnects.getCount());
    Assert.assertEquals(1, zkJobCoordinator.zkSessionMetrics.zkSyncConnected.getCount());
    Assert.assertEquals(2, zkJobCoordinator.zkSessionMetrics.zkSessionErrors.getCount());
}
Also used : NoOpMetricsRegistry(org.apache.samza.util.NoOpMetricsRegistry) HashMap(java.util.HashMap) JobModel(org.apache.samza.job.model.JobModel) MapConfig(org.apache.samza.config.MapConfig) ZkSessionStateChangedListener(org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) SamzaException(org.apache.samza.SamzaException) Test(org.junit.Test)

Example 3 with ZkSessionStateChangedListener

use of org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener 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)

Aggregations

HashMap (java.util.HashMap)3 MapConfig (org.apache.samza.config.MapConfig)3 JobModel (org.apache.samza.job.model.JobModel)3 NoOpMetricsRegistry (org.apache.samza.util.NoOpMetricsRegistry)3 ZkSessionStateChangedListener (org.apache.samza.zk.ZkJobCoordinator.ZkSessionStateChangedListener)3 Test (org.junit.Test)3 MetricsRegistryMap (org.apache.samza.metrics.MetricsRegistryMap)2 SamzaException (org.apache.samza.SamzaException)1 StreamPartitionCountMonitor (org.apache.samza.coordinator.StreamPartitionCountMonitor)1