@Test public void testGC() throws Exception { int gcRuns = PictureTilingCacheGCManager.getGCRuns(); PictureTilingService pts = Framework.getLocalService(PictureTilingService.class); assertNotNull(pts); benchTiler(pts, new MagickTiler()); testMagick2(); testMagick2(); long cacheSize = PictureTilingCacheGCManager.getCacheSizeInKBs(); // System.out.println("CacheSize = " + cacheSize + "KB"); assertTrue(cacheSize > 0); int reduceSize = 500; // System.out.println("performing GC with " + reduceSize // + " KB target reduction"); PictureTilingCacheGCManager.doGC(reduceSize); int gcRuns2 = PictureTilingCacheGCManager.getGCRuns(); assertEquals(1, gcRuns2 - gcRuns); long newCacheSize = PictureTilingCacheGCManager.getCacheSizeInKBs(); // System.out.println("new cacheSize = " + newCacheSize + "KB"); // System.out.println("effective delta = " + (cacheSize - newCacheSize) // + "KB"); assertTrue(cacheSize - newCacheSize > reduceSize); }
public static boolean gcIfNeeded() { gcCalls += 1; log.debug("GC Thread awake, see if there is some work to be done"); long totalSize = getCacheSizeInKBs(); long limit = getMaxDiskSpaceUsageKB(); if (totalSize < limit) { log.debug("No GC needed, go back to sleep for now"); return false; } // do the GC long deltaInKB = totalSize - limit; log.debug("GC needed to free " + deltaInKB + " KB of data"); doGC(deltaInKB); log.debug("GC terminated"); return true; }