diff --git a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java index a105ff35e6..64d667955d 100644 --- a/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java +++ b/ratis-common/src/main/java/org/apache/ratis/protocol/RaftClientReply.java @@ -178,10 +178,10 @@ public static Builder newBuilder() { } /** - * Get the peer information for the entire group. - * The peer information may be unavailable for exception reply. + * Get the commit information for the entire group. + * The commit information may be unavailable for exception reply. * - * @return the peer information if it is available; otherwise, return null. + * @return the commit information if it is available; otherwise, return null. */ public Collection getCommitInfos() { return commitInfos; @@ -200,7 +200,7 @@ public long getLogIndex() { public String toString() { return super.toString() + ", " + (isSuccess()? "SUCCESS": "FAILED " + exception) - + ", logIndex=" + getLogIndex() + ", peer info=" + ProtoUtils.toString(commitInfos); + + ", logIndex=" + getLogIndex() + ", commits" + ProtoUtils.toString(commitInfos); } public boolean isSuccess() { diff --git a/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java b/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java index c1f768f68d..7f0cb56204 100644 --- a/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java +++ b/ratis-common/src/main/java/org/apache/ratis/util/ProtoUtils.java @@ -227,9 +227,9 @@ static String toString(CommitInfoProto proto) { } static String toString(LogInfoProto proto) { -// return RaftPeerId.valueOf(proto.getCommitInfo().getServer().getId()) -// + ":c" + proto.getCommitInfo().getCommitIndex(); - return "test"; + return "lastSnapshot: " + proto.getLastSnapshot() + + ", applied: " + proto.getApplied() + + ", committed: " + proto.getCommitted(); } static String toString(Collection protos) { diff --git a/ratis-server/src/test/java/org/apache/ratis/RaftAsyncTests.java b/ratis-server/src/test/java/org/apache/ratis/RaftAsyncTests.java index 4f3867e42e..71c5c5ef06 100644 --- a/ratis-server/src/test/java/org/apache/ratis/RaftAsyncTests.java +++ b/ratis-server/src/test/java/org/apache/ratis/RaftAsyncTests.java @@ -64,7 +64,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; import java.util.stream.StreamSupport; import static org.apache.ratis.RaftTestUtil.waitForLeader; diff --git a/ratis-server/src/test/java/org/apache/ratis/WatchRequestTests.java b/ratis-server/src/test/java/org/apache/ratis/WatchRequestTests.java index db8d471de6..a9bdd1a3a9 100644 --- a/ratis-server/src/test/java/org/apache/ratis/WatchRequestTests.java +++ b/ratis-server/src/test/java/org/apache/ratis/WatchRequestTests.java @@ -283,7 +283,6 @@ static void checkMajority(List> replies, final RaftClientReply watchMajorityCommittedReply = watchReplies.getMajorityCommitted(); { // check commit infos final Collection commitInfos = watchMajorityCommittedReply.getCommitInfos(); - final String message = "logIndex=" + logIndex + ", " + ProtoUtils.toString(commitInfos); Assert.assertEquals(NUM_SERVERS, commitInfos.size()); diff --git a/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupInfoBaseTest.java b/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupInfoBaseTest.java index 758414ff05..72eedf0f32 100644 --- a/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupInfoBaseTest.java +++ b/ratis-server/src/test/java/org/apache/ratis/server/impl/GroupInfoBaseTest.java @@ -105,8 +105,7 @@ private void runTest(CLUSTER cluster) throws Exception { try(final RaftClient client = cluster.createClient(peer.getId())) { final GroupListReply info = client.getGroupManagementApi(peer.getId()).list(); Assert.assertEquals(1, info.getGroupIds().stream().filter(id -> group.getGroupId().equals(id)).count()); - Collection commitInfoProtos = info.getCommitInfos(); - for(CommitInfoProto i : commitInfoProtos) { + for(CommitInfoProto i : info.getCommitInfos()) { if (RaftPeerId.valueOf(i.getServer().getId()).equals(killedFollower)) { Assert.assertTrue(i.getCommitIndex() <= maxCommit); } else { diff --git a/ratis-server/src/test/java/org/apache/ratis/server/impl/StateMachineShutdownTests.java b/ratis-server/src/test/java/org/apache/ratis/server/impl/StateMachineShutdownTests.java index 5e1ff7f153..246abb99f0 100644 --- a/ratis-server/src/test/java/org/apache/ratis/server/impl/StateMachineShutdownTests.java +++ b/ratis-server/src/test/java/org/apache/ratis/server/impl/StateMachineShutdownTests.java @@ -98,7 +98,7 @@ public void testStateMachineShutdownWaitsForApplyTxn() throws Exception { RaftClientReply watchReply = client.io().watch( logIndex, RaftProtos.ReplicationLevel.ALL_COMMITTED); watchReply.getCommitInfos().forEach( - val -> Assert.assertTrue(val.getCommitIndex() >= logIndex)); + val -> Assert.assertTrue(val.getCommitIndex() >= logIndex)); final RaftServer.Division secondFollower = cluster.getFollowers().get(1); // Second follower is blocked in apply transaction Assert.assertTrue(secondFollower.getInfo().getLastAppliedIndex() < logIndex); diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractRatisCommand.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractRatisCommand.java index 0e7b358c41..cc3357ac92 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractRatisCommand.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/command/AbstractRatisCommand.java @@ -40,7 +40,6 @@ import java.util.stream.Collectors; import java.util.stream.Stream; - /** * The base class for the ratis shell which need to connect to server. */ @@ -120,9 +119,9 @@ public int run(CommandLine cl) throws IOException { } groupInfoReply = run(peers, p -> client.getGroupManagementApi((p.getId())).info(remoteGroupId)); - processReply(groupInfoReply, - () -> "Failed to get group info for group id " + remoteGroupId.getUuid() + " from " + peers); - raftGroup = groupInfoReply.getGroup(); + processReply(groupInfoReply, + () -> "Failed to get group info for group id " + remoteGroupId.getUuid() + " from " + peers); + raftGroup = groupInfoReply.getGroup(); } return 0; } diff --git a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/group/GroupInfoCommand.java b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/group/GroupInfoCommand.java index 4d3c396abc..0125440e90 100644 --- a/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/group/GroupInfoCommand.java +++ b/ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/group/GroupInfoCommand.java @@ -26,7 +26,6 @@ import java.io.IOException; - /** * Command for querying ratis group information. */ diff --git a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/ElectionCommandIntegrationTest.java b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/ElectionCommandIntegrationTest.java index 01f5239246..a61bb19f73 100644 --- a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/ElectionCommandIntegrationTest.java +++ b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/ElectionCommandIntegrationTest.java @@ -103,8 +103,8 @@ void runTestElectionTransferCommandToHigherPriority(MiniRaftCluster cluster) thr // verify that priorities of new leader and old leader are both 2 ret = shell.run("group", "info", "-peers", address); Assertions.assertEquals(0 , ret); - String expected = String.format("\"%s\"%n priority: %d", newLeader.getPeer().getAddress(), 2); - String expected2 = String.format("\"%s\"%n priority: %d", leader.getPeer().getAddress(), 2); + String expected = String.format("\"%s\"%n priority: %d", newLeader.getPeer().getAddress(), 2); + String expected2 = String.format("\"%s\"%n priority: %d", leader.getPeer().getAddress(), 2); Assertions.assertTrue(out.toString().contains(expected)); Assertions.assertTrue(out.toString().contains(expected2)); } diff --git a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/GroupCommandIntegrationTest.java b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/GroupCommandIntegrationTest.java index c686f79359..d523e0f371 100644 --- a/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/GroupCommandIntegrationTest.java +++ b/ratis-test/src/test/java/org/apache/ratis/shell/cli/sh/GroupCommandIntegrationTest.java @@ -78,7 +78,7 @@ public void testGroupInfoCommand() throws Exception { } void runTestGroupInfoCommand(MiniRaftCluster cluster) throws Exception { - RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster); + final RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster); final String address = getClusterAddress(cluster); final StringPrintStream out = new StringPrintStream(); RatisShell shell = new RatisShell(out.getPrintStream()); @@ -93,13 +93,13 @@ void runTestGroupInfoCommand(MiniRaftCluster cluster) throws Exception { } @Test - public void testGroupInfoCommandIncludesCorrectPeerInfo() throws Exception { - // set number of server to 1 so that we can make sure which server returns the peer information + public void testGroupInfoCommandIncludesCorrectLogInfo() throws Exception { + // set number of server to 1 so that we can make sure which server returns the LogInfoProto // since information of applied index, snapshot index are not shared between servers - runWithNewCluster(1, this::runTestGroupInfoCommandWithPeerInfoVerification); + runWithNewCluster(1, this::runTestGroupInfoCommandWithLogInfoVerification); } - void runTestGroupInfoCommandWithPeerInfoVerification(MiniRaftCluster cluster) throws Exception { + void runTestGroupInfoCommandWithLogInfoVerification(MiniRaftCluster cluster) throws Exception { RaftServer.Division leader = RaftTestUtil.waitForLeader(cluster); try (final RaftClient client = cluster.createClient(leader.getId())) {