You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sh...@apache.org on 2020/04/27 10:37:47 UTC

[incubator-ratis] branch master updated: RATIS-885. Fix Failed UT because error use of attemptRepeatedly to check boolean condition (#68)

This is an automated email from the ASF dual-hosted git repository.

shashikant pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new a611ccf  RATIS-885. Fix Failed UT because error use of attemptRepeatedly to check boolean condition (#68)
a611ccf is described below

commit a611ccf1b2ac29f3c6e732ab530e6e4f4f08c014
Author: runzhiwang <51...@users.noreply.github.com>
AuthorDate: Mon Apr 27 18:37:40 2020 +0800

    RATIS-885. Fix Failed UT because error use of attemptRepeatedly to check boolean condition (#68)
---
 .../apache/ratis/InstallSnapshotNotificationTests.java | 12 ++++++++----
 .../ratis/server/impl/RaftReconfigurationBaseTest.java | 12 ++++++++----
 .../ratis/statemachine/RaftSnapshotBaseTest.java       | 12 ++++++++----
 .../org/apache/ratis/server/ServerRestartTests.java    | 18 ++++++++++++------
 4 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/ratis-server/src/test/java/org/apache/ratis/InstallSnapshotNotificationTests.java b/ratis-server/src/test/java/org/apache/ratis/InstallSnapshotNotificationTests.java
index 6ab767e..9cf4652 100644
--- a/ratis-server/src/test/java/org/apache/ratis/InstallSnapshotNotificationTests.java
+++ b/ratis-server/src/test/java/org/apache/ratis/InstallSnapshotNotificationTests.java
@@ -136,8 +136,10 @@ public abstract class InstallSnapshotNotificationTests<CLUSTER extends MiniRaftC
       LOG.info("nextIndex = {}", nextIndex);
       final List<File> snapshotFiles = RaftSnapshotBaseTest.getSnapshotFiles(cluster,
           nextIndex - SNAPSHOT_TRIGGER_THRESHOLD, nextIndex);
-      JavaUtils.attemptRepeatedly(() -> snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists),
-          10, ONE_SECOND, "snapshotFile.exist", LOG);
+      JavaUtils.attemptRepeatedly(() -> {
+        Assert.assertTrue(snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists));
+        return null;
+      }, 10, ONE_SECOND, "snapshotFile.exist", LOG);
       logs = storageDirectory.getLogSegmentFiles();
     } finally {
       cluster.shutdown();
@@ -212,8 +214,10 @@ public abstract class InstallSnapshotNotificationTests<CLUSTER extends MiniRaftC
       LOG.info("{}: oldLeaderNextIndex = {}", leaderId, oldLeaderNextIndex);
       final List<File> snapshotFiles = RaftSnapshotBaseTest.getSnapshotFiles(cluster,
           oldLeaderNextIndex - SNAPSHOT_TRIGGER_THRESHOLD, oldLeaderNextIndex);
-      JavaUtils.attemptRepeatedly(() -> snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists),
-          10, ONE_SECOND, "snapshotFile.exist", LOG);
+      JavaUtils.attemptRepeatedly(() -> {
+        Assert.assertTrue(snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists));
+        return null;
+      }, 10, ONE_SECOND, "snapshotFile.exist", LOG);
     }
 
     final RaftPeerId followerId = cluster.getFollowers().get(0).getId();
diff --git a/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java b/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java
index 4302249..f7545bc 100644
--- a/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java
+++ b/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftReconfigurationBaseTest.java
@@ -532,8 +532,10 @@ public abstract class RaftReconfigurationBaseTest<CLUSTER extends MiniRaftCluste
       }, 10, sleepTime, "confIndex", LOG);
 
       // wait till the old leader persist the new conf
-      JavaUtils.attemptRepeatedly(() -> log.getFlushIndex() >= confIndex,
-          10, sleepTime, "FLUSH", LOG);
+      JavaUtils.attemptRepeatedly(() -> {
+        Assert.assertTrue(log.getFlushIndex() >= confIndex);
+        return null;
+      }, 10, sleepTime, "FLUSH", LOG);
       final long committed = log.getLastCommittedIndex();
       Assert.assertTrue(committed < confIndex);
 
@@ -546,8 +548,10 @@ public abstract class RaftReconfigurationBaseTest<CLUSTER extends MiniRaftCluste
       Assert.assertTrue(gotNotLeader.get());
 
       // the old leader should have truncated the setConf from the log
