Skip to content

Commit

Permalink
fix ElectionCommandIntegrationTest, and ProtoUtils.toString for LogIn…
Browse files Browse the repository at this point in the history
…foProto
  • Loading branch information
DaveTeng0 committed Mar 6, 2024
1 parent 8737a1f commit f5d6fbd
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommitInfoProto> getCommitInfos() {
return commitInfos;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommitInfoProto> protos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ static void checkMajority(List<CompletableFuture<RaftClientReply>> replies,
final RaftClientReply watchMajorityCommittedReply = watchReplies.getMajorityCommitted();
{ // check commit infos
final Collection<CommitInfoProto> commitInfos = watchMajorityCommittedReply.getCommitInfos();

final String message = "logIndex=" + logIndex + ", " + ProtoUtils.toString(commitInfos);
Assert.assertEquals(NUM_SERVERS, commitInfos.size());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommitInfoProto> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import java.io.IOException;


/**
* Command for querying ratis group information.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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())) {
Expand Down

0 comments on commit f5d6fbd

Please sign in to comment.