You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/02/20 19:38:02 UTC

[GitHub] sijie closed pull request #1165: Issue #1164: TestTruncate#testPurgeLogs is flaky

sijie closed pull request #1165: Issue #1164: TestTruncate#testPurgeLogs is flaky
URL: https://github.com/apache/bookkeeper/pull/1165
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/stream/distributedlog/core/src/main/java/org/apache/distributedlog/BKAbstractLogWriter.java b/stream/distributedlog/core/src/main/java/org/apache/distributedlog/BKAbstractLogWriter.java
index 1e24225ba..fb40a6b8c 100644
--- a/stream/distributedlog/core/src/main/java/org/apache/distributedlog/BKAbstractLogWriter.java
+++ b/stream/distributedlog/core/src/main/java/org/apache/distributedlog/BKAbstractLogWriter.java
@@ -76,6 +76,11 @@
                 TimeUnit.MILLISECONDS.convert(dynConf.getRetentionPeriodHours(), TimeUnit.HOURS));
     }
 
+    @VisibleForTesting
+    CompletableFuture<List<LogSegmentMetadata>> getLastTruncationAttempt() {
+        return lastTruncationAttempt;
+    }
+
     // manage write handler
 
     protected synchronized BKLogWriteHandler getCachedWriteHandler() {
diff --git a/stream/distributedlog/core/src/test/java/org/apache/distributedlog/TestTruncate.java b/stream/distributedlog/core/src/test/java/org/apache/distributedlog/TestTruncate.java
index ae2ebf498..b4c3f409d 100644
--- a/stream/distributedlog/core/src/test/java/org/apache/distributedlog/TestTruncate.java
+++ b/stream/distributedlog/core/src/test/java/org/apache/distributedlog/TestTruncate.java
@@ -17,11 +17,17 @@
  */
 package org.apache.distributedlog;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import java.net.URI;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 import org.apache.commons.lang3.tuple.ImmutablePair;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.distributedlog.LogSegmentMetadata.TruncationStatus;
@@ -34,9 +40,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
-
-
 /**
  * Test Cases for truncation.
  */
@@ -105,9 +108,13 @@ public void testPurgeLogs() throws Exception {
             Utils.ioResult(writer.write(DLMTestUtil.getLogRecordInstance(txid++)));
         }
 
-        // to make sure the truncation task is executed
-        DLSN lastDLSN = Utils.ioResult(dlm.getLastDLSNAsync());
-        LOG.info("Get last dlsn of stream {} : {}", name, lastDLSN);
+        // wait until truncation task to be completed.
+        BKAsyncLogWriter bkLogWriter = (BKAsyncLogWriter) writer;
+        CompletableFuture<List<LogSegmentMetadata>> truncationAttempt = bkLogWriter.getLastTruncationAttempt();
+        while (truncationAttempt == null || !truncationAttempt.isDone()) {
+            TimeUnit.MILLISECONDS.sleep(20);
+            truncationAttempt = bkLogWriter.getLastTruncationAttempt();
+        }
 
         assertEquals(6, distributedLogManager.getLogSegments().size());
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services