@Test public void testSplit() throws SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException { assertEquals("K must be an even number for this test to work.", 0, K%2); for (KBucket bucket: buckets) { KademliaPeer[] peers = destinationMap.get(bucket); int originalDepth = KademliaTestUtil.getDepth(bucket); for (int i=0; i<K; i++) { assertFalse(bucket.shouldSplit(peers[i])); bucket.addOrUpdate(peers[i]); } assertTrue(bucket.shouldSplit(peers[K])); KBucket newBucket = bucket.split(); assertNotNull(newBucket); assertEquals(originalDepth+1, KademliaTestUtil.getDepth(bucket)); assertEquals(originalDepth+1, KademliaTestUtil.getDepth(bucket)); assertTrue(maxId(bucket).compareTo(minId(newBucket)) < 0); } }
int depth = KademliaTestUtil.getDepth(bucket); int bitIndex = Hash.HASH_LENGTH*8 - depth; Boolean previousBit = null;