CompositeDataSupport toCompositeData() { Object[] values = new Object[]{ stats.getName(), stats.getRequestCount(), stats.getHitCount(), new BigDecimal(stats.getHitRate(),new MathContext(2)), stats.getMissCount(), new BigDecimal(stats.getMissRate(), new MathContext(2)), stats.getLoadCount(), stats.getLoadSuccessCount(), stats.getLoadExceptionCount(), timeInWords(stats.getTotalLoadTime()), TimeUnit.NANOSECONDS.toMillis((long) stats.getAverageLoadPenalty()) + "ms", stats.getEvictionCount(), stats.getElementCount(), humanReadableByteCount(stats.estimateCurrentWeight()), humanReadableByteCount(stats.estimateCurrentMemoryWeight()), humanReadableByteCount(stats.getMaxTotalWeight()), }; try { return new CompositeDataSupport(TYPE, FIELD_NAMES, values); } catch (OpenDataException e) { throw new IllegalStateException(e); } } }
CompositeDataSupport toCompositeData() { Object[] values = new Object[]{ stats.getName(), stats.getRequestCount(), stats.getHitCount(), new BigDecimal(stats.getHitRate(),new MathContext(2)), stats.getMissCount(), new BigDecimal(stats.getMissRate(), new MathContext(2)), stats.getLoadCount(), stats.getLoadSuccessCount(), stats.getLoadExceptionCount(), timeInWords(stats.getTotalLoadTime()), TimeUnit.NANOSECONDS.toMillis((long) stats.getAverageLoadPenalty()) + "ms", stats.getEvictionCount(), stats.getElementCount(), humanReadableByteCount(stats.estimateCurrentWeight()), humanReadableByteCount(stats.estimateCurrentMemoryWeight()), humanReadableByteCount(stats.getMaxTotalWeight()), }; try { return new CompositeDataSupport(TYPE, FIELD_NAMES, values); } catch (OpenDataException e) { throw new IllegalStateException(e); } } }
CompositeDataSupport toCompositeData() { Object[] values = new Object[]{ stats.getName(), stats.getRequestCount(), stats.getHitCount(), new BigDecimal(stats.getHitRate(),new MathContext(2)), stats.getMissCount(), new BigDecimal(stats.getMissRate(), new MathContext(2)), stats.getLoadCount(), stats.getLoadSuccessCount(), stats.getLoadExceptionCount(), timeInWords(stats.getTotalLoadTime()), TimeUnit.NANOSECONDS.toMillis((long) stats.getAverageLoadPenalty()) + "ms", stats.getEvictionCount(), stats.getElementCount(), humanReadableByteCount(stats.estimateCurrentWeight()), humanReadableByteCount(stats.estimateCurrentMemoryWeight()), humanReadableByteCount(stats.getMaxTotalWeight()), }; try { return new CompositeDataSupport(TYPE, FIELD_NAMES, values); } catch (OpenDataException e) { throw new IllegalStateException(e); } } }
/** * Put and retrieve different files concurrently. * @throws Exception */ @Test public void testGetAddDifferent() throws Exception { //add load List<ListenableFuture<Integer>> futures = put(folder); // Create an async retrieve task final SettableFuture<File> retFuture = SettableFuture.create(); Thread t = new Thread(new Runnable() { @Override public void run() { retFuture.set(stagingCache.getIfPresent(ID_PREFIX + 1)); } }); //start taskLatch.countDown(); callbackLatch.countDown(); t.start(); //assert no file retrieve assertNull(retFuture.get()); assertEquals(1, stagingCache.getStats().getLoadCount()); assertFuture(futures, 0); assertCacheStats(stagingCache, 0, 0, 1, 1); }
/** * Retrieve without adding. * @throws Exception */ @Test public void testGetNoAdd() throws Exception { File ret = stagingCache.getIfPresent(ID_PREFIX + 0); // assert no file assertNull(ret); assertEquals(1, stagingCache.getStats().getLoadCount()); assertCacheStats(stagingCache, 0, 0, 0, 0); }
assertTrue(Files.equal(gold, fromUploadStream)); assertEquals(2, cache.getStagingCacheStats().getLoadCount()); assertEquals(0, cache.getCacheStats().getLoadCount()); assertEquals(0, cache.getCacheStats().getLoadSuccessCount());
assertEquals(2, cache.getStagingCacheStats().getLoadCount()); assertEquals(0, cache.getStagingCacheStats().getLoadSuccessCount()); assertEquals(2, cache.getCacheStats().getLoadCount()); assertEquals(2, cache.getCacheStats().getLoadSuccessCount());
assertEquals(2, cache.getStagingCacheStats().getLoadCount()); assertEquals(1, cache.getStagingCacheStats().getLoadSuccessCount()); assertEquals(1, cache.getCacheStats().getLoadCount()); assertEquals(1, cache.getCacheStats().getLoadSuccessCount());
private static void assertCacheStats(FileCache cache, long elems, long weight, long loads, long loadSuccesses) { assertEquals(elems, cache.getStats().getElementCount()); assertEquals(weight, cache.getStats().estimateCurrentWeight()); assertEquals(loads, cache.getStats().getLoadCount()); assertEquals(loadSuccesses, cache.getStats().getLoadSuccessCount()); } }
/** * Load and get from the download cache. * @throws Exception */ @Test public void getLoad() throws Exception { LOG.info("Starting getLoad"); File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile()); loader.write(ID_PREFIX + 0, f); // Not present yet File cached = cache.getIfPresent(ID_PREFIX + 0); assertNull(cached); // present after loading cached = cache.get(ID_PREFIX + 0); assertNotNull(cached); assertTrue(Files.equal(f, cached)); assertCacheStats(cache.getStagingCacheStats(), 0, 0, 0, 0); assertEquals(2, cache.getStagingCacheStats().getLoadCount()); assertEquals(0, cache.getStagingCacheStats().getLoadSuccessCount()); assertCacheStats(cache.getCacheStats(), 1, 4 * 1024, 0, 3); assertEquals(1, cache.getCacheStats().getLoadCount()); assertEquals(1, cache.getCacheStats().getLoadSuccessCount()); LOG.info("Finished getLoad"); }
assertTrue(Files.equal(copyToFile(randomStream(0, 4 * 1024), folder.newFile()), ret)); assertEquals(1, stagingCache.getStats().getLoadCount()); assertEquals(1, stagingCache.getStats().getLoadSuccessCount()); assertCacheStats(stagingCache, 1, 4 * 1024, 1, 1);
/** * Invalidate cache entry. * @throws Exception */ @Test public void invalidate() throws Exception { LOG.info("Starting invalidate"); File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile()); loader.write(ID_PREFIX + 0, f); // present after loading File cached = cache.get(ID_PREFIX + 0); assertNotNull(cached); assertTrue(Files.equal(f, cached)); cache.invalidate(ID_PREFIX + 0); // Not present now cached = cache.getIfPresent(ID_PREFIX + 0); assertNull(cached); assertCacheStats(cache.getStagingCacheStats(), 0, 0, 0, 0); assertEquals(2, cache.getStagingCacheStats().getLoadCount()); assertEquals(0, cache.getStagingCacheStats().getLoadSuccessCount()); assertCacheStats(cache.getCacheStats(), 0, 0, 0, 3); assertEquals(1, cache.getCacheStats().getLoadCount()); assertEquals(1, cache.getCacheStats().getLoadSuccessCount()); /** Check eviction count */ assertEquals(0, cache.getCacheStats().getEvictionCount()); LOG.info("Finished invalidate"); }