public BlockingEnvelopeMap() { this(new NoOpMetricsRegistry()); }
@Test public void testNoOpMetricsHappyPath() { NoOpMetricsRegistry registry = new NoOpMetricsRegistry(); Counter counter1 = registry.newCounter("testc", "a"); Counter counter2 = registry.newCounter("testc", "b"); Counter counter3 = registry.newCounter("testc2", "c"); Gauge<String> gauge1 = registry.newGauge("testg", "a", "1"); Gauge<String> gauge2 = registry.newGauge("testg", "b", "2"); Gauge<String> gauge3 = registry.newGauge("testg", "c", "3"); Gauge<String> gauge4 = registry.newGauge("testg2", "d", "4"); Timer timer1 = registry.newTimer("testt", "a"); Timer timer2 = registry.newTimer("testt", "b"); Timer timer3 = registry.newTimer("testt2", "c");
public BlockingEnvelopeMap() { this(new NoOpMetricsRegistry()); }
public MockBlockingEnvelopeMap(BlockingQueue<IncomingMessageEnvelope> injectedQueue, Clock clock) { super(new NoOpMetricsRegistry(), clock); this.injectedQueue = injectedQueue; }
private ZkUtils getZkUtils() { return new ZkUtils(KEY_BUILDER, zkClient, CONNECTION_TIMEOUT_MS, SESSION_TIMEOUT_MS, new NoOpMetricsRegistry()); }
private ZkUtils getZkUtilsWithNewClient() { ZkClient zkClient = ZkCoordinationUtilsFactory .createZkClient(testZkConnectionString, SESSION_TIMEOUT_MS, CONNECTION_TIMEOUT_MS); return new ZkUtils( KEY_BUILDER, zkClient, CONNECTION_TIMEOUT_MS, SESSION_TIMEOUT_MS, new NoOpMetricsRegistry()); } }
private ZkUtils getZkUtilsWithNewClient(String processorId) { ZkClient zkClient = ZkCoordinationUtilsFactory .createZkClient(testZkConnectionString, SESSION_TIMEOUT_MS, CONNECTION_TIMEOUT_MS); return new ZkUtils(KEY_BUILDER, zkClient, CONNECTION_TIMEOUT_MS, SESSION_TIMEOUT_MS, new NoOpMetricsRegistry()); } }
public MockBlockingEnvelopeMap(boolean fetchLimitByBytesEnabled) { super(new NoOpMetricsRegistry(), CLOCK, null); injectedQueue = new MockQueue(); }
@Test public void testCloseShouldRetryOnceOnInterruptedException() { ZkClient zkClient = Mockito.mock(ZkClient.class); ZkUtils zkUtils = new ZkUtils(KEY_BUILDER, zkClient, CONNECTION_TIMEOUT_MS, SESSION_TIMEOUT_MS, new NoOpMetricsRegistry()); Mockito.doThrow(new ZkInterruptedException(new InterruptedException())) .doAnswer(invocation -> null) .when(zkClient).close(); zkUtils.close(); Mockito.verify(zkClient, Mockito.times(2)).close(); }
@Before public void testSetup() { ZkClient zkClient = new ZkClient(testZkConnectionString, ZkConfig.DEFAULT_SESSION_TIMEOUT_MS, ZkConfig.DEFAULT_CONNECTION_TIMEOUT_MS); this.zkUtils = new ZkUtils(new ZkKeyBuilder("group1"), zkClient, ZkConfig.DEFAULT_CONNECTION_TIMEOUT_MS, ZkConfig.DEFAULT_SESSION_TIMEOUT_MS, new NoOpMetricsRegistry()); ZkClient zkClient1 = new ZkClient(testZkConnectionString, ZkConfig.DEFAULT_SESSION_TIMEOUT_MS, ZkConfig.DEFAULT_CONNECTION_TIMEOUT_MS); this.zkUtils1 = new ZkUtils(new ZkKeyBuilder("group1"), zkClient1, ZkConfig.DEFAULT_CONNECTION_TIMEOUT_MS, ZkConfig.DEFAULT_SESSION_TIMEOUT_MS, new NoOpMetricsRegistry()); }
public CoordinationUtils getCoordinationUtils(String groupId, String participantId, Config config) { ZkConfig zkConfig = new ZkConfig(config); ZkClient zkClient = createZkClient(zkConfig.getZkConnect(), zkConfig.getZkSessionTimeoutMs(), zkConfig.getZkConnectionTimeoutMs()); ZkUtils zkUtils = new ZkUtils(new ZkKeyBuilder(groupId), zkClient, zkConfig.getZkConnectionTimeoutMs(), zkConfig.getZkSessionTimeoutMs(), new NoOpMetricsRegistry()); return new ZkCoordinationUtils(participantId, zkConfig, zkUtils); }
@Test public void testCloseShouldTearDownZkConnectionOnInterruptedException() throws Exception { CountDownLatch latch = new CountDownLatch(1); // Establish connection with the zookeeper server. ZkClient zkClient = new ZkClient("127.0.0.1:" + zkServer.getPort()); ZkUtils zkUtils = new ZkUtils(KEY_BUILDER, zkClient, CONNECTION_TIMEOUT_MS, SESSION_TIMEOUT_MS, new NoOpMetricsRegistry()); Thread threadToInterrupt = new Thread(() -> { try { latch.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } zkUtils.close(); }); threadToInterrupt.start(); Field field = ZkClient.class.getDeclaredField("_closed"); field.setAccessible(true); Assert.assertFalse(field.getBoolean(zkClient)); threadToInterrupt.interrupt(); threadToInterrupt.join(); Assert.assertTrue(field.getBoolean(zkClient)); } }
public CoordinationUtils getCoordinationUtils(String groupId, String participantId, Config config) { ZkConfig zkConfig = new ZkConfig(config); ZkClient zkClient = createZkClient(zkConfig.getZkConnect(), zkConfig.getZkSessionTimeoutMs(), zkConfig.getZkConnectionTimeoutMs()); ZkUtils zkUtils = new ZkUtils(new ZkKeyBuilder(groupId), zkClient, zkConfig.getZkConnectionTimeoutMs(), zkConfig.getZkSessionTimeoutMs(), new NoOpMetricsRegistry()); return new ZkCoordinationUtils(participantId, zkConfig, zkUtils); }
public CoordinationUtils getCoordinationUtils(String groupId, String participantId, Config config) { ZkConfig zkConfig = new ZkConfig(config); ZkClient zkClient = createZkClient(zkConfig.getZkConnect(), zkConfig.getZkSessionTimeoutMs(), zkConfig.getZkConnectionTimeoutMs()); ZkUtils zkUtils = new ZkUtils(new ZkKeyBuilder(groupId), zkClient, zkConfig.getZkConnectionTimeoutMs(), zkConfig.getZkSessionTimeoutMs(), new NoOpMetricsRegistry()); return new ZkCoordinationUtils(participantId, zkConfig, zkUtils); }
public CoordinationUtils getCoordinationUtils(String groupId, String participantId, Config config) { ZkConfig zkConfig = new ZkConfig(config); ZkClient zkClient = createZkClient(zkConfig.getZkConnect(), zkConfig.getZkSessionTimeoutMs(), zkConfig.getZkConnectionTimeoutMs()); ZkUtils zkUtils = new ZkUtils(new ZkKeyBuilder(groupId), zkClient, zkConfig.getZkConnectionTimeoutMs(), zkConfig.getZkSessionTimeoutMs(), new NoOpMetricsRegistry()); return new ZkCoordinationUtils(participantId, zkConfig, zkUtils); }
public CoordinationUtils getCoordinationUtils(String groupId, String participantId, Config config) { ZkConfig zkConfig = new ZkConfig(config); ZkClient zkClient = createZkClient(zkConfig.getZkConnect(), zkConfig.getZkSessionTimeoutMs(), zkConfig.getZkConnectionTimeoutMs()); ZkUtils zkUtils = new ZkUtils(new ZkKeyBuilder(groupId), zkClient, zkConfig.getZkConnectionTimeoutMs(), zkConfig.getZkSessionTimeoutMs(), new NoOpMetricsRegistry()); return new ZkCoordinationUtils(participantId, zkConfig, zkUtils); }
@Before public void setUp() throws Exception { // Create a different local store directory every time the test is executed to avoid // intermittent test failures due to previous unsuccessful test re-runs. localStoreDir = Files.createTempDir(); jobDir = new File(localStoreDir, "test-jobName-jobId"); taskStoreDir = new File(new File(jobDir, "test-store"), "test-task"); config = ImmutableMap.of(LocalStoreMonitorConfig.CONFIG_LOCAL_STORE_DIR, localStoreDir.getCanonicalPath()); // Make scaffold directories for testing. FileUtils.forceMkdir(taskStoreDir); taskStoreSize = taskStoreDir.getTotalSpace(); // Set default return values for methods. Mockito.when(jobsClientMock.getJobStatus(Mockito.any())).thenReturn(JobStatus.STOPPED); Task task = new Task("localHost", "test-task", "0", new ArrayList<>(), ImmutableList.of("test-store")); Mockito.when(jobsClientMock.getTasks(Mockito.any())).thenReturn(ImmutableList.of(task)); localStoreMonitorMetrics = new LocalStoreMonitorMetrics("TestMonitorName", new NoOpMetricsRegistry()); // Initialize the local store monitor with mock and config localStoreMonitor = new LocalStoreMonitor(new LocalStoreMonitorConfig(new MapConfig(config)), localStoreMonitorMetrics, jobsClientMock); }
@Test public void testInit() { Context context = mock(Context.class); JobContext jobContext = mock(JobContext.class); when(context.getJobContext()).thenReturn(jobContext); when(jobContext.getConfig()).thenReturn(new MapConfig()); ContainerContext containerContext = mock(ContainerContext.class); when(context.getContainerContext()).thenReturn(containerContext); when(containerContext.getContainerMetricsRegistry()).thenReturn(new NoOpMetricsRegistry()); TaskContext taskContext = mock(TaskContext.class); when(context.getTaskContext()).thenReturn(taskContext); when(taskContext.getStore(any())).thenReturn(mock(KeyValueStore.class)); TableProvider tableProvider = createTableProvider("t1"); tableProvider.init(context); Assert.assertNotNull(tableProvider.getTable()); }
@Test public void testShouldStopPartitionCountMonitorWhenStoppingTheJobCoordinator() { ZkKeyBuilder keyBuilder = Mockito.mock(ZkKeyBuilder.class); ZkClient mockZkClient = Mockito.mock(ZkClient.class); when(keyBuilder.getJobModelVersionBarrierPrefix()).thenReturn(TEST_BARRIER_ROOT); ZkUtils zkUtils = Mockito.mock(ZkUtils.class); when(zkUtils.getKeyBuilder()).thenReturn(keyBuilder); when(zkUtils.getZkClient()).thenReturn(mockZkClient); 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("TEST_PROCESSOR_ID", new MapConfig(), new NoOpMetricsRegistry(), zkUtils)); StreamPartitionCountMonitor monitor = Mockito.mock(StreamPartitionCountMonitor.class); zkJobCoordinator.debounceTimer = mockDebounceTimer; zkJobCoordinator.streamPartitionCountMonitor = monitor; zkJobCoordinator.stop(); Mockito.verify(monitor).stop(); } }
private KafkaSystemConsumer createConsumer(String fetchMsg, String fetchBytes) { final Map<String, String> map = new HashMap<>(); map.put(JobConfig.JOB_NAME(), TEST_JOB); map.put(String.format(KafkaConfig.CONSUMER_FETCH_THRESHOLD(), TEST_SYSTEM), fetchMsg); map.put(String.format(KafkaConfig.CONSUMER_FETCH_THRESHOLD_BYTES(), TEST_SYSTEM), fetchBytes); map.put(String.format("systems.%s.consumer.%s", TEST_SYSTEM, ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG), BOOTSTRAP_SERVER); map.put(JobConfig.JOB_NAME(), "jobName"); Config config = new MapConfig(map); String clientId = KafkaConsumerConfig.createClientId(TEST_PREFIX_ID, config); KafkaConsumerConfig consumerConfig = KafkaConsumerConfig.getKafkaSystemConsumerConfig(config, TEST_SYSTEM, clientId); final KafkaConsumer<byte[], byte[]> kafkaConsumer = new MockKafkaConsumer(consumerConfig); MockKafkaSystemConsumer newKafkaSystemConsumer = new MockKafkaSystemConsumer(kafkaConsumer, TEST_SYSTEM, config, TEST_PREFIX_ID, new KafkaSystemConsumerMetrics(TEST_SYSTEM, new NoOpMetricsRegistry()), System::currentTimeMillis); return newKafkaSystemConsumer; }