BinarySearchTokenMapper implements HashPartitioner { public void initSearchMechanism(Collection<HostToken> hostTokens) { for (HostToken hostToken : hostTokens) { tokenMap.put(hostToken.getToken(), hostToken); } initBinarySearch(); } BinarySearchTokenMapper(HashPartitioner p); @Override Long hash(int key); @Override Long hash(long key); @Override Long hash(String key); @Override Long hash(byte[] key); @Override HostToken getToken(Long keyHash); void initSearchMechanism(Collection<HostToken> hostTokens); void addHostToken(HostToken hostToken); void remoteHostToken(HostToken hostToken); void removeHost(Host host); boolean isEmpty(); String toString();  }
@Test public void testSearchToken() throws Exception { final BinarySearchTokenMapper tokenMapper = new BinarySearchTokenMapper(new Murmur1HashPartitioner()); tokenMapper.initSearchMechanism(getTestTokens()); Long failures = 0L; failures += runTest(309687905L - 1000000L, 309687905L, "h1", tokenMapper); Assert.assertTrue("Failures: " + failures, failures == 0); failures += runTest(309687905L + 1L, 309687905L + 1000000L, "h2", tokenMapper); Assert.assertTrue("Failures: " + failures, failures == 0); failures += runTest(1383429731L + 1L, 1383429731L + 1000000L, "h3", tokenMapper); Assert.assertTrue("Failures: " + failures, failures == 0); failures += runTest(2457171554L + 1L, 2457171554L + 1000000L, "h4", tokenMapper); Assert.assertTrue("Failures: " + failures, failures == 0); failures += runTest(3530913377L + 1L, 3530913377L + 1000000L, "h1", tokenMapper); Assert.assertTrue("Failures: " + failures, failures == 0); }