guluo2016 commented on code in PR #8569:
URL: https://github.com/apache/hbase/pull/8569#discussion_r3873464406


##########
hbase-server/src/test/java/org/apache/hadoop/hbase/master/janitor/TestCatalogJanitor.java:
##########
@@ -690,6 +694,63 @@ public void testAlreadyRunningStatus() throws Exception {
     assertTrue(gcValues.contains(-1), "One janitor.scan() call should have 
returned -1");
   }
 
+  @Test
+  public void testAlreadyRunningStatusDoesNotClearLock() throws Exception {
+    CatalogJanitor spy = spy(this.janitor);
+
+    CountDownLatch scanStarted = new CountDownLatch(1);
+    CountDownLatch allowScanToFinish = new CountDownLatch(1);
+
+    doAnswer(invocation -> {
+      scanStarted.countDown();
+      allowScanToFinish.await();
+      return new CatalogJanitorReport();
+    }).when(spy).scanForReport();
+
+    Thread scanThread = new Thread(() -> {
+      try {
+        spy.scan();
+      } catch (IOException e) {
+        throw new RuntimeException(e);
+      }
+    });
+
+    // First scan acquires the lock and remains running.
+    scanThread.start();
+    assertTrue(scanStarted.await(5, TimeUnit.SECONDS));
+    LOG.info("First catalog janitor scan started and waiting to finish.");
+
+    // Second scan detects that another scan is running.
+    assertEquals(-1, spy.scan());
+    LOG.info("Second catalog janitor scan attempt returned -1.");
+
+    // The second scan must not clear the lock.
+    // Therefore, the third scan must also report that a scan is running.
+    try {
+      assertTimeoutPreemptively(
+        Duration.ofMinutes(1),

Review Comment:
   one minute is too long



-- 
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.

To unsubscribe, e-mail: [email protected]

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

Reply via email to