public DataStoreCacheStatsMBean getStagingCacheStats() { return stagingCache.getStats(); }
public DataStoreCacheStatsMBean getStagingCacheStats() { return stagingCache.getStats(); }
public DataStoreCacheStatsMBean getStagingCacheStats() { return stagingCache.getStats(); }
private static void assertCacheStats(UploadStagingCache cache, long elems, long weight, long hits, long count) { assertEquals(elems, cache.getStats().getElementCount()); assertEquals(weight, cache.getStats().estimateCurrentWeight()); assertEquals(hits, cache.getStats().getHitCount()); assertEquals(count, cache.getStats().getRequestCount()); } }
/** * Error in putting file to stage. * @throws Exception */ @Test public void testPutMoveFileError() throws Exception { File empty = new File(folder.getRoot(), String.valueOf(System.currentTimeMillis())); assertFalse(empty.exists()); Optional<SettableFuture<Integer>> future = stagingCache.put(ID_PREFIX + 0, empty); // assert no file assertFalse(future.isPresent()); assertEquals(1, stagingCache.getStats().getMissCount()); assertCacheStats(stagingCache, 0, 0, 0, 1); }
/** * 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); }
@Test public void testZeroCache() throws IOException { stagingCache = UploadStagingCache.build(root, null, 1/*threads*/, 0 /* bytes */, uploader, null/*cache*/, statsProvider, executor, null, 3000, 6000); closer.register(stagingCache); File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile()); Optional<SettableFuture<Integer>> future = stagingCache.put(ID_PREFIX + 0, f); assertFalse(future.isPresent()); assertNull(stagingCache.getIfPresent(ID_PREFIX + 0)); assertEquals(0, Iterators.size(stagingCache.getAllIdentifiers())); assertEquals(0, stagingCache.getStats().getMaxTotalWeight()); }
@Test public void zeroCache() throws IOException { LOG.info("Starting zeroCache"); cache = new CompositeDataStoreCache(root.getAbsolutePath(), null, 0 /* bytes */, 10, 1/*threads*/, loader, uploader, statsProvider, executor, scheduledExecutor, fileCacheExecutor, 3000, 6000); closer.register(cache); File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile()); boolean accepted = cache.stage(ID_PREFIX + 0, f); assertFalse(accepted); assertNull(cache.getIfPresent(ID_PREFIX + 0)); assertNull(cache.get(ID_PREFIX + 0)); assertEquals(0, cache.getStagingCache().getStats().getMaxTotalWeight()); assertEquals(0, cache.getStagingCacheStats().getMaxTotalWeight()); assertEquals(0,cache.getDownloadCache().getStats().getMaxTotalWeight()); assertEquals(0,cache.getCacheStats().getMaxTotalWeight()); cache.invalidate(ID_PREFIX + 0); cache.close(); LOG.info("Finished zeroCache"); }