Search in sources :

Example 1 with TcpChannel

use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.

the class SimpleNioTransportTests method build.

@Override
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    NetworkService networkService = new NetworkService(Collections.emptyList());
    return new NioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings), namedWriteableRegistry, new NoneCircuitBreakerService(), new NioGroupFactory(settings, logger)) {

        @Override
        public void executeHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener<Version> listener) {
            if (doHandshake) {
                super.executeHandshake(node, channel, profile, listener);
            } else {
                listener.onResponse(version.minimumCompatibilityVersion());
            }
        }
    };
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ActionListener(org.opensearch.action.ActionListener) TcpChannel(org.opensearch.transport.TcpChannel) NetworkService(org.opensearch.common.network.NetworkService) ConnectionProfile(org.opensearch.transport.ConnectionProfile) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 2 with TcpChannel

use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.

the class SimpleNioTransportTests method testDefaultKeepAliveSettings.

public void testDefaultKeepAliveSettings() throws IOException {
    assumeTrue("setting default keepalive options not supported on this platform", (IOUtils.LINUX || IOUtils.MAC_OS_X) && JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0);
    try (MockTransportService serviceC = buildService("TS_C", Version.CURRENT, Settings.EMPTY);
        MockTransportService serviceD = buildService("TS_D", Version.CURRENT, Settings.EMPTY)) {
        serviceC.start();
        serviceC.acceptIncomingRequests();
        serviceD.start();
        serviceD.acceptIncomingRequests();
        try (Transport.Connection connection = serviceC.openConnection(serviceD.getLocalDiscoNode(), TestProfiles.LIGHT_PROFILE)) {
            assertThat(connection, instanceOf(StubbableTransport.WrappedConnection.class));
            Transport.Connection conn = ((StubbableTransport.WrappedConnection) connection).getConnection();
            assertThat(conn, instanceOf(TcpTransport.NodeChannels.class));
            TcpTransport.NodeChannels nodeChannels = (TcpTransport.NodeChannels) conn;
            for (TcpChannel channel : nodeChannels.getChannels()) {
                assertFalse(channel.isServerChannel());
                checkDefaultKeepAliveOptions(channel);
            }
            assertThat(serviceD.getOriginalTransport(), instanceOf(TcpTransport.class));
            for (TcpChannel channel : getAcceptedChannels((TcpTransport) serviceD.getOriginalTransport())) {
                assertTrue(channel.isServerChannel());
                checkDefaultKeepAliveOptions(channel);
            }
        }
    }
}
Also used : MockTransportService(org.opensearch.test.transport.MockTransportService) TcpChannel(org.opensearch.transport.TcpChannel) TcpTransport(org.opensearch.transport.TcpTransport) StubbableTransport(org.opensearch.test.transport.StubbableTransport) Transport(org.opensearch.transport.Transport) TcpTransport(org.opensearch.transport.TcpTransport)

Example 3 with TcpChannel

use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.

the class TaskManagerTests method testTrackingChannelTask.

public void testTrackingChannelTask() throws Exception {
    final TaskManager taskManager = new TaskManager(Settings.EMPTY, threadPool, Collections.emptySet());
    Set<Task> cancelledTasks = ConcurrentCollections.newConcurrentSet();
    taskManager.setTaskCancellationService(new TaskCancellationService(mock(TransportService.class)) {

        @Override
        void cancelTaskAndDescendants(CancellableTask task, String reason, boolean waitForCompletion, ActionListener<Void> listener) {
            assertThat(reason, equalTo("channel was closed"));
            assertFalse(waitForCompletion);
            assertTrue("task [" + task + "] was cancelled already", cancelledTasks.add(task));
        }
    });
    Map<TcpChannel, Set<Task>> pendingTasks = new HashMap<>();
    Set<Task> expectedCancelledTasks = new HashSet<>();
    FakeTcpChannel[] channels = new FakeTcpChannel[randomIntBetween(1, 10)];
    List<Releasable> stopTrackingTasks = new ArrayList<>();
    for (int i = 0; i < channels.length; i++) {
        channels[i] = new SingleThreadedTcpChannel();
    }
    int iterations = randomIntBetween(1, 200);
    for (int i = 0; i < iterations; i++) {
        final List<Releasable> subset = randomSubsetOf(stopTrackingTasks);
        stopTrackingTasks.removeAll(subset);
        Releasables.close(subset);
        final FakeTcpChannel channel = randomFrom(channels);
        final Task task = taskManager.register("transport", "test", new CancellableRequest(Integer.toString(i)));
        if (channel.isOpen() && randomBoolean()) {
            channel.close();
            expectedCancelledTasks.addAll(pendingTasks.getOrDefault(channel, Collections.emptySet()));
        }
        final Releasable stopTracking = taskManager.startTrackingCancellableChannelTask(channel, (CancellableTask) task);
        if (channel.isOpen()) {
            pendingTasks.computeIfAbsent(channel, k -> new HashSet<>()).add(task);
            stopTrackingTasks.add(() -> {
                stopTracking.close();
                assertTrue(pendingTasks.get(channel).remove(task));
                expectedCancelledTasks.remove(task);
            });
        } else {
            expectedCancelledTasks.add(task);
        }
    }
    assertBusy(() -> assertThat(expectedCancelledTasks, everyItem(in(cancelledTasks))), 30, TimeUnit.SECONDS);
    for (FakeTcpChannel channel : channels) {
        channel.close();
    }
    assertThat(taskManager.numberOfChannelPendingTaskTrackers(), equalTo(0));
}
Also used : ThreadPool(org.opensearch.threadpool.ThreadPool) TestThreadPool(org.opensearch.threadpool.TestThreadPool) HashMap(java.util.HashMap) Releasable(org.opensearch.common.lease.Releasable) Releasables(org.opensearch.common.lease.Releasables) ArrayList(java.util.ArrayList) ConcurrentCollections(org.opensearch.common.util.concurrent.ConcurrentCollections) HashSet(java.util.HashSet) Matchers.everyItem(org.hamcrest.Matchers.everyItem) After(org.junit.After) Map(java.util.Map) ActionListener(org.opensearch.action.ActionListener) TransportTasksActionTests(org.opensearch.action.admin.cluster.node.tasks.TransportTasksActionTests) Before(org.junit.Before) TimeValue(org.opensearch.common.unit.TimeValue) TransportRequest(org.opensearch.transport.TransportRequest) Iterator(java.util.Iterator) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) TcpChannel(org.opensearch.transport.TcpChannel) Set(java.util.Set) Settings(org.opensearch.common.settings.Settings) FakeTcpChannel(org.opensearch.transport.FakeTcpChannel) TransportService(org.opensearch.transport.TransportService) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Phaser(java.util.concurrent.Phaser) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) Matchers.in(org.hamcrest.Matchers.in) Mockito.mock(org.mockito.Mockito.mock) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FakeTcpChannel(org.opensearch.transport.FakeTcpChannel) TcpChannel(org.opensearch.transport.TcpChannel) FakeTcpChannel(org.opensearch.transport.FakeTcpChannel) Releasable(org.opensearch.common.lease.Releasable) HashSet(java.util.HashSet)

