public void intCacheIterator2() { IntObjectCache<Integer> cache = new IntObjectCache<Integer>(4); cache.cacheObject(0, 0); cache.cacheObject(1, 1); cache.cacheObject(2, 2); cache.cacheObject(4, 4); cache.cacheObject(3, 3); cache.tryKey(4); cache.cacheObject(4, 5); HashSet<Object> values = new HashSet<Object>(); for (Object obj : cache) { values.add(obj); } assertFalse(values.contains(0)); assertTrue(values.contains(1)); assertTrue(values.contains(2)); assertTrue(values.contains(3)); assertTrue(values.contains(5)); assertTrue(cache.get(4).equals(5)); }
public void testPerformance() throws IOException { final IntObjectCache<String> stringCache = new IntObjectCache<String>(2000); final IntObjectCache.DeletedPairsListener listener = new IntObjectCache.DeletedPairsListener() { @Override public void objectRemoved(final int key, final Object value) { try { assertEquals(myEnumerator.enumerate((String)value), key); } catch (IOException e) { throw new RuntimeException(e); } } }; PlatformTestUtil.startPerformanceTest("PersistentStringEnumerator performance failed", 2500, new ThrowableRunnable() { @Override public void run() throws Exception { stringCache.addDeletedPairsListener(listener); for (int i = 0; i < 100000; ++i) { final String string = createRandomString(); stringCache.cacheObject(myEnumerator.enumerate(string), string); } stringCache.removeDeletedPairsListener(listener); stringCache.removeAll(); } }).assertTiming(); myEnumerator.close(); System.out.printf("File size = %d bytes\n", myFile.length()); }
public void testPerformance() throws IOException { final IntObjectCache<String> stringCache = new IntObjectCache<String>(2000); final IntObjectCache.DeletedPairsListener listener = new IntObjectCache.DeletedPairsListener() { @Override public void objectRemoved(final int key, final Object value) { try { assertEquals(myEnumerator.enumerate((String)value), key); } catch (IOException e) { throw new RuntimeException(e); } } }; PlatformTestUtil.startPerformanceTest("PersistentStringEnumerator performance failed", 2500, new ThrowableRunnable() { @Override public void run() throws Exception { stringCache.addDeletedPairsListener(listener); for (int i = 0; i < 100000; ++i) { final String string = createRandomString(); stringCache.cacheObject(myEnumerator.enumerate(string), string); } stringCache.removeDeletedPairsListener(listener); stringCache.removeAll(); } }).cpuBound().assertTiming(); myEnumerator.close(); System.out.printf("File size = %d bytes\n", myFile.length()); }