Source:
<code>public void testZkBarrierForVersionUpgradeWithTimeOut() { String barrierId = String.format("%s/%s", zkUtils1.getKeyBuilder().getRootPath(), RandomStringUtils.randomAlphabetic(4)); List<String> processors = ImmutableList.of("p1", "p2", "p3"); AtomicInteger timeoutStateChangeCalled = new AtomicInteger(0); CountDownLatch latch = new CountDownLatch(2); TestZkBarrierListener listener = new TestZkBarrierListener(latch, timeoutStateChangeCalled, State.TIMED_OUT); ZkBarrierForVersionUpgrade processor1Barrier = new ZkBarrierForVersionUpgrade(barrierId, zkUtils, listener); ZkBarrierForVersionUpgrade processor2Barrier = new ZkBarrierForVersionUpgrade(barrierId, zkUtils1, listener); processor1Barrier.create(BARRIER_VERSION, processors); processor1Barrier.join(BARRIER_VERSION, "p1"); processor2Barrier.join(BARRIER_VERSION, "p2"); processor1Barrier.expire(BARRIER_VERSION); boolean result = false; try { result = latch.await(10000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { e.printStackTrace(); } assertTrue("Barrier Timeout test failed to complete within test timeout.", result); List<String> children = zkUtils.getZkClient().getChildren(barrierId + "/barrier_1/barrier_participants"); State barrierState = zkUtils.getZkClient().readData(barrierId + "/barrier_1/barrier_state"); assertEquals(State.TIMED_OUT, barrierState); assertNotNull(children); assertEquals("Unexpected barrier state. Didn't find two processors.", 2, children.size()); assertEquals("Unexpected barrier state. Didn't find the expected members.", ImmutableList.of("p1", "p2"), children); <START> assertEquals(2, timeoutStateChangeCalled.get()); <END> }</code><technical_language>this flaky in this scenario? - thread-1 await latch check counter==2 - zk-client thread listener.onEvent() is called for processor-1 processor1 increments counter processor1 counts latch listener.onEvent() is called for processor-2 processor2 increments counter counter-check in thread-1 succeed/fail depending ZkClient thread deliver event for processor2? simpler a single latch count = 2 separate listener instances</technical_language>

Target:
public void testZkBarrierForVersionUpgradeWithTimeOut() { String barrierId = String.format("%s/%s", zkUtils1.getKeyBuilder().getRootPath(), RandomStringUtils.randomAlphabetic(4)); List<String> processors = ImmutableList.of("p1", "p2", "p3"); CountDownLatch latch = new CountDownLatch(2); TestZkBarrierListener listener = new TestZkBarrierListener(latch, State.TIMED_OUT); ZkBarrierForVersionUpgrade processor1Barrier = new ZkBarrierForVersionUpgrade(barrierId, zkUtils, listener); ZkBarrierForVersionUpgrade processor2Barrier = new ZkBarrierForVersionUpgrade(barrierId, zkUtils1, listener); processor1Barrier.create(BARRIER_VERSION, processors); processor1Barrier.join(BARRIER_VERSION, "p1"); processor2Barrier.join(BARRIER_VERSION, "p2"); processor1Barrier.expire(BARRIER_VERSION); boolean result = false; try { result = latch.await(10000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { e.printStackTrace(); } assertTrue("Barrier Timeout test failed to complete within test timeout.", result); List<String> children = zkUtils.getZkClient().getChildren(barrierId + "/barrier_1/barrier_participants"); State barrierState = zkUtils.getZkClient().readData(barrierId + "/barrier_1/barrier_state"); assertEquals(State.TIMED_OUT, barrierState); assertNotNull(children); assertEquals("Unexpected barrier state. Didn't find two processors.", 2, children.size()); assertEquals("Unexpected barrier state. Didn't find the expected members.", ImmutableList.of("p1", "p2"), children); }