Package org.jgroups.raft.testfwk
Class RaftTestUtils
java.lang.Object
org.jgroups.raft.testfwk.RaftTestUtils
Utilities for developing tests with Raft.
- Since:
- 1.0.13
- Author:
- José Bolina
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidDeletes all the replicated data and internal state for the givenRAFTinstance.static BaseElectionelection(org.jgroups.JChannel ch) Retrieves theBaseElectionprotocol from the providedJChannel.static booleaneventually(BooleanSupplier bs, long timeout, TimeUnit unit) Verify that in the given time constraints, the expression returnstrue.static booleaneventuallyIsRaftLeader(org.jgroups.JChannel ch, long timeoutMs) Checks that given the time constraints, eventuallyisRaftLeader(JChannel)istrue.static booleanisRaftLeader(org.jgroups.JChannel ch) Checks if the node is the currentRAFTleader.static RAFTraft(org.jgroups.JChannel ch) Retrieves theRAFTprotocol from the providedJChannel.
-
Method Details
-
raft
Retrieves theRAFTprotocol from the providedJChannel.- Parameters:
ch- The channel to search the protocol.- Returns:
- The
RAFTinstance ornullif not found.
-
election
Retrieves theBaseElectionprotocol from the providedJChannel. The concrete type might vary according to the configured protocol stack.- Parameters:
ch- The channel to search the protocol.- Returns:
- The
BaseElectioninstance ornullif not found.
-
isRaftLeader
public static boolean isRaftLeader(org.jgroups.JChannel ch) Checks if the node is the currentRAFTleader.This method search the protocol stack to retrieve the
RAFTinstance and then verifies if elected.- Parameters:
ch- The channel to verify.- Returns:
trueif currently the leader, andfalseotherwise or not found theRAFTprotocol.
-
eventuallyIsRaftLeader
public static boolean eventuallyIsRaftLeader(org.jgroups.JChannel ch, long timeoutMs) Checks that given the time constraints, eventuallyisRaftLeader(JChannel)istrue.- Parameters:
ch- Channel to verify.timeoutMs- The timeout in milliseconds.- Returns:
trueif it became the leader,false, otherwise.- See Also:
-
deleteRaftLog
Deletes all the replicated data and internal state for the givenRAFTinstance.This is useful when multiple tests for the same uses stable storage. After running each test the data can be deleted to no affect subsequent tests.
-
eventually
Verify that in the given time constraints, the expression returnstrue.- Parameters:
bs- Boolean expression to verify.timeout- Timeout value.unit- Timeout unit.- Returns:
trueif expression valid before time out,false, otherwise.- Throws:
RuntimeException- If an exception is thrown while verifying the expression.
-