@Test
  @Ignore // FIXME started breaking 8/10
  public void testRefreshNoisily() throws Exception {
    final CountingCacheEntryFactory factory = new CountingCacheEntryFactory("value");
    CountingCacheEventListener countingCacheEventListener = new CountingCacheEventListener();
    CountingCacheEventListener.resetCounters();
    cache.getCacheEventNotificationService().registerListener(countingCacheEventListener);
    selfPopulatingCache = new SelfPopulatingCache(cache, factory);

    // check initial conditions on counters
    assertEquals(0, CountingCacheEventListener.getCacheElementsPut(cache).size());
    assertEquals(0, CountingCacheEventListener.getCacheElementsUpdated(cache).size());

    Element e1 = selfPopulatingCache.get("key1");
    Element e2 = selfPopulatingCache.get("key2");
    assertEquals(2, factory.getCount());
    assertEquals(2, CountingCacheEventListener.getCacheElementsPut(cache).size());
    assertEquals(0, CountingCacheEventListener.getCacheElementsUpdated(cache).size());
    long lastUpdateTime1 = e1.getLastUpdateTime();
    long lastUpdateTime2 = e2.getLastUpdateTime();

    // wait a little so creation time to allow CPU clock to advance
    Thread.sleep(100L);

    // full refresh
    selfPopulatingCache.refresh(false);
    assertEquals(4, factory.getCount());
    assertEquals(2, CountingCacheEventListener.getCacheElementsPut(cache).size());
    assertEquals(2, CountingCacheEventListener.getCacheElementsUpdated(cache).size());
    e1 = selfPopulatingCache.get("key1");
    e2 = selfPopulatingCache.get("key2");
    assertEquals(4, factory.getCount());
    assertEquals(2, CountingCacheEventListener.getCacheElementsPut(cache).size());
    assertEquals(2, CountingCacheEventListener.getCacheElementsUpdated(cache).size());
    assertFalse(
        "getLastUpdateTime() should not be the same (" + lastUpdateTime1 + ")",
        lastUpdateTime1 == e1.getLastUpdateTime());
    assertFalse(
        "getLastUpdateTime() should not be the same (" + lastUpdateTime2 + ")",
        lastUpdateTime2 == e2.getLastUpdateTime());
    lastUpdateTime2 = e2.getLastUpdateTime();

    // wait a little to allow CPU clock to advance
    Thread.sleep(100L);

    // single element refresh
    e2 = selfPopulatingCache.refresh("key2", false);
    assertEquals(5, factory.getCount());
    assertEquals(2, CountingCacheEventListener.getCacheElementsPut(cache).size());
    assertEquals(3, CountingCacheEventListener.getCacheElementsUpdated(cache).size());
    assertFalse(
        "getLastUpdateTime() should not be the same (" + lastUpdateTime2 + ")",
        lastUpdateTime2 == e2.getLastUpdateTime());
  }
  /** Tests that an entry is created once only. */
  public void testCreateOnce() throws Exception {
    final String value = "value";
    final CountingCacheEntryFactory factory = new CountingCacheEntryFactory(value);
    selfPopulatingCache = new SelfPopulatingCache(cache, factory);

    // Fetch the value several times
    for (int i = 0; i < 5; i++) {
      assertSame(value, selfPopulatingCache.get("key").getObjectValue());
      assertEquals(1, factory.getCount());
    }
  }
  /** Tests refreshing the entries. */
  public void testRefresh() throws Exception {
    final String value = "value";
    final CountingCacheEntryFactory factory = new CountingCacheEntryFactory(value);
    selfPopulatingCache = new SelfPopulatingCache(cache, factory);

    // Check the value
    assertSame(value, selfPopulatingCache.get("key").getObjectValue());
    assertEquals(1, factory.getCount());

    // Refresh
    selfPopulatingCache.refresh();
    assertEquals(2, factory.getCount());

    // Check the value
    assertSame(value, selfPopulatingCache.get("key").getObjectValue());
    assertEquals(2, factory.getCount());
  }
  /** Tests refreshing the entries. */
  @Test
  public void testRefreshWithException() throws Exception {
    final String value = "value";
    final CountingCacheEntryFactory factory = new CountingCacheEntryFactory(value);
    selfPopulatingCache = new SelfPopulatingCache(cache, factory);

    // Check the value
    String explodingKey = "explode";
    assertSame(value, selfPopulatingCache.get(explodingKey).getObjectValue());
    assertEquals(1, factory.getCount());

    // Refresh
    try {
      selfPopulatingCache.refresh();
      fail("This should have exploded!");
    } catch (CacheException e) {
      assertNotNull(e.getCause());
      assertEquals(
          e.getCause().getMessage() + " on refresh with key " + explodingKey, e.getMessage());
    }
  }