/** teardown */
 @Override
 @After
 public void tearDown() throws Exception {
   if (selfPopulatingCache != null) {
     selfPopulatingCache.removeAll();
   }
   if (manager != null) {
     manager.shutdown();
   }
   super.tearDown();
 }
  /**
   * Tests discarding little used entries. <cache name="sampleIdlingExpiringCache"
   * maxElementsInMemory="1" eternal="false" timeToIdleSeconds="2" timeToLiveSeconds="5"
   * overflowToDisk="true" />
   */
  public void testDiscardLittleUsed() throws Exception {
    final CacheEntryFactory factory = new CountingCacheEntryFactory("value");
    selfPopulatingCache = new SelfPopulatingCache(cache, factory);

    selfPopulatingCache.get("key1");
    selfPopulatingCache.get("key2");
    assertEquals(2, selfPopulatingCache.getSize());
    selfPopulatingCache.refresh();
    assertEquals(2, selfPopulatingCache.getSize());
    Thread.sleep(2020);

    // Will be two, because counting expired elements
    assertEquals(2, selfPopulatingCache.getSize());

    // Check the cache
    selfPopulatingCache.removeAll();
    assertEquals(0, selfPopulatingCache.getSize());
  }
 /** teardown */
 protected void tearDown() throws Exception {
   selfPopulatingCache.removeAll();
   manager.shutdown();
   super.tearDown();
 }