-      JavaUtils.attemptRepeatedly(() -> log.getLastCommittedIndex() >= confIndex,
-          10, ONE_SECOND, "COMMIT", LOG);
+      JavaUtils.attemptRepeatedly(() -> {
+        Assert.assertTrue(log.getLastCommittedIndex() >= confIndex);
+        return null;
+      }, 10, ONE_SECOND, "COMMIT", LOG);
       Assert.assertTrue(log.get(confIndex).hasConfigurationEntry());
       log2 = null;
     } finally {
diff --git a/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java b/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java
index 9b36ec6..712b8b3 100644
--- a/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java
+++ b/ratis-server/src/test/java/org/apache/ratis/statemachine/RaftSnapshotBaseTest.java
@@ -149,8 +149,10 @@ public abstract class RaftSnapshotBaseTest extends BaseTest {
     LOG.info("nextIndex = {}", nextIndex);
     // wait for the snapshot to be done
     final List<File> snapshotFiles = getSnapshotFiles(cluster, nextIndex - SNAPSHOT_TRIGGER_THRESHOLD, nextIndex);
-    JavaUtils.attemptRepeatedly(() -> snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists),
-        10, ONE_SECOND, "snapshotFile.exist", LOG);
+    JavaUtils.attemptRepeatedly(() -> {
+      Assert.assertTrue(snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists));
+      return null;
+    }, 10, ONE_SECOND, "snapshotFile.exist", LOG);
 
     // restart the peer and check if it can correctly load snapshot
     cluster.restart(false);
@@ -197,8 +199,10 @@ public abstract class RaftSnapshotBaseTest extends BaseTest {
       final long nextIndex = cluster.getLeader().getState().getLog().getNextIndex();
       LOG.info("nextIndex = {}", nextIndex);
       final List<File> snapshotFiles = getSnapshotFiles(cluster, nextIndex - SNAPSHOT_TRIGGER_THRESHOLD, nextIndex);
-      JavaUtils.attemptRepeatedly(() -> snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists),
-          10, ONE_SECOND, "snapshotFile.exist", LOG);
+      JavaUtils.attemptRepeatedly(() -> {
+        Assert.assertTrue(snapshotFiles.stream().anyMatch(RaftSnapshotBaseTest::exists));
+        return null;
+      }, 10, ONE_SECOND, "snapshotFile.exist", LOG);
       logs = storageDirectory.getLogSegmentFiles();
     } finally {
       cluster.shutdown();
diff --git a/ratis-test/src/test/java/org/apache/ratis/server/ServerRestartTests.java b/ratis-test/src/test/java/org/apache/ratis/server/ServerRestartTests.java
index d420709..ab277de 100644
--- a/ratis-test/src/test/java/org/apache/ratis/server/ServerRestartTests.java
+++ b/ratis-test/src/test/java/org/apache/ratis/server/ServerRestartTests.java
@@ -112,8 +112,10 @@ public abstract class ServerRestartTests<CLUSTER extends MiniRaftCluster>
     final long leaderLastIndex = cluster.getLeader().getState().getLog().getLastEntryTermIndex().getIndex();
     // make sure the restarted follower can catchup
     final ServerState followerState = cluster.getRaftServerImpl(followerId).getState();
-    JavaUtils.attemptRepeatedly(() -> followerState.getLastAppliedIndex() >= leaderLastIndex,
-        10, ONE_SECOND, "follower catchup", LOG);
+    JavaUtils.attemptRepeatedly(() -> {
+      Assert.assertTrue(followerState.getLastAppliedIndex() >= leaderLastIndex);
+      return null;
+    }, 10, ONE_SECOND, "follower catchup", LOG);
 
     // make sure the restarted peer's log segments is correct
     final RaftServerImpl follower = cluster.restartServer(followerId, false);
@@ -292,10 +294,14 @@ public abstract class ServerRestartTests<CLUSTER extends MiniRaftCluster>
       cluster.restartServer(id, false);
       final RaftServerImpl server = cluster.getRaftServerImpl(id);
       final RaftLog raftLog = server.getState().getLog();
-      JavaUtils.attemptRepeatedly(() -> raftLog.getLastCommittedIndex() >= loggedCommitIndex,
-          10, HUNDRED_MILLIS, id + "(commitIndex >= loggedCommitIndex)", LOG);
-      JavaUtils.attemptRepeatedly(() -> server.getState().getLastAppliedIndex() >= loggedCommitIndex,
-          10, HUNDRED_MILLIS, id + "(lastAppliedIndex >= loggedCommitIndex)", LOG);
+      JavaUtils.attemptRepeatedly(() -> {
+        Assert.assertTrue(raftLog.getLastCommittedIndex() >= loggedCommitIndex);
+        return null;
+      }, 10, HUNDRED_MILLIS, id + "(commitIndex >= loggedCommitIndex)", LOG);
+      JavaUtils.attemptRepeatedly(() -> {
+        Assert.assertTrue(server.getState().getLastAppliedIndex() >= loggedCommitIndex);
+        return null;
+      }, 10, HUNDRED_MILLIS, id + "(lastAppliedIndex >= loggedCommitIndex)", LOG);
       LOG.info("{}: commitIndex={}, lastAppliedIndex={}",
           id, raftLog.getLastCommittedIndex(), server.getState().getLastAppliedIndex());
       cluster.killServer(id);