Beispiel #1
0
  @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);
  }
Beispiel #2
0
  @Test
  public void testGC2() throws Exception {
    int reduceSize = 500;
    int gcRuns = PictureTilingCacheGCManager.getGCRuns();
    int gcCalls = PictureTilingCacheGCManager.getGCCalls();
    PictureTilingComponent.endGC();

    String maxStr =
        PictureTilingComponent.getEnvValue(
            PictureTilingCacheGCManager.MAX_DISK_SPACE_USAGE_KEY,
            Long.toString(PictureTilingCacheGCManager.MAX_DISK_SPACE_USAGE_KB));
    PictureTilingComponent.setEnvValue(
        PictureTilingCacheGCManager.MAX_DISK_SPACE_USAGE_KEY, Integer.toString(reduceSize));

    PictureTilingService pts = Framework.getLocalService(PictureTilingService.class);
    assertNotNull(pts);
    benchTiler(pts, new MagickTiler());

    // System.out.println("Tiling run 1");
    testMagick2();
    // System.out.println("Tiling run 2");
    testMagick2();
    // System.out.println("Tiling run 3");
    testMagick2();

    long cacheSize = PictureTilingCacheGCManager.getCacheSizeInKBs();
    // System.out.println("CacheSize = " + cacheSize + "KB");
    assertTrue(cacheSize > 0);

    GCTask.setGCIntervalInMinutes(-100);
    PictureTilingComponent.startGC();

    // System.out.println("waiting for GC to run");
    Thread.currentThread().sleep(600);

    int gcRuns2 = PictureTilingCacheGCManager.getGCRuns();
    int gcCalls2 = PictureTilingCacheGCManager.getGCCalls();

    int runs = gcRuns2 - gcRuns;
    int calls = gcCalls2 - gcCalls;
    // System.out.println("GC runs = " + runs);
    // System.out.println("GC calls = " + calls);

    assertTrue(runs > 0);
    assertTrue(calls > 2);

    PictureTilingComponent.endGC();

    long newCacheSize = PictureTilingCacheGCManager.getCacheSizeInKBs();
    // System.out.println("new cacheSize = " + newCacheSize + "KB");
    // System.out.println("effective delta = " + (cacheSize - newCacheSize)
    // + "KB");
    assertTrue(cacheSize - newCacheSize > reduceSize);

    PictureTilingComponent.setEnvValue(
        PictureTilingCacheGCManager.MAX_DISK_SPACE_USAGE_KEY, maxStr);
  }