133tosakarin commented on code in PR #1166:
URL: https://github.com/apache/ratis/pull/1166#discussion_r1797209369
##########
ratis-server/src/test/java/org/apache/ratis/server/impl/LeaderElectionTests.java:
##########
@@ -97,6 +100,70 @@ public void testBasicLeaderElection() throws Exception {
cluster.shutdown();
}
+ static class SleepCode implements CodeInjectionForTesting.Code {
+ private final long sleepMs;
+
+ SleepCode(long sleepMs) {
+ this.sleepMs = sleepMs;
+ }
+
+ @Override
+ public boolean execute(Object localId, Object remoteId, Object... args) {
+ try {
+ LOG.info("{}: Simulate RaftServer startup blocking", localId);
+ Thread.sleep(sleepMs);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ return true;
+ }
+ }
+
+ @Test
+ public void testWaitServerReady() throws Exception {
+ LOG.info("Running testWaitServerReady");
+ int []arr = {1, 2, 3, 4, 5};
+ for (int i : arr) {
+ final MiniRaftCluster cluster = newCluster(1);
+ CodeInjectionForTesting.put(RaftServerImpl.START_COMPLETE, new
SleepCode(1000));
+ cluster.start();
+ // Leader will be elected if the server is ready
+ Assertions.assertTrue(RaftTestUtil.waitForLeader(cluster).getId() !=
null);
+ cluster.shutdown();
+ }
+ }
+
+ @Test
+ public void testAddServerForWaitReady() throws IOException,
InterruptedException {
Review Comment:
I want to test to ensure that new members join and execute normally
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]