public void testPut() throws Exception { for (int i = 0; i < KEYS_COUNT; i++) { sbTree.put(i, createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + i)); doReset(); } for (int i = 0; i < KEYS_COUNT; i++) { Assert.assertEquals( sbTree.get(i), createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + i), i + " key is absent"); doReset(); } Assert.assertEquals(0, (int) sbTree.firstKey()); doReset(); Assert.assertEquals(KEYS_COUNT - 1, (int) sbTree.lastKey()); doReset(); for (int i = KEYS_COUNT; i < 2 * KEYS_COUNT; i++) { Assert.assertNull(sbTree.get(i)); doReset(); } }
public void testKeyDelete() throws Exception { for (int i = 0; i < KEYS_COUNT; i++) { sbTree.put(i, createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); doReset(); } for (int i = 0; i < KEYS_COUNT; i++) { if (i % 3 == 0) Assert.assertEquals( sbTree.remove(i), createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); doReset(); } Assert.assertEquals((int) sbTree.firstKey(), 1); doReset(); Assert.assertEquals( (int) sbTree.lastKey(), (KEYS_COUNT - 1) % 3 == 0 ? KEYS_COUNT - 2 : KEYS_COUNT - 1); doReset(); for (int i = 0; i < KEYS_COUNT; i++) { if (i % 3 == 0) Assert.assertNull(sbTree.get(i)); else Assert.assertEquals( sbTree.get(i), createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); doReset(); } }
public void testKeyDeleteRandomGaussian() throws Exception { NavigableSet<Integer> keys = new TreeSet<Integer>(); long seed = System.currentTimeMillis(); System.out.println("testKeyDeleteRandomGaussian seed : " + seed); MersenneTwisterFast random = new MersenneTwisterFast(seed); while (keys.size() < KEYS_COUNT) { int key = (int) (random.nextGaussian() * Integer.MAX_VALUE / 2 + Integer.MAX_VALUE); if (key < 0) continue; sbTree.put(key, createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); keys.add(key); Assert.assertEquals( sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); doReset(); } Iterator<Integer> keysIterator = keys.iterator(); while (keysIterator.hasNext()) { int key = keysIterator.next(); if (key % 3 == 0) { sbTree.remove(key); keysIterator.remove(); } doReset(); } Assert.assertEquals(sbTree.firstKey(), keys.first()); doReset(); Assert.assertEquals(sbTree.lastKey(), keys.last()); doReset(); for (int key : keys) { if (key % 3 == 0) { Assert.assertNull(sbTree.get(key)); } else { Assert.assertEquals( sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); } doReset(); } }
public void testKeyPutRandomUniform() throws Exception { final NavigableSet<Integer> keys = new TreeSet<Integer>(); long seed = System.currentTimeMillis(); System.out.println("testKeyPutRandomUniform seed : " + seed); final MersenneTwisterFast random = new MersenneTwisterFast(seed); while (keys.size() < KEYS_COUNT) { int key = random.nextInt(Integer.MAX_VALUE); sbTree.put(key, createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); keys.add(key); doReset(); } Assert.assertEquals(sbTree.firstKey(), keys.first()); doReset(); Assert.assertEquals(sbTree.lastKey(), keys.last()); doReset(); for (int key : keys) { Assert.assertEquals( sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); doReset(); } }
public void testKeysUpdateFromSmallToSmall() throws Exception { for (int i = 0; i < KEYS_COUNT; i++) { if (i % 2 == 0) sbTree.put(i, createValue(i, 512)); else sbTree.put(i / 2, createValue(i / 2, 1024)); doReset(); } for (int i = 0; i < KEYS_COUNT / 2; i++) { Assert.assertEquals(sbTree.get(i), createValue(i, 1024)); doReset(); } }
public void testKeysUpdateFromBigToSmall() throws Exception { for (int i = 0; i < KEYS_COUNT; i++) { if (i % 2 == 0) { sbTree.put(i, createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); } else sbTree.put(i / 2, createValue(i / 2, 1024)); doReset(); } for (int i = 0; i < KEYS_COUNT / 2; i++) { Assert.assertEquals(sbTree.get(i), createValue(i, 1024)); doReset(); } }
public void testKeyDeleteRandomUniform() throws Exception { NavigableSet<Integer> keys = new TreeSet<Integer>(); for (int i = 0; i < KEYS_COUNT; i++) { sbTree.put(i, createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); keys.add(i); doReset(); } Iterator<Integer> keysIterator = keys.iterator(); while (keysIterator.hasNext()) { int key = keysIterator.next(); if (key % 3 == 0) { sbTree.remove(key); keysIterator.remove(); } doReset(); } Assert.assertEquals(sbTree.firstKey(), keys.first()); doReset(); Assert.assertEquals(sbTree.lastKey(), keys.last()); doReset(); for (int key : keys) { if (key % 3 == 0) { Assert.assertNull(sbTree.get(key)); } else { Assert.assertEquals( sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4)); } doReset(); } }