Search in sources :

Example 1 with NOOP_TRANSPORT_INTERCEPTOR

use of org.opensearch.transport.TransportService.NOOP_TRANSPORT_INTERCEPTOR in project OpenSearch by opensearch-project.

the class DisruptableMockTransportTests method initTransports.

@Before
public void initTransports() {
    node1 = new DiscoveryNode("node1", buildNewFakeTransportAddress(), Version.CURRENT);
    node2 = new DiscoveryNode("node2", buildNewFakeTransportAddress(), Version.CURRENT);
    disconnectedLinks = new HashSet<>();
    blackholedLinks = new HashSet<>();
    blackholedRequestLinks = new HashSet<>();
    List<DisruptableMockTransport> transports = new ArrayList<>();
    deterministicTaskQueue = new DeterministicTaskQueue(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), "dummy").build(), random());
    final DisruptableMockTransport transport1 = new DisruptableMockTransport(node1, logger, deterministicTaskQueue) {

        @Override
        protected ConnectionStatus getConnectionStatus(DiscoveryNode destination) {
            return DisruptableMockTransportTests.this.getConnectionStatus(getLocalNode(), destination);
        }

        @Override
        protected Optional<DisruptableMockTransport> getDisruptableMockTransport(TransportAddress address) {
            return transports.stream().filter(t -> t.getLocalNode().getAddress().equals(address)).findAny();
        }

        @Override
        protected void execute(Runnable runnable) {
            deterministicTaskQueue.scheduleNow(runnable);
        }
    };
    final DisruptableMockTransport transport2 = new DisruptableMockTransport(node2, logger, deterministicTaskQueue) {

        @Override
        protected ConnectionStatus getConnectionStatus(DiscoveryNode destination) {
            return DisruptableMockTransportTests.this.getConnectionStatus(getLocalNode(), destination);
        }

        @Override
        protected Optional<DisruptableMockTransport> getDisruptableMockTransport(TransportAddress address) {
            return transports.stream().filter(t -> t.getLocalNode().getAddress().equals(address)).findAny();
        }

        @Override
        protected void execute(Runnable runnable) {
            deterministicTaskQueue.scheduleNow(runnable);
        }
    };
    transports.add(transport1);
    transports.add(transport2);
    service1 = transport1.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), NOOP_TRANSPORT_INTERCEPTOR, a -> node1, null, Collections.emptySet());
    service2 = transport2.createTransportService(Settings.EMPTY, deterministicTaskQueue.getThreadPool(), NOOP_TRANSPORT_INTERCEPTOR, a -> node2, null, Collections.emptySet());
    service1.start();
    service2.start();
    final PlainActionFuture<Void> fut1 = new PlainActionFuture<>();
    service1.connectToNode(node2, fut1);
    final PlainActionFuture<Void> fut2 = new PlainActionFuture<>();
    service2.connectToNode(node1, fut2);
    deterministicTaskQueue.runAllTasksInTimeOrder();
    assertTrue(fut1.isDone());
    assertTrue(fut2.isDone());
}
Also used : TransportRequestHandler(org.opensearch.transport.TransportRequestHandler) ThreadPool(org.opensearch.threadpool.ThreadPool) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Version(org.opensearch.Version) Node(org.opensearch.node.Node) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) ConnectionStatus(org.opensearch.test.disruption.DisruptableMockTransport.ConnectionStatus) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) Empty(org.opensearch.transport.TransportResponse.Empty) DeterministicTaskQueue(org.opensearch.cluster.coordination.DeterministicTaskQueue) TransportChannel(org.opensearch.transport.TransportChannel) TransportRequest(org.opensearch.transport.TransportRequest) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) TransportResponse(org.opensearch.transport.TransportResponse) TransportService(org.opensearch.transport.TransportService) Tuple(org.opensearch.common.collect.Tuple) TransportAddress(org.opensearch.common.transport.TransportAddress) Consumer(java.util.function.Consumer) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) Optional(java.util.Optional) ConnectTransportException(org.opensearch.transport.ConnectTransportException) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.endsWith(org.hamcrest.Matchers.endsWith) TransportException(org.opensearch.transport.TransportException) NOOP_TRANSPORT_INTERCEPTOR(org.opensearch.transport.TransportService.NOOP_TRANSPORT_INTERCEPTOR) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) DeterministicTaskQueue(org.opensearch.cluster.coordination.DeterministicTaskQueue) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) TransportAddress(org.opensearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) Before(org.junit.Before)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.endsWith (org.hamcrest.Matchers.endsWith)1 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)1 Before (org.junit.Before)1 Version (org.opensearch.Version)1 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)1 DeterministicTaskQueue (org.opensearch.cluster.coordination.DeterministicTaskQueue)1 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)1 Tuple (org.opensearch.common.collect.Tuple)1 StreamInput (org.opensearch.common.io.stream.StreamInput)1