@Test
  public void testTimeStats() throws CacheException, InterruptedException {
    final long ESTAT_RES = 100; // the resolution, in ms, of entry stats
    String name = getUniqueName();
    Object key1 = 1;
    Object key2 = 2;
    Object missingKey = 999;
    Object value = "VALUE";
    long before;
    long after;
    long oldBefore;
    long oldAfter;

    AttributesFactory factory = new AttributesFactory();
    // factory.setScope(Scope.LOCAL);
    factory.setStatisticsEnabled(true);

    Region region = createPartitionedRegion(name, factory.create());
    CacheStatistics rStats = region.getStatistics();

    assertEquals(0, rStats.getLastAccessedTime());
    assertEquals(0, rStats.getLastModifiedTime());

    before = ((InternalRegion) region).cacheTimeMillis();
    // When the get is invoked, the lastAccessedTime and lastModified time
    // are updated as a new BucketRegion is created.
    region.get(missingKey);

    after = ((InternalRegion) region).cacheTimeMillis();

    assertInRange(before, after, rStats.getLastAccessedTime());
    assertInRange(before, after, rStats.getLastModifiedTime());

    oldBefore = before;
    oldAfter = after;
    waitForClockToChange(region);
    before = ((InternalRegion) region).cacheTimeMillis();
    region.get(missingKey);

    after = ((InternalRegion) region).cacheTimeMillis();

    assertInRange(before, after, rStats.getLastAccessedTime());
    assertInRange(oldBefore, oldAfter, rStats.getLastModifiedTime());

    waitForClockToChange(region);
    before = ((InternalRegion) region).cacheTimeMillis();
    region.put(key1, value);
    CacheStatistics eStats = region.getEntry(key1).getStatistics();
    after = ((InternalRegion) region).cacheTimeMillis();

    assertInRange(before, after, rStats.getLastModifiedTime());
    assertInRange(before, after, rStats.getLastAccessedTime());

    assertInRange(before - ESTAT_RES, after + ESTAT_RES, eStats.getLastAccessedTime());
    assertInRange(before - ESTAT_RES, after + ESTAT_RES, eStats.getLastModifiedTime());

    oldBefore = before;
    oldAfter = after;
    waitForClockToChange(region);
    before = ((InternalRegion) region).cacheTimeMillis();
    region.get(key1);
    // eStats must be obtained again. The previous object is not updated.
    // Seems it just provides a snapshot at the moment it is received.
    eStats = region.getEntry(key1).getStatistics();
    after = ((InternalRegion) region).cacheTimeMillis();

    assertInRange(before, after, rStats.getLastAccessedTime());
    assertInRange(oldBefore, oldAfter, rStats.getLastModifiedTime());
    assertInRange(before - ESTAT_RES, after + ESTAT_RES, eStats.getLastAccessedTime());
    assertInRange(oldBefore - ESTAT_RES, oldAfter + ESTAT_RES, eStats.getLastModifiedTime());

    long oldOldBefore = oldBefore;
    long oldOldAfter = oldAfter;
    oldBefore = before;
    oldAfter = after;
    waitForClockToChange(region, ESTAT_RES);
    before = ((InternalRegion) region).cacheTimeMillis();
    region.create(key2, null);
    region.get(key2);
    CacheStatistics eStats2 = region.getEntry(key2).getStatistics();
    after = ((InternalRegion) region).cacheTimeMillis();

    assertInRange(before, after, rStats.getLastModifiedTime());
    assertInRange(before, after, rStats.getLastAccessedTime());

    assertInRange(oldBefore - ESTAT_RES, oldAfter + ESTAT_RES, eStats.getLastAccessedTime());
    assertInRange(oldOldBefore - ESTAT_RES, oldOldAfter + ESTAT_RES, eStats.getLastModifiedTime());

    assertInRange(before - ESTAT_RES, after + ESTAT_RES, eStats2.getLastAccessedTime());
    assertInRange(before - ESTAT_RES, after + ESTAT_RES, eStats2.getLastModifiedTime());

    // Invalidation does not update the modification/access
    // times
    region.invalidate(key2);

    assertInRange(before, after, rStats.getLastModifiedTime());
    assertInRange(before - ESTAT_RES, after + ESTAT_RES, eStats2.getLastAccessedTime());
    assertInRange(before - ESTAT_RES, after + ESTAT_RES, eStats2.getLastModifiedTime());
    assertInRange(before, after, rStats.getLastAccessedTime());

    region.destroy(key2);

    assertInRange(before, after, rStats.getLastModifiedTime());
    assertInRange(before, after, rStats.getLastAccessedTime());
  }
Tests that the {@linkplain CacheStatistics#getLastAccessedTime last access time} and
{@link CacheStatistics#getLastModifiedTime last modified time} are updated appropriately for a
partitioned region with only one server.
geode-core/src/distributedTest/java/org/apache/geode/cache30/CacheStatisticsPartitionedRegionDUnitTest.java