public void testExpiredData() throws InterruptedException {
    dc.put("k", "v", -1, 6000000);
    Thread.sleep(100);

    InternalCacheEntry entry = dc.get("k");
    assert entry.getClass().equals(transienttype());
    assert entry.getLastUsed() <= System.currentTimeMillis();
    long entryLastUsed = entry.getLastUsed();
    Thread.sleep(100);
    entry = dc.get("k");
    assert entry.getLastUsed() > entryLastUsed;
    dc.put("k", "v", -1, 0);
    dc.purgeExpired();

    dc.put("k", "v", 6000000, -1);
    Thread.sleep(100);
    assert dc.size() == 1;

    entry = dc.get("k");
    assert entry != null : "Entry should not be null!";
    assert entry.getClass().equals(mortaltype())
        : "Expected " + mortaltype() + ", was " + entry.getClass().getSimpleName();
    assert entry.getCreated() <= System.currentTimeMillis();

    dc.put("k", "v", 0, -1);
    Thread.sleep(10);
    assert dc.get("k") == null;
    assert dc.size() == 0;

    dc.put("k", "v", 0, -1);
    Thread.sleep(100);
    assert dc.size() == 1;
    dc.purgeExpired();
    assert dc.size() == 0;
  }
  public void testUpdatingLastUsed() throws Exception {
    long idle = 600000;
    dc.put("k", "v", -1, -1);
    InternalCacheEntry ice = dc.get("k");
    assert ice.getClass().equals(immortaltype());
    assert ice.getExpiryTime() == -1;
    assert ice.getMaxIdle() == -1;
    assert ice.getLifespan() == -1;
    dc.put("k", "v", -1, idle);
    long oldTime = System.currentTimeMillis();
    Thread.sleep(100); // for time calc granularity
    ice = dc.get("k");
    assert ice.getClass().equals(transienttype());
    assert ice.getExpiryTime() > -1;
    assert ice.getLastUsed() > oldTime;
    Thread.sleep(100); // for time calc granularity
    assert ice.getLastUsed() < System.currentTimeMillis();
    assert ice.getMaxIdle() == idle;
    assert ice.getLifespan() == -1;

    oldTime = System.currentTimeMillis();
    Thread.sleep(100); // for time calc granularity
    assert dc.get("k") != null;

    // check that the last used stamp has been updated on a get
    assert ice.getLastUsed() > oldTime;
    Thread.sleep(100); // for time calc granularity
    assert ice.getLastUsed() < System.currentTimeMillis();
  }
 @Override
 protected String toString(InternalCacheEntry ice) {
   if (ice == null) return null;
   StringBuilder sb = new StringBuilder(256);
   sb.append(ice.getClass().getSimpleName());
   sb.append("[key=").append(ice.getKey()).append(", value=").append(ice.getValue());
   sb.append(", created=").append(ice.getCreated()).append(", isCreated=").append(ice.isCreated());
   sb.append(", lastUsed=")
       .append(ice.getLastUsed())
       .append(", isChanged=")
       .append(ice.isChanged());
   sb.append(", expires=")
       .append(ice.getExpiryTime())
       .append(", isExpired=")
       .append(ice.isExpired(System.currentTimeMillis()));
   sb.append(", canExpire=")
       .append(ice.canExpire())
       .append(", isEvicted=")
       .append(ice.isEvicted());
   sb.append(", isRemoved=").append(ice.isRemoved()).append(", isValid=").append(ice.isValid());
   sb.append(", lifespan=")
       .append(ice.getLifespan())
       .append(", maxIdle=")
       .append(ice.getMaxIdle());
   return sb.append(']').toString();
 }
 private void assertContainerEntry(
     Class<? extends InternalCacheEntry> type, String expectedValue) {
   assert dc.containsKey("k");
   InternalCacheEntry entry = dc.get("k");
   assertEquals(type, entry.getClass());
   assertEquals(expectedValue, entry.getValue());
 }