private void waitForConnectorSync(int timeoutInSeconds) throws InterruptedException { int t = 0; while (ConsistentHash.emptyRing().equals(connector1.getConsistentHash()) || !connector1.getConsistentHash().equals(connector2.getConsistentHash())) { // don't have a member for String yet, which means we must wait a little longer if (t++ > timeoutInSeconds * 10) { fail( "Connectors did not manage to synchronize consistent hash ring within " + timeoutInSeconds + " seconds..."); } Thread.sleep(100); } }
@Test public void testConnectorRecoversWhenGossipRouterReconnects() throws Exception { final AtomicInteger counter1 = new AtomicInteger(0); final AtomicInteger counter2 = new AtomicInteger(0); connector1.subscribe(String.class.getName(), new CountingCommandHandler<String>(counter1)); connector1.connect(20); assertTrue( "Expected connector 1 to connect within 10 seconds", connector1.awaitJoined(10, TimeUnit.SECONDS)); connector2.subscribe(Long.class.getName(), new CountingCommandHandler<Long>(counter2)); connector2.connect(80); assertTrue("Connector 2 failed to connect", connector2.awaitJoined()); // the nodes joined, but didn't detect eachother gossipRouter.start(); // now, they should detect eachother and start syncing their state waitForConnectorSync(60); }