3939import org .apache .ratis .util .JavaUtils ;
4040import org .apache .ratis .util .Slf4jUtils ;
4141import org .apache .ratis .util .SizeInBytes ;
42- import org .junit .Assert ;
43- import org .junit .Test ;
42+ import org .junit .jupiter . api . Assertions ;
43+ import org .junit .jupiter . api . Test ;
4444import org .slf4j .Logger ;
4545import org .slf4j .LoggerFactory ;
4646import org .slf4j .event .Level ;
@@ -194,7 +194,7 @@ private void testAddNewFollowers(CLUSTER cluster, int numRequests) throws Except
194194 try (final RaftClient client = cluster .createClient (leaderId )) {
195195 for (; i < numRequests ; i ++) {
196196 final RaftClientReply reply = client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i ));
197- Assert .assertTrue (reply .isSuccess ());
197+ Assertions .assertTrue (reply .isSuccess ());
198198 }
199199 }
200200
@@ -206,7 +206,7 @@ private void testAddNewFollowers(CLUSTER cluster, int numRequests) throws Except
206206 final List <File > snapshotFiles = RaftSnapshotBaseTest .getSnapshotFiles (cluster ,
207207 nextIndex - SNAPSHOT_TRIGGER_THRESHOLD , nextIndex );
208208 JavaUtils .attemptRepeatedly (() -> {
209- Assert .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
209+ Assertions .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
210210 return null ;
211211 }, 10 , ONE_SECOND , "snapshotFile.exist" , LOG );
212212 logs = LogSegmentPath .getLogSegmentPaths (leader .getRaftStorage ());
@@ -220,7 +220,7 @@ private void testAddNewFollowers(CLUSTER cluster, int numRequests) throws Except
220220 // delete the log segments from the leader
221221 LOG .info ("Delete logs {}" , logs );
222222 for (LogSegmentPath path : logs ) {
223- FileUtils .deleteFully (path .getPath ()); // the log may be already purged
223+ FileUtils .deleteFully (path .getPath ()); // the log may be already puged
224224 }
225225
226226 // restart the peer
@@ -231,13 +231,13 @@ private void testAddNewFollowers(CLUSTER cluster, int numRequests) throws Except
231231
232232 // generate some more traffic
233233 try (final RaftClient client = cluster .createClient (cluster .getLeader ().getId ())) {
234- Assert .assertTrue (client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i )).isSuccess ());
234+ Assertions .assertTrue (client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i )).isSuccess ());
235235 }
236236
237237 final SnapshotInfo leaderSnapshotInfo = cluster .getLeader ().getStateMachine ().getLatestSnapshot ();
238238 LOG .info ("LeaderSnapshotInfo: {}" , leaderSnapshotInfo .getTermIndex ());
239239 final boolean set = LEADER_SNAPSHOT_INFO_REF .compareAndSet (null , leaderSnapshotInfo );
240- Assert .assertTrue (set );
240+ Assertions .assertTrue (set );
241241
242242 // add two more peers
243243 final MiniRaftCluster .PeerChanges change = cluster .addNewPeers (2 , true ,
@@ -253,7 +253,7 @@ private void testAddNewFollowers(CLUSTER cluster, int numRequests) throws Except
253253 // leader snapshot.
254254 for (RaftServer .Division follower : cluster .getFollowers ()) {
255255 final long expected = leaderSnapshotInfo .getIndex ();
256- Assert .assertEquals (expected , RaftServerTestUtil .getLatestInstalledSnapshotIndex (follower ));
256+ Assertions .assertEquals (expected , RaftServerTestUtil .getLatestInstalledSnapshotIndex (follower ));
257257 RaftSnapshotBaseTest .assertLogContent (follower , false );
258258 }
259259
@@ -279,7 +279,7 @@ private void testRestartFollower(CLUSTER cluster) throws Exception {
279279 try (final RaftClient client = cluster .createClient (leaderId )) {
280280 for (; i < SNAPSHOT_TRIGGER_THRESHOLD * 2 - 1 ; i ++) {
281281 final RaftClientReply reply = client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i ));
282- Assert .assertTrue (reply .isSuccess ());
282+ Assertions .assertTrue (reply .isSuccess ());
283283 }
284284 }
285285
@@ -290,7 +290,7 @@ private void testRestartFollower(CLUSTER cluster) throws Exception {
290290 final List <File > snapshotFiles = RaftSnapshotBaseTest .getSnapshotFiles (cluster ,
291291 oldLeaderNextIndex - SNAPSHOT_TRIGGER_THRESHOLD , oldLeaderNextIndex );
292292 JavaUtils .attemptRepeatedly (() -> {
293- Assert .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
293+ Assertions .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
294294 return null ;
295295 }, 10 , ONE_SECOND , "snapshotFile.exist" , LOG );
296296 }
@@ -300,7 +300,7 @@ private void testRestartFollower(CLUSTER cluster) throws Exception {
300300
301301 // generate some more traffic
302302 try (final RaftClient client = cluster .createClient (leader .getId ())) {
303- Assert .assertTrue (client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i )).isSuccess ());
303+ Assertions .assertTrue (client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i )).isSuccess ());
304304 }
305305
306306 FIVE_SECONDS .sleep ();
@@ -309,8 +309,8 @@ private void testRestartFollower(CLUSTER cluster) throws Exception {
309309 JavaUtils .attempt (() -> {
310310 final long newLeaderNextIndex = leader .getRaftLog ().getNextIndex ();
311311 LOG .info ("{}: newLeaderNextIndex = {}" , leaderId , newLeaderNextIndex );
312- Assert .assertTrue (newLeaderNextIndex > oldLeaderNextIndex );
313- Assert .assertEquals (newLeaderNextIndex , follower .getRaftLog ().getNextIndex ());
312+ Assertions .assertTrue (newLeaderNextIndex > oldLeaderNextIndex );
313+ Assertions .assertEquals (newLeaderNextIndex , follower .getRaftLog ().getNextIndex ());
314314 }, 10 , ONE_SECOND , "followerNextIndex" , LOG );
315315 }
316316
@@ -331,14 +331,14 @@ private void testInstallSnapshotNotificationCount(CLUSTER cluster) throws Except
331331
332332 // Let a few heartbeats pass.
333333 ONE_SECOND .sleep ();
334- Assert .assertEquals (0 , numSnapshotRequests .get ());
334+ Assertions .assertEquals (0 , numSnapshotRequests .get ());
335335
336336 // Generate data.
337337 try (final RaftClient client = cluster .createClient (leaderId )) {
338338 for (; i < 10 ; i ++) {
339339 RaftClientReply
340340 reply = client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i ));
341- Assert .assertTrue (reply .isSuccess ());
341+ Assertions .assertTrue (reply .isSuccess ());
342342 }
343343 }
344344
@@ -349,42 +349,42 @@ private void testInstallSnapshotNotificationCount(CLUSTER cluster) throws Except
349349
350350 // Take snapshot and check result.
351351 long snapshotIndex = cluster .getLeader ().getStateMachine ().takeSnapshot ();
352- Assert .assertEquals (20 , snapshotIndex );
352+ Assertions .assertEquals (20 , snapshotIndex );
353353 final SnapshotInfo leaderSnapshotInfo = cluster .getLeader ().getStateMachine ().getLatestSnapshot ();
354- Assert .assertEquals (20 , leaderSnapshotInfo .getIndex ());
354+ Assertions .assertEquals (20 , leaderSnapshotInfo .getIndex ());
355355 final boolean set = LEADER_SNAPSHOT_INFO_REF .compareAndSet (null , leaderSnapshotInfo );
356- Assert .assertTrue (set );
356+ Assertions .assertTrue (set );
357357
358358 // Wait for the snapshot to be done.
359359 final RaftServer .Division leader = cluster .getLeader ();
360360 final long nextIndex = leader .getRaftLog ().getNextIndex ();
361- Assert .assertEquals (21 , nextIndex );
361+ Assertions .assertEquals (21 , nextIndex );
362362 // End index is exclusive.
363363 final List <File > snapshotFiles = RaftSnapshotBaseTest .getSnapshotFiles (cluster ,
364364 0 , nextIndex );
365365 JavaUtils .attemptRepeatedly (() -> {
366- Assert .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
366+ Assertions .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
367367 return null ;
368368 }, 10 , ONE_SECOND , "snapshotFile.exist" , LOG );
369369
370370 // Clear all log files and reset cached log start index.
371371 long snapshotInstallIndex =
372372 leader .getRaftLog ().onSnapshotInstalled (leader .getRaftLog ().getLastCommittedIndex ()).get ();
373- Assert .assertEquals (20 , snapshotInstallIndex );
373+ Assertions .assertEquals (20 , snapshotInstallIndex );
374374
375375 // Check that logs are gone.
376- Assert .assertEquals (0 ,
376+ Assertions .assertEquals (0 ,
377377 LogSegmentPath .getLogSegmentPaths (leader .getRaftStorage ()).size ());
378- Assert .assertEquals (RaftLog .INVALID_LOG_INDEX , leader .getRaftLog ().getStartIndex ());
378+ Assertions .assertEquals (RaftLog .INVALID_LOG_INDEX , leader .getRaftLog ().getStartIndex ());
379379
380380 // Allow some heartbeats to go through, then make sure none of them had
381381 // snapshot requests.
382382 ONE_SECOND .sleep ();
383- Assert .assertEquals (0 , numSnapshotRequests .get ());
383+ Assertions .assertEquals (0 , numSnapshotRequests .get ());
384384
385385 // Make sure leader and followers are still up to date.
386386 for (RaftServer .Division follower : cluster .getFollowers ()) {
387- Assert .assertEquals (
387+ Assertions .assertEquals (
388388 leader .getRaftLog ().getNextIndex (),
389389 follower .getRaftLog ().getNextIndex ());
390390 }
@@ -400,7 +400,7 @@ private void testInstallSnapshotNotificationCount(CLUSTER cluster) throws Except
400400
401401 // Generate more data.
402402 try (final RaftClient client = cluster .createClient (leader .getId ())) {
403- Assert .assertTrue (client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i )).isSuccess ());
403+ Assertions .assertTrue (client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i )).isSuccess ());
404404 }
405405
406406 // Make sure leader and followers are still up to date.
@@ -412,7 +412,7 @@ private void testInstallSnapshotNotificationCount(CLUSTER cluster) throws Except
412412 }
413413
414414 // Make sure each new peer got one snapshot notification.
415- Assert .assertEquals (2 , numSnapshotRequests .get ());
415+ Assertions .assertEquals (2 , numSnapshotRequests .get ());
416416
417417 } finally {
418418 cluster .shutdown ();
@@ -437,7 +437,7 @@ private void testInstallSnapshotInstalledEvent(CLUSTER cluster) throws Exception
437437 for (; i < SNAPSHOT_TRIGGER_THRESHOLD * 2 - 1 ; i ++) {
438438 RaftClientReply
439439 reply = client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i ));
440- Assert .assertTrue (reply .isSuccess ());
440+ Assertions .assertTrue (reply .isSuccess ());
441441 }
442442 }
443443
@@ -448,7 +448,7 @@ private void testInstallSnapshotInstalledEvent(CLUSTER cluster) throws Exception
448448 final List <File > snapshotFiles = RaftSnapshotBaseTest .getSnapshotFiles (cluster ,
449449 nextIndex - SNAPSHOT_TRIGGER_THRESHOLD , nextIndex );
450450 JavaUtils .attemptRepeatedly (() -> {
451- Assert .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
451+ Assertions .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
452452 return null ;
453453 }, 10 , ONE_SECOND , "snapshotFile.exist" , LOG );
454454 logs = LogSegmentPath .getLogSegmentPaths (leader .getRaftStorage ());
@@ -470,13 +470,13 @@ private void testInstallSnapshotInstalledEvent(CLUSTER cluster) throws Exception
470470
471471 // generate some more traffic
472472 try (final RaftClient client = cluster .createClient (cluster .getLeader ().getId ())) {
473- Assert .assertTrue (client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i )).isSuccess ());
473+ Assertions .assertTrue (client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i )).isSuccess ());
474474 }
475475
476476 final SnapshotInfo leaderSnapshotInfo = cluster .getLeader ().getStateMachine ().getLatestSnapshot ();
477477 LOG .info ("LeaderSnapshotInfo: {}" , leaderSnapshotInfo .getTermIndex ());
478478 final boolean set = LEADER_SNAPSHOT_INFO_REF .compareAndSet (null , leaderSnapshotInfo );
479- Assert .assertTrue (set );
479+ Assertions .assertTrue (set );
480480
481481 // add one new peer
482482 final MiniRaftCluster .PeerChanges change = cluster .addNewPeers (1 , true , true );
@@ -490,7 +490,7 @@ private void testInstallSnapshotInstalledEvent(CLUSTER cluster) throws Exception
490490 // Check the installed snapshot index on each Follower matches with the
491491 // leader snapshot.
492492 for (RaftServer .Division follower : cluster .getFollowers ()) {
493- Assert .assertEquals (leaderSnapshotInfo .getIndex (),
493+ Assertions .assertEquals (leaderSnapshotInfo .getIndex (),
494494 RaftServerTestUtil .getLatestInstalledSnapshotIndex (follower ));
495495 }
496496
@@ -500,9 +500,9 @@ private void testInstallSnapshotInstalledEvent(CLUSTER cluster) throws Exception
500500 (SimpleStateMachine4Testing ) cluster .getFollowers ().get (0 ).getStateMachine ();
501501 final File followerSnapshotFile = new File (followerStateMachine .getStateMachineDir (),
502502 leaderSnapshotFile .getName ());
503- Assert .assertEquals (numNotifyInstallSnapshotFinished .get (), 2 );
504- Assert .assertTrue (leaderSnapshotFile .exists ());
505- Assert .assertFalse (followerSnapshotFile .exists ());
503+ Assertions .assertEquals (numNotifyInstallSnapshotFinished .get (), 2 );
504+ Assertions .assertTrue (leaderSnapshotFile .exists ());
505+ Assertions .assertFalse (followerSnapshotFile .exists ());
506506
507507 // restart the peer and check if it can correctly handle conf change
508508 cluster .restartServer (cluster .getLeader ().getId (), false );
@@ -535,7 +535,7 @@ private void testInstallSnapshotDuringBootstrap(CLUSTER cluster) throws Exceptio
535535 for (; i < SNAPSHOT_TRIGGER_THRESHOLD * 2 - 1 ; i ++) {
536536 RaftClientReply
537537 reply = client .io ().send (new RaftTestUtil .SimpleMessage ("m" + i ));
538- Assert .assertTrue (reply .isSuccess ());
538+ Assertions .assertTrue (reply .isSuccess ());
539539 }
540540 }
541541
@@ -546,15 +546,15 @@ private void testInstallSnapshotDuringBootstrap(CLUSTER cluster) throws Exceptio
546546 final List <File > snapshotFiles = RaftSnapshotBaseTest .getSnapshotFiles (cluster ,
547547 nextIndex - SNAPSHOT_TRIGGER_THRESHOLD , nextIndex );
548548 JavaUtils .attemptRepeatedly (() -> {
549- Assert .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
549+ Assertions .assertTrue (snapshotFiles .stream ().anyMatch (RaftSnapshotBaseTest ::exists ));
550550 return null ;
551551 }, 10 , ONE_SECOND , "snapshotFile.exist" , LOG );
552552
553553 RaftSnapshotBaseTest .assertLeaderContent (cluster );
554554
555555 final SnapshotInfo leaderSnapshotInfo = cluster .getLeader ().getStateMachine ().getLatestSnapshot ();
556556 final boolean set = LEADER_SNAPSHOT_INFO_REF .compareAndSet (null , leaderSnapshotInfo );
557- Assert .assertTrue (set );
557+ Assertions .assertTrue (set );
558558
559559 // add two more peers
560560 final MiniRaftCluster .PeerChanges change = cluster .addNewPeers (2 , true ,
@@ -568,12 +568,12 @@ private void testInstallSnapshotDuringBootstrap(CLUSTER cluster) throws Exceptio
568568 // Check the installed snapshot index on each Follower matches with the
569569 // leader snapshot.
570570 for (RaftServer .Division follower : cluster .getFollowers ()) {
571- Assert .assertEquals (leaderSnapshotInfo .getIndex (),
571+ Assertions .assertEquals (leaderSnapshotInfo .getIndex (),
572572 RaftServerTestUtil .getLatestInstalledSnapshotIndex (follower ));
573573 }
574574
575575 // Make sure each new peer got at least one snapshot notification.
576- Assert .assertTrue (2 <= numSnapshotRequests .get ());
576+ Assertions .assertTrue (2 <= numSnapshotRequests .get ());
577577 } finally {
578578 cluster .shutdown ();
579579 }
0 commit comments