Class RaftTestUtils

java.lang.Object
org.jgroups.raft.testfwk.RaftTestUtils

public final class RaftTestUtils extends Object
Utilities for developing tests with Raft.
Since:
1.0.13
Author:
José Bolina
  • Method Details

    • raft

      public static RAFT raft(org.jgroups.JChannel ch)
      Retrieves the RAFT protocol from the provided JChannel.
      Parameters:
      ch - The channel to search the protocol.
      Returns:
      The RAFT instance or null if not found.
    • election

      public static BaseElection election(org.jgroups.JChannel ch)
      Retrieves the BaseElection protocol from the provided JChannel. The concrete type might vary according to the configured protocol stack.
      Parameters:
      ch - The channel to search the protocol.
      Returns:
      The BaseElection instance or null if not found.
    • isRaftLeader

      public static boolean isRaftLeader(org.jgroups.JChannel ch)
      Checks if the node is the current RAFT leader.

      This method search the protocol stack to retrieve the RAFT instance and then verifies if elected.

      Parameters:
      ch - The channel to verify.
      Returns:
      true if currently the leader, and false otherwise or not found the RAFT protocol.
    • eventuallyIsRaftLeader

      public static boolean eventuallyIsRaftLeader(org.jgroups.JChannel ch, long timeoutMs)
      Checks that given the time constraints, eventually isRaftLeader(JChannel) is true.
      Parameters:
      ch - Channel to verify.
      timeoutMs - The timeout in milliseconds.
      Returns:
      true if it became the leader, false, otherwise.
      See Also:
    • deleteRaftLog

      public static void deleteRaftLog(RAFT r) throws Exception
      Deletes all the replicated data and internal state for the given RAFT instance.

      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.

      Parameters:
      r - RAFT instance to delete all information.
      Throws:
      Exception - If an exception happens while deleting the data.
      See Also:
    • eventually

      public static boolean eventually(BooleanSupplier bs, long timeout, TimeUnit unit)
      Verify that in the given time constraints, the expression returns true.
      Parameters:
      bs - Boolean expression to verify.
      timeout - Timeout value.
      unit - Timeout unit.
      Returns:
      true if expression valid before time out, false, otherwise.
      Throws:
      RuntimeException - If an exception is thrown while verifying the expression.