4747import org .apache .ratis .thirdparty .com .google .protobuf .ByteString ;
4848import org .apache .ratis .thirdparty .com .google .protobuf .InvalidProtocolBufferException ;
4949import org .apache .ratis .util .JavaUtils ;
50+ import org .apache .ratis .util .PlatformUtils ;
5051import org .apache .ratis .util .Slf4jUtils ;
5152import org .apache .ratis .util .TimeDuration ;
5253import org .apache .ratis .util .function .CheckedRunnable ;
@@ -85,6 +86,10 @@ public abstract class RaftAsyncTests<CLUSTER extends MiniRaftCluster> extends Ba
8586 {
8687 getProperties ().setClass (MiniRaftCluster .STATEMACHINE_CLASS_KEY ,
8788 SimpleStateMachine4Testing .class , StateMachine .class );
89+ if (!PlatformUtils .LINUX ) {
90+ getProperties ().setBoolean ("raft.netty.server.use-epoll" , false );
91+ getProperties ().setBoolean ("raft.netty.client.use-epoll" , false );
92+ }
8893 }
8994
9095 @ Test
@@ -110,8 +115,8 @@ public void testAsyncConfiguration() throws IOException {
110115
111116 static void assertRaftRetryFailureException (RaftRetryFailureException rfe , RetryPolicy retryPolicy , String name ) {
112117 Assertions .assertNotNull (rfe , name + " does not have RaftRetryFailureException" );
113- Assertions .assertTrue (
114- rfe . getMessage (). contains ( retryPolicy . toString ()), name + ": unexpected error message, rfe=" + rfe + ", retryPolicy=" + retryPolicy );
118+ Assertions .assertTrue (rfe . getMessage (). contains ( retryPolicy . toString ()),
119+ name + ": unexpected error message, rfe=" + rfe + ", retryPolicy=" + retryPolicy );
115120 }
116121
117122 @ Test
@@ -284,8 +289,8 @@ public void testStaleReadAsync() throws Exception {
284289
285290 void runTestStaleReadAsync (CLUSTER cluster ) throws Exception {
286291 final int numMessages = 10 ;
287- try ( RaftClient client = cluster . createClient ()) {
288- RaftTestUtil . waitForLeader ( cluster );
292+ RaftServer . Division division = waitForLeader ( cluster );
293+ try ( RaftClient client = cluster . createClient ( division . getId ())) {
289294
290295 // submit some messages
291296 final List <CompletableFuture <RaftClientReply >> futures = new ArrayList <>();
@@ -306,6 +311,7 @@ void runTestStaleReadAsync(CLUSTER cluster) throws Exception {
306311 // Use a follower with the max commit index
307312 final RaftClientReply lastWriteReply = replies .get (replies .size () - 1 );
308313 final RaftPeerId leader = lastWriteReply .getServerId ();
314+ Assertions .assertEquals (leader , lastWriteReply .getServerId ());
309315 LOG .info ("leader = " + leader );
310316 final Collection <CommitInfoProto > commitInfos = lastWriteReply .getCommitInfos ();
311317 LOG .info ("commitInfos = " + commitInfos );
@@ -368,8 +374,8 @@ public void testWriteAsyncCustomReplicationLevel() throws Exception {
368374
369375 void runTestWriteAsyncCustomReplicationLevel (CLUSTER cluster ) throws Exception {
370376 final int numMessages = 20 ;
371- try ( RaftClient client = cluster . createClient ()) {
372- RaftTestUtil . waitForLeader ( cluster );
377+ final RaftPeerId leader = waitForLeader ( cluster ). getId ();
378+ try ( RaftClient client = cluster . createClient ( leader )) {
373379
374380 // submit some messages
375381 for (int i = 0 ; i < numMessages ; i ++) {
@@ -419,13 +425,13 @@ void runTestAppendEntriesTimeout(CLUSTER cluster) throws Exception {
419425 LOG .info ("Running testAppendEntriesTimeout" );
420426 final TimeDuration oldExpiryTime = RaftServerConfigKeys .RetryCache .expiryTime (getProperties ());
421427 RaftServerConfigKeys .RetryCache .setExpiryTime (getProperties (), TimeDuration .valueOf (20 , TimeUnit .SECONDS ));
422- RaftPeerId id = waitForLeader (cluster ).getId ();
428+ final RaftPeerId leader = waitForLeader (cluster ).getId ();
423429 long time = System .currentTimeMillis ();
424430 long waitTime = 5000 ;
425431 try (final RaftClient client = cluster .createClient ()) {
426432 // block append requests
427433 cluster .getServerAliveStream ()
428- .filter (impl -> !impl .getInfo ().isLeader () && impl .getPeer ().getId () != id )
434+ .filter (impl -> !impl .getInfo ().isLeader () && ! impl .getPeer ().getId (). equals ( leader ) )
429435 .map (SimpleStateMachine4Testing ::get )
430436 .forEach (SimpleStateMachine4Testing ::blockWriteStateMachineData );
431437
@@ -435,7 +441,7 @@ void runTestAppendEntriesTimeout(CLUSTER cluster) throws Exception {
435441 Assertions .assertFalse (replyFuture .isDone ());
436442 // unblock append request.
437443 cluster .getServerAliveStream ()
438- .filter (impl -> !impl .getInfo ().isLeader () && impl .getPeer ().getId () != id )
444+ .filter (impl -> !impl .getInfo ().isLeader () && ! impl .getPeer ().getId (). equals ( leader ) )
439445 .map (SimpleStateMachine4Testing ::get )
440446 .forEach (SimpleStateMachine4Testing ::unblockWriteStateMachineData );
441447
0 commit comments