Class MultiNodeCoordinator


  • public final class MultiNodeCoordinator
    extends Object

    Tools to allow tests to run in-step on multiple nodes

    Tests are launched on all nodes and use waitForState() to ensure each node is kept in-sync with each other as the test cases progress :

         enum Steps {
           STARTED,
           CONFIGURED,
           RUNNING,
           TESTS,
           FINISHED
         };
     
          // create coordinator for this test
          //
          MultiNodeCoordinator coordinator = new MultiNodeCoordinator();
    
          // Wait for all nodes to get here
          //
          coordinator.waitForState(Steps.STARTED);
    
          // load configuration
          //
    
          // wait for all nodes to complete loading configuration
          //
          coordinator.waitForState(Steps.CONFIGURED);
    
          // start embedded server
          //
    
          // wait for all nodes to complete starting application
          //
          coordinator.waitForState(Steps.RUNNING);
    
          // run tests
          //
    
          // wait for all nodes to complete tests
          //
          coordinator.waitForState(Steps.TESTS);
    
          // wait for all nodes to finish this test
          //
          coordinator.waitForState(Steps.FINISHED);
     

    Strings can also be used to specify states :

          MultiNodeCoordinator coordinator = new MultiNodeCoordinator();
          coordinator.waitForState("One");
          coordinator.waitForState("Two");
          coordinator.waitForState("Three");
     
    • Constructor Detail

      • MultiNodeCoordinator

        public MultiNodeCoordinator​(String source)

        Create an instance of node coordinator with a custom source name

        Parameters:
        source - name of this coordinator
      • MultiNodeCoordinator

        public MultiNodeCoordinator()

        Create an instance of node coordinator with a default name

        Source name is derived from test class name and method

    • Method Detail

      • waitForState

        public void waitForState​(Enum<?> state,
                                 int waitSeconds)
                          throws MultiNodeException

        Waits for all nodes in the cluster to declare that they have got to this state

        This method can be run within or outside a transaction

        Parameters:
        state - state to wait for
        waitSeconds - maximum time to wait
        Throws:
        MultiNodeException - On timeout or invalid configuration
      • waitForState

        public void waitForState​(String state,
                                 int waitSeconds)
                          throws MultiNodeException

        Waits for all nodes in the cluster to declare that they have got to this state

        This method can be run within or outside a transaction

        Parameters:
        state - state to wait for
        waitSeconds - maximum time to wait
        Throws:
        MultiNodeException - On timeout or invalid configuration
      • waitForState

        public void waitForState​(Enum<?> state)
                          throws MultiNodeException

        Waits for all nodes in the cluster to declare that they have got to this state

        maximum wait time is 300 seconds

        This method can be run within or outside a transaction

        Parameters:
        state - state to wait for
        Throws:
        MultiNodeException - On timeout or invalid configuration
      • waitForState

        public void waitForState​(String state)
                          throws MultiNodeException

        Waits for all nodes in the cluster to declare that they have got to this state

        maximum wait time is 300 seconds

        This method can be run within or outside a transaction

        Parameters:
        state - state to wait for
        Throws:
        MultiNodeException - On timeout or invalid configuration