static void drainReferenceQueues(Cache<?, ?> cache) { if (hasLocalCache(cache)) { drainReferenceQueues(toLocalCache(cache)); } }
private void assertCleanup( LoadingCache<Integer, String> cache, CountingRemovalListener<Integer, String> removalListener) { // initialSize will most likely be 2, but it's possible for the GC to have already run, so we'll // observe a size of 1 long initialSize = cache.size(); assertTrue(initialSize == 1 || initialSize == 2); // wait up to 5s byte[] filler = new byte[1024]; for (int i = 0; i < 500; i++) { System.gc(); CacheTesting.drainReferenceQueues(cache); if (cache.size() == 1) { break; } try { Thread.sleep(10); } catch (InterruptedException e) { /* ignore */ } try { // Fill up heap so soft references get cleared. filler = new byte[Math.max(filler.length, filler.length * 2)]; } catch (OutOfMemoryError e) { } } CacheTesting.processPendingNotifications(cache); assertEquals(1, cache.size()); assertEquals(1, removalListener.getCount()); }
static void drainReferenceQueues(Cache<?, ?> cache) { if (hasLocalCache(cache)) { drainReferenceQueues(toLocalCache(cache)); } }
private void assertCleanup(LoadingCache<Integer, String> cache, CountingRemovalListener<Integer, String> removalListener) { // initialSize will most likely be 2, but it's possible for the GC to have already run, so we'll // observe a size of 1 long initialSize = cache.size(); assertTrue(initialSize == 1 || initialSize == 2); // wait up to 5s byte[] filler = new byte[1024]; for (int i = 0; i < 500; i++) { System.gc(); CacheTesting.drainReferenceQueues(cache); if (cache.size() == 1) { break; } try { Thread.sleep(10); } catch (InterruptedException e) { /* ignore */} try { // Fill up heap so soft references get cleared. filler = new byte[Math.max(filler.length, filler.length * 2)]; } catch (OutOfMemoryError e) {} } CacheTesting.processPendingNotifications(cache); assertEquals(1, cache.size()); assertEquals(1, removalListener.getCount()); }