Example 4 with TcpChannel

use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.

the class SimpleMockNioTransportTests method build.

@Override
protected Transport build(Settings settings, final Version version, ClusterSettings clusterSettings, boolean doHandshake) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    NetworkService networkService = new NetworkService(Collections.emptyList());
    return new MockNioTransport(settings, version, threadPool, networkService, new MockPageCacheRecycler(settings), namedWriteableRegistry, new NoneCircuitBreakerService()) {

        @Override
        public void executeHandshake(DiscoveryNode node, TcpChannel channel, ConnectionProfile profile, ActionListener<Version> listener) {
            if (doHandshake) {
                super.executeHandshake(node, channel, profile, listener);
            } else {
                listener.onResponse(version.minimumCompatibilityVersion());
            }
        }
    };
}
Also used : NamedWriteableRegistry(org.opensearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) MockPageCacheRecycler(org.opensearch.common.util.MockPageCacheRecycler) ActionListener(org.opensearch.action.ActionListener) TcpChannel(org.opensearch.transport.TcpChannel) NetworkService(org.opensearch.common.network.NetworkService) ConnectionProfile(org.opensearch.transport.ConnectionProfile) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService)

Example 5 with TcpChannel

use of org.opensearch.transport.TcpChannel in project OpenSearch by opensearch-project.

the class SimpleNetty4TransportTests method testDefaultKeepAliveSettings.

public void testDefaultKeepAliveSettings() throws IOException {
    assumeTrue("setting default keepalive options not supported on this platform", (IOUtils.LINUX || IOUtils.MAC_OS_X) && JavaVersion.current().compareTo(JavaVersion.parse("11")) >= 0);
    try (MockTransportService serviceC = buildService("TS_C", Version.CURRENT, Settings.EMPTY);
        MockTransportService serviceD = buildService("TS_D", Version.CURRENT, Settings.EMPTY)) {
        serviceC.start();
        serviceC.acceptIncomingRequests();
        serviceD.start();
        serviceD.acceptIncomingRequests();
        try (Transport.Connection connection = serviceC.openConnection(serviceD.getLocalDiscoNode(), TestProfiles.LIGHT_PROFILE)) {
            assertThat(connection, instanceOf(StubbableTransport.WrappedConnection.class));
            Transport.Connection conn = ((StubbableTransport.WrappedConnection) connection).getConnection();
            assertThat(conn, instanceOf(TcpTransport.NodeChannels.class));
            TcpTransport.NodeChannels nodeChannels = (TcpTransport.NodeChannels) conn;
            for (TcpChannel channel : nodeChannels.getChannels()) {
                assertFalse(channel.isServerChannel());
                checkDefaultKeepAliveOptions(channel);
            }
            assertThat(serviceD.getOriginalTransport(), instanceOf(TcpTransport.class));
            for (TcpChannel channel : getAcceptedChannels((TcpTransport) serviceD.getOriginalTransport())) {
                assertTrue(channel.isServerChannel());
                checkDefaultKeepAliveOptions(channel);
            }
        }
    }
}
Also used : MockTransportService(org.opensearch.test.transport.MockTransportService) TcpChannel(org.opensearch.transport.TcpChannel) TcpTransport(org.opensearch.transport.TcpTransport) StubbableTransport(org.opensearch.test.transport.StubbableTransport) Transport(org.opensearch.transport.Transport) TcpTransport(org.opensearch.transport.TcpTransport)

Aggregations

TcpChannel (org.opensearch.transport.TcpChannel)5 ActionListener (org.opensearch.action.ActionListener)3 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)2 NamedWriteableRegistry (org.opensearch.common.io.stream.NamedWriteableRegistry)2 NetworkService (org.opensearch.common.network.NetworkService)2 MockPageCacheRecycler (org.opensearch.common.util.MockPageCacheRecycler)2 NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)2 MockTransportService (org.opensearch.test.transport.MockTransportService)2 StubbableTransport (org.opensearch.test.transport.StubbableTransport)2 ConnectionProfile (org.opensearch.transport.ConnectionProfile)2 TcpTransport (org.opensearch.transport.TcpTransport)2 Transport (org.opensearch.transport.Transport)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1