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 ;
@@ -83,6 +84,10 @@ public abstract class RaftAsyncTests<CLUSTER extends MiniRaftCluster> extends Ba
8384 {
8485 getProperties ().setClass (MiniRaftCluster .STATEMACHINE_CLASS_KEY ,
8586 SimpleStateMachine4Testing .class , StateMachine .class );
87+ if (!PlatformUtils .LINUX ) {
88+ getProperties ().setBoolean ("raft.netty.server.use-epoll" , false );
89+ getProperties ().setBoolean ("raft.netty.client.use-epoll" , false );
90+ }
8691 }
8792
8893 @ Test
@@ -282,8 +287,8 @@ public void testStaleReadAsync() throws Exception {
282287
283288 void runTestStaleReadAsync (CLUSTER cluster ) throws Exception {
284289 final int numMessages = 10 ;
285- try ( RaftClient client = cluster . createClient ()) {
286- RaftTestUtil . waitForLeader ( cluster );
290+ RaftServer . Division division = waitForLeader ( cluster );
291+ try ( RaftClient client = cluster . createClient ( division . getId ())) {
287292
288293 // submit some messages
289294 final List <CompletableFuture <RaftClientReply >> futures = new ArrayList <>();
@@ -304,6 +309,7 @@ void runTestStaleReadAsync(CLUSTER cluster) throws Exception {
304309 // Use a follower with the max commit index
305310 final RaftClientReply lastWriteReply = replies .get (replies .size () - 1 );
306311 final RaftPeerId leader = lastWriteReply .getServerId ();
312+ Assert .assertEquals (leader , lastWriteReply .getServerId ());
307313 LOG .info ("leader = " + leader );
308314 final Collection <CommitInfoProto > commitInfos = lastWriteReply .getCommitInfos ();
309315 LOG .info ("commitInfos = " + commitInfos );
@@ -366,8 +372,8 @@ public void testWriteAsyncCustomReplicationLevel() throws Exception {
366372
367373 void runTestWriteAsyncCustomReplicationLevel (CLUSTER cluster ) throws Exception {
368374 final int numMessages = 20 ;
369- try ( RaftClient client = cluster . createClient ()) {
370- RaftTestUtil . waitForLeader ( cluster );
375+ final RaftPeerId leader = waitForLeader ( cluster ). getId ();
376+ try ( RaftClient client = cluster . createClient ( leader )) {
371377
372378 // submit some messages
373379 for (int i = 0 ; i < numMessages ; i ++) {
@@ -417,13 +423,13 @@ void runTestAppendEntriesTimeout(CLUSTER cluster) throws Exception {
417423 LOG .info ("Running testAppendEntriesTimeout" );
418424 final TimeDuration oldExpiryTime = RaftServerConfigKeys .RetryCache .expiryTime (getProperties ());
419425 RaftServerConfigKeys .RetryCache .setExpiryTime (getProperties (), TimeDuration .valueOf (20 , TimeUnit .SECONDS ));
420- waitForLeader (cluster );
426+ final RaftPeerId leader = waitForLeader (cluster ). getId ( );
421427 long time = System .currentTimeMillis ();
422428 long waitTime = 5000 ;
423429 try (final RaftClient client = cluster .createClient ()) {
424430 // block append requests
425431 cluster .getServerAliveStream ()
426- .filter (impl -> !impl .getInfo ().isLeader ())
432+ .filter (impl -> !impl .getInfo ().isLeader () && ! impl . getPeer (). getId (). equals ( leader ) )
427433 .map (SimpleStateMachine4Testing ::get )
428434 .forEach (SimpleStateMachine4Testing ::blockWriteStateMachineData );
429435
@@ -433,7 +439,7 @@ void runTestAppendEntriesTimeout(CLUSTER cluster) throws Exception {
433439 Assert .assertFalse (replyFuture .isDone ());
434440 // unblock append request.
435441 cluster .getServerAliveStream ()
436- .filter (impl -> !impl .getInfo ().isLeader ())
442+ .filter (impl -> !impl .getInfo ().isLeader () && ! impl . getPeer (). getId (). equals ( leader ) )
437443 .map (SimpleStateMachine4Testing ::get )
438444 .forEach (SimpleStateMachine4Testing ::unblockWriteStateMachineData );
439445
0 commit comments