diff --git a/router/java/test/junit/net/i2p/router/networkdb/kademlia/KBucketSetTest.java b/core/java/test/junit/net/i2p/kademlia/KBucketSetTest.java similarity index 75% rename from router/java/test/junit/net/i2p/router/networkdb/kademlia/KBucketSetTest.java rename to core/java/test/junit/net/i2p/kademlia/KBucketSetTest.java index 6c9d542107fd1e77be9fc62f527205cbcc0876d2..193f4067e8c827710e2c88462b39672f7fcaa88c 100644 --- a/router/java/test/junit/net/i2p/router/networkdb/kademlia/KBucketSetTest.java +++ b/core/java/test/junit/net/i2p/kademlia/KBucketSetTest.java @@ -1,4 +1,4 @@ -package net.i2p.router.networkdb.kademlia; +package net.i2p.kademlia; /* * free (adj.): unencumbered; not under the control of others * Written by jrandom in 2003 and released into the public domain @@ -20,11 +20,13 @@ import net.i2p.data.Hash; public class KBucketSetTest extends TestCase{ private I2PAppContext context; - private KBucketSet set; + private KBucketSet<Hash> set; + private static final int K = 8; + private static final int B = 1; public void setUp(){ context = I2PAppContext.getGlobalContext(); - set = new KBucketSet(context, Hash.FAKE_HASH); + set = new KBucketSet<Hash>(context, Hash.FAKE_HASH, K, B); } public void testRandom(){ @@ -36,6 +38,7 @@ public class KBucketSetTest extends TestCase{ } public void testSelf() { - assertTrue(set.add(Hash.FAKE_HASH)); + // new implementation will never include myself + assertFalse(set.add(Hash.FAKE_HASH)); } -} \ No newline at end of file +} diff --git a/router/java/test/junit/net/i2p/router/networkdb/kademlia/KBucketImplTest.java b/router/java/test/junit/net/i2p/router/networkdb/kademlia/KBucketImplTest.java deleted file mode 100644 index 185ff21d031bcd2c7fabb002198305935b693e9b..0000000000000000000000000000000000000000 --- a/router/java/test/junit/net/i2p/router/networkdb/kademlia/KBucketImplTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package net.i2p.router.networkdb.kademlia; -/* - * free (adj.): unencumbered; not under the control of others - * Written by jrandom in 2003 and released into the public domain - * with no warranty of any kind, either expressed or implied. - * It probably won't make your computer catch on fire, or eat - * your children, but it might. Use at your own risk. - * - */ - -import junit.framework.TestCase; -import net.i2p.I2PAppContext; -import net.i2p.data.Hash; -import net.i2p.util.RandomSource; - -/** - * Test KBucketImpl - * - * @author comwiz - */ - -public class KBucketImplTest extends TestCase{ - private I2PAppContext context; - - public void setUp(){ - context = I2PAppContext.getGlobalContext(); - } - - public void testLimits() { - int low = 0; - int high = 4; - - KBucketImpl bucket = new KBucketImpl(I2PAppContext.getGlobalContext(), Hash.FAKE_HASH); - bucket.setRange(low, high); - Hash lowerBoundKey = bucket.getRangeBeginKey(); - Hash upperBoundKey = bucket.getRangeEndKey(); - assertTrue(bucket.shouldContain(lowerBoundKey));// - assertTrue(bucket.shouldContain(upperBoundKey)); - - } - - public void testRand() { - int low = 1; - int high = 2000; - - LocalHash local = new LocalHash(Hash.FAKE_HASH); - local.prepareCache(); - KBucketImpl bucket = new KBucketImpl(I2PAppContext.getGlobalContext(), local); - bucket.setRange(low, high); - Hash lowerBoundKey = bucket.getRangeBeginKey(); - Hash upperBoundKey = bucket.getRangeEndKey(); - - for (int i = 0; i < 1000; i++) { - Hash rnd = bucket.generateRandomKey(); - assertTrue(bucket.shouldContain(rnd));// - } - } - - public void testRand2() { - int low = 1; - int high = 2000; - - byte hash[] = new byte[Hash.HASH_LENGTH]; - RandomSource.getInstance().nextBytes(hash); - LocalHash local = new LocalHash(hash); - local.prepareCache(); - KBucketImpl bucket = new KBucketImpl(I2PAppContext.getGlobalContext(), local); - bucket.setRange(low, high); - Hash lowerBoundKey = bucket.getRangeBeginKey(); - Hash upperBoundKey = bucket.getRangeEndKey(); - - for (int i = 0; i < 1000; i++) { - Hash rnd = bucket.generateRandomKey(); - assertTrue(bucket.shouldContain(rnd)); - } - } -}