Skip to content

Commit

Permalink
RATIS-1976. Migrate ratis-test tests to Junit 5 - Part 1 (apache#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
nandakumar131 authored and szetszwo committed Jun 16, 2024
1 parent 016018f commit dfa30fe
Show file tree
Hide file tree
Showing 33 changed files with 349 additions and 332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@
import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.LifeCycle;
import org.apache.ratis.util.SizeInBytes;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -74,14 +73,12 @@ public abstract class InstallSnapshotFromLeaderTests<CLUSTER extends MiniRaftClu
private static final int SNAPSHOT_TRIGGER_THRESHOLD = 64;
private static final int PURGE_GAP = 8;

@Test
public void testMultiFileInstallSnapshot() throws Exception {
getProperties().setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY,
StateMachineWithMultiNestedSnapshotFile.class, StateMachine.class);
runWithNewCluster(1, this::testMultiFileInstallSnapshot);
}

@Test
public void testSeparateSnapshotInstallPath() throws Exception {
getProperties().setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY,
StateMachineWithSeparatedSnapshotPath.class, StateMachine.class);
Expand All @@ -98,14 +95,14 @@ private void testMultiFileInstallSnapshot(CLUSTER cluster) throws Exception {
for (; i < SNAPSHOT_TRIGGER_THRESHOLD * 2 - 1; i++) {
RaftClientReply
reply = client.io().send(new RaftTestUtil.SimpleMessage("m" + i));
Assert.assertTrue(reply.isSuccess());
Assertions.assertTrue(reply.isSuccess());
}

client.getSnapshotManagementApi(leaderId).create(3000);
}

final SnapshotInfo snapshot = cluster.getLeader().getStateMachine().getLatestSnapshot();
Assert.assertEquals(3, snapshot.getFiles().size());
Assertions.assertEquals(3, snapshot.getFiles().size());

