Source:
private void testStreamProcessor(String[] processorIds) { final String testSystem = "test-system"; final String inputTopic = "numbers"; final String outputTopic = "output"; final int messageCount = 40; final Map<String, String> map = createConfigs(testSystem, inputTopic, outputTopic, messageCount); createTopics(inputTopic, outputTopic); TestStreamTask.endLatch = new CountDownLatch(messageCount); StreamProcessor[] streamProcessors = new StreamProcessor[processorIds.length]; CountDownLatch[] startCountDownLatches = new CountDownLatch[processorIds.length]; for (int i = 0; i < processorIds.length; i++) { startCountDownLatches[i] = new CountDownLatch(1); streamProcessors[i] = createStreamProcessor(processorIds[i], map, startCountDownLatches[i], null); } produceMessages(0, inputTopic, messageCount); Thread[] threads = new Thread[processorIds.length]; for (int i = 0; i < processorIds.length; i++) { threads[i] = runInThread(streamProcessors[i], TestStreamTask.endLatch); threads[i].start(); try { startCountDownLatches[i].await(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Assert.fail("got interrupted while waiting for the " + i + "th processor to start."); } } try { TestStreamTask.endLatch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { Assert.fail("endLatch.await failed with an interruption:" + e.getLocalizedMessage()); } try { for (Thread t : threads) { synchronized (t) { t.notify(); } t.join(1000); } } catch (InterruptedException e) { Assert.fail("Failed to join finished thread:" + e.getLocalizedMessage()); } Map<Integer, Boolean> expectedValues = new HashMap<>(messageCount); for (int i = 0; i < messageCount; i++) { expectedValues.put(i, false); } verifyNumMessages(outputTopic, expectedValues, messageCount); }

Target:
private void testStreamProcessor(String[] processorIds) { TestZkStreamProcessorBase.TestStreamTask.endLatch = new CountDownLatch(messageCount); StreamProcessor[] streamProcessors = new StreamProcessor[processorIds.length]; CountDownLatch[] startCountDownLatches = new CountDownLatch[processorIds.length]; for (int i = 0; i < processorIds.length; i++) { startCountDownLatches[i] = new CountDownLatch(1); streamProcessors[i] = createStreamProcessor(processorIds[i], map, startCountDownLatches[i], null); } produceMessages(0, inputTopic, messageCount); Thread[] threads = new Thread[processorIds.length]; for (int i = 0; i < processorIds.length; i++) { threads[i] = runInThread(streamProcessors[i], TestZkStreamProcessorBase.TestStreamTask.endLatch); threads[i].start(); try { startCountDownLatches[i].await(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Assert.fail("got interrupted while waiting for the " + i + "th processor to start."); } } try { TestZkStreamProcessorBase.TestStreamTask.endLatch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { Assert.fail("endLatch.await failed with an interruption:" + e.getLocalizedMessage()); } try { for (Thread t : threads) { synchronized (t) { t.notify(); } t.join(1000); } } catch (InterruptedException e) { Assert.fail("Failed to join finished thread:" + e.getLocalizedMessage()); } verifyNumMessages(outputTopic, messageCount, messageCount); }