@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); } }
KBucket split() { BigInteger pivot = startId.add(endId).divide(BigInteger.valueOf(2)); return split(pivot); }
KBucket extends AbstractBucket { KBucket split() { BigInteger pivot = startId.add(endId).divide(BigInteger.valueOf(2)); return split(pivot); } }
KBucket extends AbstractBucket { KBucket split() { BigInteger pivot = startId.add(endId).divide(BigInteger.valueOf(2)); return split(pivot); } KBucket(BigInteger startId, BigInteger endId, int depth); }
KBucket extends AbstractBucket { KBucket split() { BigInteger pivot = startId.add(endId).divide(BigInteger.valueOf(2)); return split(pivot); } KBucket(BigInteger startId, BigInteger endId, int depth); void setLastLookupTime(long lastLookupTime); long getLastLookupTime(); @Override String toString(); }
KBucket extends AbstractBucket { KBucket split() { BigInteger pivot = startId.add(endId).divide(BigInteger.valueOf(2)); return split(pivot); } KBucket(BigInteger startId, BigInteger endId, int depth); void setLastLookupTime(long lastLookupTime); long getLastLookupTime(); @Override String toString();  }