// add two more peers
final MiniRaftCluster.PeerChanges change = cluster.addNewPeers(2, true,
Expand All @@ -121,8 +118,8 @@ private void testMultiFileInstallSnapshot(CLUSTER cluster) throws Exception {
JavaUtils.attempt(() -> {
for (RaftServer.Division follower : cluster.getFollowers()) {
final SnapshotInfo info = follower.getStateMachine().getLatestSnapshot();
Assert.assertNotNull(info);
Assert.assertEquals(3, info.getFiles().size());
Assertions.assertNotNull(info);
Assertions.assertEquals(3, info.getFiles().size());
}
}, 10, ONE_SECOND, "check snapshot", LOG);
} finally {
Expand Down Expand Up @@ -182,8 +179,8 @@ public long takeSnapshot() {
return RaftLog.INVALID_LOG_INDEX;
}

Assert.assertTrue(file1.exists());
Assert.assertTrue(file2.exists());
Assertions.assertTrue(file1.exists());
Assertions.assertTrue(file2.exists());
return super.takeSnapshot();
}

Expand All @@ -199,7 +196,7 @@ public SnapshotInfo getLatestSnapshot() {
files.add(new FileInfo(
file2.toPath(),
null));
Assert.assertEquals(2, files.size());
Assertions.assertEquals(2, files.size());

SnapshotInfo info = super.getLatestSnapshot();
if (info == null) {
Expand All @@ -224,8 +221,8 @@ public synchronized void initialize(RaftServer server, RaftGroupId groupId, Raft
this.snapshotDir = new File(root, "snapshot");
this.tmpDir = new File(root, "tmp");
FileUtils.deleteFully(root);
Assert.assertTrue(this.snapshotDir.mkdirs());
Assert.assertTrue(this.tmpDir.mkdirs());
Assertions.assertTrue(this.snapshotDir.mkdirs());
Assertions.assertTrue(this.tmpDir.mkdirs());
this.root.deleteOnExit();
}

Expand All @@ -246,13 +243,13 @@ public long takeSnapshot() {
try {
FileUtils.deleteFully(snapshotRealDir);
FileUtils.deleteFully(snapshotTmpDir);
Assert.assertTrue(snapshotTmpDir.mkdirs());
Assertions.assertTrue(snapshotTmpDir.mkdirs());
final File snapshotFile1 = new File(snapshotTmpDir, "deer");
final File snapshotFile2 = new File(snapshotTmpDir, "loves");
final File snapshotFile3 = new File(snapshotTmpDir, "vegetable");
Assert.assertTrue(snapshotFile1.createNewFile());
Assert.assertTrue(snapshotFile2.createNewFile());
Assert.assertTrue(snapshotFile3.createNewFile());
Assertions.assertTrue(snapshotFile1.createNewFile());
Assertions.assertTrue(snapshotFile2.createNewFile());
Assertions.assertTrue(snapshotFile3.createNewFile());
FileUtils.move(snapshotTmpDir, snapshotRealDir);
} catch (IOException ioe) {
LOG.error("create snapshot data file failed", ioe);
Expand Down
22 changes: 11 additions & 11 deletions ratis-server/src/test/java/org/apache/ratis/RetryCacheTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.apache.ratis.util.JavaUtils;
import org.apache.ratis.util.Slf4jUtils;
import org.apache.ratis.util.TimeDuration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.event.Level;

import java.util.Arrays;
Expand Down Expand Up @@ -84,9 +84,9 @@ void runTestBasicRetry(CLUSTER cluster) throws Exception {
}

public static void assertReply(RaftClientReply reply, RaftClient client, long callId) {
Assert.assertEquals(client.getId(), reply.getClientId());
Assert.assertEquals(callId, reply.getCallId());
Assert.assertTrue(reply.isSuccess());
Assertions.assertEquals(client.getId(), reply.getClientId());
Assertions.assertEquals(callId, reply.getCallId());
Assertions.assertTrue(reply.isSuccess());
}

public void assertServer(MiniRaftCluster cluster, ClientId clientId, long callId, long oldLastApplied) throws Exception {
Expand All @@ -97,10 +97,10 @@ public void assertServer(MiniRaftCluster cluster, ClientId clientId, long callId
if (server.getInfo().getLastAppliedIndex() < leaderApplied) {
Thread.sleep(1000);
}
Assert.assertEquals(2, server.getRetryCache().getStatistics().size());
Assert.assertNotNull(RetryCacheTestUtil.get(server, clientId, callId));
Assertions.assertEquals(2, server.getRetryCache().getStatistics().size());
Assertions.assertNotNull(RetryCacheTestUtil.get(server, clientId, callId));
// make sure there is only one log entry committed
Assert.assertEquals(1, count(server.getRaftLog(), oldLastApplied + 1));
Assertions.assertEquals(1, count(server.getRaftLog(), oldLastApplied + 1));
}
}

Expand Down Expand Up @@ -145,10 +145,10 @@ void runTestRetryOnNewLeader(CLUSTER cluster) throws Exception {

final RaftPeerId newLeaderId = JavaUtils.attemptRepeatedly(() -> {
final RaftPeerId id = RaftTestUtil.waitForLeader(cluster).getId();
Assert.assertNotEquals(leaderId, id);
Assertions.assertNotEquals(leaderId, id);
return id;
}, 10, TimeDuration.valueOf(100, TimeUnit.MILLISECONDS), "wait for a leader different than " + leaderId, LOG);
Assert.assertNotEquals(leaderId, newLeaderId);
Assertions.assertNotEquals(leaderId, newLeaderId);
// same clientId and callId in the request
r = cluster.newRaftClientRequest(client.getId(), newLeaderId,
callId, new SimpleMessage("message"));
Expand All @@ -164,7 +164,7 @@ void runTestRetryOnNewLeader(CLUSTER cluster) throws Exception {
}

// check the new leader and make sure the retry did not get committed
Assert.assertEquals(0, count(cluster.getLeader().getRaftLog(), oldLastApplied + 1));
Assertions.assertEquals(0, count(cluster.getLeader().getRaftLog(), oldLastApplied + 1));
}
}
}
Loading

0 comments on commit dfa30fe

Please sign in to comment.