Class MockTransportService

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, LifecycleComponent, Releasable, TransportConnectionListener, TransportMessageListener

    public final class MockTransportService
    extends TransportService
    A mock delegate service that allows to simulate different network topology failures. Internally it maps TransportAddress objects to rules that inject failures. Adding rules for a node is done by adding rules for all bound addresses of a node (and the publish address, if different). Matching requests to rules is based on the delegate address associated with the discovery node of the request, namely by DiscoveryNode.getAddress(). This address is usually the publish address of the node but can also be a different one (for example, @see org.elasticsearch.discovery.HandshakingTransportAddressConnector, which constructs fake DiscoveryNode instances where the publish address is one of the bound addresses).
    • Method Detail

      • clearAllRules

        public void clearAllRules()
        Clears all the registered rules.
      • clearRule

        public void clearRule​(TransportService transportService)
        Clears the rule associated with the provided delegate service.
      • clearRule

        public void clearRule​(TransportAddress transportAddress)
        Clears the rule associated with the provided delegate address.
      • addFailToSendNoConnectRule

        public void addFailToSendNoConnectRule​(TransportService transportService)
        Adds a rule that will cause every send request to fail, and each new connect since the rule is added to fail as well.
      • addFailToSendNoConnectRule

        public void addFailToSendNoConnectRule​(TransportAddress transportAddress)
        Adds a rule that will cause every send request to fail, and each new connect since the rule is added to fail as well.
      • addFailToSendNoConnectRule

        public void addFailToSendNoConnectRule​(TransportService transportService,
                                               java.lang.String... blockedActions)
        Adds a rule that will cause matching operations to throw ConnectTransportExceptions
      • addFailToSendNoConnectRule

        public void addFailToSendNoConnectRule​(TransportService transportService,
                                               java.util.Set<java.lang.String> blockedActions)
        Adds a rule that will cause matching operations to throw ConnectTransportExceptions
      • addFailToSendNoConnectRule

        public void addFailToSendNoConnectRule​(TransportAddress transportAddress,
                                               java.util.Set<java.lang.String> blockedActions)
        Adds a rule that will cause matching operations to throw ConnectTransportExceptions
      • addUnresponsiveRule

        public void addUnresponsiveRule​(TransportService transportService)
        Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.
      • addUnresponsiveRule

        public void addUnresponsiveRule​(TransportAddress transportAddress)
        Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.
      • addUnresponsiveRule

        public void addUnresponsiveRule​(TransportService transportService,
                                        TimeValue duration)
        Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.
        Parameters:
        duration - the amount of time to delay sending and connecting.
      • addUnresponsiveRule

        public void addUnresponsiveRule​(TransportAddress transportAddress,
                                        TimeValue duration)
        Adds a rule that will cause ignores each send request, simulating an unresponsive node and failing to connect once the rule was added.
        Parameters:
        duration - the amount of time to delay sending and connecting.
      • addSendBehavior

        public boolean addSendBehavior​(TransportService transportService,
                                       StubbableTransport.SendRequestBehavior sendBehavior)
        Adds a new send behavior that is used for communication with the given delegate service.
        Returns:
        true if no other send behavior was registered for any of the addresses bound by delegate service.
      • addSendBehavior

        public boolean addSendBehavior​(TransportAddress transportAddress,
                                       StubbableTransport.SendRequestBehavior sendBehavior)
        Adds a new send behavior that is used for communication with the given delegate address.
        Returns:
        true if no other send behavior was registered for this address before.
      • addSendBehavior

        public boolean addSendBehavior​(StubbableTransport.SendRequestBehavior behavior)
        Adds a send behavior that is the default send behavior.
        Returns:
        true if no default send behavior was registered
      • addConnectBehavior

        public boolean addConnectBehavior​(TransportService transportService,
                                          StubbableTransport.OpenConnectionBehavior connectBehavior)
        Adds a new connect behavior that is used for creating connections with the given delegate service.
        Returns:
        true if no other send behavior was registered for any of the addresses bound by delegate service.
      • addConnectBehavior

        public boolean addConnectBehavior​(TransportAddress transportAddress,
                                          StubbableTransport.OpenConnectionBehavior connectBehavior)
        Adds a new connect behavior that is used for creating connections with the given delegate address.
        Returns:
        true if no other send behavior was registered for this address before.
      • addGetConnectionBehavior

        public boolean addGetConnectionBehavior​(TransportAddress transportAddress,
                                                StubbableConnectionManager.GetConnectionBehavior behavior)
        Adds a get connection behavior that is used for communication with the given delegate address.
        Returns:
        true if no other get connection behavior was registered for this address before.
      • addGetConnectionBehavior

        public boolean addGetConnectionBehavior​(StubbableConnectionManager.GetConnectionBehavior behavior)
        Adds a get connection behavior that is the default get connection behavior.
        Returns:
        true if no default get connection behavior was registered.
      • addNodeConnectedBehavior

        public boolean addNodeConnectedBehavior​(TransportAddress transportAddress,
                                                StubbableConnectionManager.NodeConnectedBehavior behavior)
        Adds a node connected behavior that is used for the given delegate address.
        Returns:
        true if no other node connected behavior was registered for this address before.
      • addNodeConnectedBehavior

        public boolean addNodeConnectedBehavior​(StubbableConnectionManager.NodeConnectedBehavior behavior)
        Adds a node connected behavior that is the default node connected behavior.
        Returns:
        true if no default node connected behavior was registered.
      • getOriginalTransport

        public Transport getOriginalTransport()
      • doClose

        protected void doClose()
                        throws java.io.IOException
        Overrides:
        doClose in class TransportService
        Throws:
        java.io.IOException