Source:
public void testBothPreferred() throws InterruptedException, IOException { MockIface iface1 = new Response1Iface(); MockIface iface2 = new Response1Iface(); startMockPartitionServerThread1(iface1, 1); startMockPartitionServerThread2(iface2, 1); Map<Host, List<HostConnection>> hostToConnectionsMap = new HashMap<Host, List<HostConnection>>(); int tryLockTimeoutMs = 0; int establishConnectionTimeoutMs = 0; int queryTimeoutMs = 0; int bulkQueryTimeoutMs = 0; mockHost1.setEnvironmentFlags(Collections.singletonMap("REGION", "REG1")); mockHost2.setEnvironmentFlags(Collections.singletonMap("REGION", "REG1")); hostToConnectionsMap.put(mockHost1, Collections.singletonList(new HostConnection(mockHost1, tryLockTimeoutMs, establishConnectionTimeoutMs, queryTimeoutMs, bulkQueryTimeoutMs))); hostToConnectionsMap.put(mockHost2, Collections.singletonList(new HostConnection(mockHost2, tryLockTimeoutMs, establishConnectionTimeoutMs, queryTimeoutMs, bulkQueryTimeoutMs))); HostConnectionPool hostConnectionPool = new HostConnectionPool(hostToConnectionsMap, null, Sets.newHashSet(mockHost1, mockHost2)); mockHost1.setState(HostState.SERVING); mockHost2.setState(HostState.SERVING); int numHits = 0; for (int i = 0; i < 10; ++i) { HankResponse response = hostConnectionPool.get(mockDomain, KEY_1, 1, null); if (response.is_set_value()) { assertEquals(RESPONSE_1, response); ++numHits; } } assertEquals("Gets should be distributed accross hosts", 5, iface1.numGets); assertEquals("Gets should be distributed accross hosts", 5, iface2.numGets); assertEquals("Half the keys should have been found", 10, numHits); }

Target:
public void testBothPreferred() throws InterruptedException, IOException { MockIface iface1 = new Response1Iface(); MockIface iface2 = new Response1Iface(); startMockPartitionServerThread1(iface1, 1); startMockPartitionServerThread2(iface2, 1); Map<Host, List<HostConnection>> hostToConnectionsMap = new HashMap<Host, List<HostConnection>>(); int tryLockTimeoutMs = 0; int establishConnectionTimeoutMs = 0; int queryTimeoutMs = 0; int bulkQueryTimeoutMs = 0; mockHost1.setEnvironmentFlags(Collections.singletonMap("REGION", "REG1")); mockHost2.setEnvironmentFlags(Collections.singletonMap("REGION", "REG1")); hostToConnectionsMap.put(mockHost1, Collections.singletonList(new HostConnection(mockHost1, tryLockTimeoutMs, establishConnectionTimeoutMs, queryTimeoutMs, bulkQueryTimeoutMs))); hostToConnectionsMap.put(mockHost2, Collections.singletonList(new HostConnection(mockHost2, tryLockTimeoutMs, establishConnectionTimeoutMs, queryTimeoutMs, bulkQueryTimeoutMs))); HostConnectionPool hostConnectionPool = new HostConnectionPool(hostToConnectionsMap, null, Sets.newHashSet(mockHost1, mockHost2)); mockHost1.setState(HostState.SERVING); mockHost2.setState(HostState.SERVING); int numHits = 0; for (int i = 0; i < 10; ++i) { HankResponse response = hostConnectionPool.get(mockDomain, KEY_1, 1, null); if (response.is_set_value()) { assertEquals(RESPONSE_1, response); ++numHits; } } assertEquals("Gets should be distributed across hosts", 5, iface1.numGets); assertEquals("Gets should be distributed across hosts", 5, iface2.numGets); assertEquals("Half the keys should have been found", 10, numHits); }