jchen21 commented on a change in pull request #6042:
URL: https://github.com/apache/geode/pull/6042#discussion_r582366221



##########
File path: 
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/versions/TombstoneDUnitTest.java
##########
@@ -117,35 +118,74 @@ public void 
testTombstoneGcMessagesBetweenPersistentAndNonPersistentRegion() {
     });
   }
 
+
   @Test
-  public void testGetOldestTombstoneTimeReplicate() {
+  public void 
testWhenAnOutOfRangeTimeStampIsSeenWeExpireItInReplicateTombstoneSweeper() {
     VM server1 = VM.getVM(0);
     VM server2 = VM.getVM(1);
+    final int FAR_INTO_THE_FUTURE = 1000000; // 1 million millis into the 
future
 
+    final int count = 10;
     server1.invoke(() -> {
-      createCacheAndRegion(REPLICATE_PERSISTENT);
-      region.put("K1", "V1");
-      region.put("K2", "V2");
+      createCacheAndRegion(RegionShortcut.REPLICATE_PERSISTENT);
+      for (int i = 0; i < count; i++) {
+        region.put("K" + i, "V" + i);
+      }
     });
 
-    server2.invoke(() -> createCacheAndRegion(REPLICATE));
+    server2.invoke(() -> createCacheAndRegion(RegionShortcut.REPLICATE));
 
     server1.invoke(() -> {
+      TombstoneService.TombstoneSweeper tombstoneSweeper =
+          ((InternalCache) 
cache).getTombstoneService().getSweeper((LocalRegion) region);
+
+      RegionEntry regionEntry = ((LocalRegion) region).getRegionEntry("K0");
+      VersionTag<?> versionTag = regionEntry.getVersionStamp().asVersionTag();
+      versionTag.setVersionTimeStamp(System.currentTimeMillis() + 
FAR_INTO_THE_FUTURE);
+
+      TombstoneService.Tombstone modifiedTombstone =
+          new TombstoneService.Tombstone(regionEntry, (LocalRegion) region,
+              versionTag);
+      tombstoneSweeper.tombstones.add(modifiedTombstone);
+      tombstoneSweeper.checkOldestUnexpired(System.currentTimeMillis());
       // Send tombstone gc message to vm1.
-      region.destroy("K1");
+      assertThat(tombstoneSweeper.getOldestTombstoneTime()).isEqualTo(0);
+    });
+  }
 
+  @Test
+  public void testGetOldestTombstoneTimeForReplicateTombstoneSweeper() {
+    VM server1 = VM.getVM(0);
+    VM server2 = VM.getVM(1);
+    final int count = 10;
+    server1.invoke(() -> {
+      createCacheAndRegion(RegionShortcut.REPLICATE_PERSISTENT);
+      for (int i = 0; i < count; i++) {
+        region.put("K" + i, "V" + i);
+      }
+    });
+
+    server2.invoke(() -> createCacheAndRegion(RegionShortcut.REPLICATE));
+
+    server1.invoke(() -> {
       TombstoneService.TombstoneSweeper tombstoneSweeper =
           ((InternalCache) 
cache).getTombstoneService().getSweeper((LocalRegion) region);
+      // Send tombstone gc message to vm1.
+      for (int i = 0; i < count; i++) {
+        region.destroy("K" + i);
+        assertThat(

Review comment:
       First, usually immediately after `Region.destroy()`, the difference 
between `tombstoneSweeper.getOldestTombstoneTime()` and 
`System.currentTimeMillis()` is only a few milliseconds. So asserting that 
   ```
   tombstoneSweeper.getOldestTombstoneTime()
                   + TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT_DEFAULT - 
System.currentTimeMillis())
                       .isGreaterThan(0)
   ```
   is like asserting `REPLICATE_TOMBSTONE_TIMEOUT_DEFAULT` is greater than 0, 
i.e. asserting 600000 > 0. There is nothing wrong with that. However, a better 
assertion would be the one you deleted:
   ```
         assertThat(tombstoneSweeper.getOldestTombstoneTime()).isGreaterThan(0)
             .isLessThan(((InternalCache) cache).cacheTimeMillis());
   ```
   Second, if we expect that GC clears out tombstones, I would recommend moving 
the following assertion
   ```
   assertThat(tombstoneSweeper.getOldestTombstoneTime()).isEqualTo(0)
   ```
    into the `for` loop, instead of after the `for` loop.
   Please correct me if I am wrong.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to