Search in sources :

Example 36 with NetworkService

use of org.elasticsearch.common.network.NetworkService in project elasticsearch by elastic.

the class MockTransportService method createNewService.

public static MockTransportService createNewService(Settings settings, Version version, ThreadPool threadPool, @Nullable ClusterSettings clusterSettings) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(ClusterModule.getNamedWriteables());
    final Transport transport = new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(settings, Collections.emptyList()), version);
    return createNewService(settings, transport, version, threadPool, clusterSettings);
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) NetworkService(org.elasticsearch.common.network.NetworkService) Transport(org.elasticsearch.transport.Transport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) MockTcpTransport(org.elasticsearch.transport.MockTcpTransport) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 37 with NetworkService

use of org.elasticsearch.common.network.NetworkService in project elasticsearch by elastic.

the class AbstractSimpleTransportTestCase method testTcpHandshake.

public void testTcpHandshake() throws IOException, InterruptedException {
    assumeTrue("only tcp transport has a handshake method", serviceA.getOriginalTransport() instanceof TcpTransport);
    TcpTransport originalTransport = (TcpTransport) serviceA.getOriginalTransport();
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    try (MockTcpTransport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(Settings.EMPTY, Collections.emptyList())) {

        @Override
        protected String handleRequest(MockChannel mockChannel, String profileName, StreamInput stream, long requestId, int messageLengthBytes, Version version, InetSocketAddress remoteAddress, byte status) throws IOException {
            return super.handleRequest(mockChannel, profileName, stream, requestId, messageLengthBytes, version, remoteAddress, // we flip the isHandshake bit back and act like the handler is not found
            (byte) (status & ~(1 << 3)));
        }
    }) {
        transport.transportServiceAdapter(serviceA.new Adapter());
        transport.start();
        // this acts like a node that doesn't have support for handshakes
        DiscoveryNode node = new DiscoveryNode("TS_TPC", "TS_TPC", transport.boundAddress().publishAddress(), emptyMap(), emptySet(), version0);
        ConnectTransportException exception = expectThrows(ConnectTransportException.class, () -> serviceA.connectToNode(node));
        assertTrue(exception.getCause() instanceof IllegalStateException);
        assertEquals("handshake failed", exception.getCause().getMessage());
    }
    try (TransportService service = buildService("TS_TPC", Version.CURRENT, null);
        TcpTransport.NodeChannels connection = originalTransport.openConnection(new DiscoveryNode("TS_TPC", "TS_TPC", service.boundAddress().publishAddress(), emptyMap(), emptySet(), version0), null)) {
        Version version = originalTransport.executeHandshake(connection.getNode(), connection.channel(TransportRequestOptions.Type.PING), TimeValue.timeValueSeconds(10));
        assertEquals(version, Version.CURRENT);
    }
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) InetSocketAddress(java.net.InetSocketAddress) Version(org.elasticsearch.Version) MockTransportService(org.elasticsearch.test.transport.MockTransportService) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Example 38 with NetworkService

use of org.elasticsearch.common.network.NetworkService in project elasticsearch by elastic.

the class AbstractSimpleTransportTestCase method testHandshakeUpdatesVersion.

public void testHandshakeUpdatesVersion() throws IOException {
    assumeTrue("only tcp transport has a handshake method", serviceA.getOriginalTransport() instanceof TcpTransport);
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    Version version = VersionUtils.randomVersionBetween(random(), Version.CURRENT.minimumCompatibilityVersion(), Version.CURRENT);
    try (MockTcpTransport transport = new MockTcpTransport(Settings.EMPTY, threadPool, BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(Settings.EMPTY, Collections.emptyList()), version)) {
        transport.transportServiceAdapter(serviceA.new Adapter());
        transport.start();
        DiscoveryNode node = new DiscoveryNode("TS_TPC", "TS_TPC", transport.boundAddress().publishAddress(), emptyMap(), emptySet(), Version.fromString("2.0.0"));
        ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
        builder.addConnections(1, TransportRequestOptions.Type.BULK, TransportRequestOptions.Type.PING, TransportRequestOptions.Type.RECOVERY, TransportRequestOptions.Type.REG, TransportRequestOptions.Type.STATE);
        try (Transport.Connection connection = serviceA.openConnection(node, builder.build())) {
            assertEquals(connection.getVersion(), version);
        }
    }
}
Also used : NamedWriteableRegistry(org.elasticsearch.common.io.stream.NamedWriteableRegistry) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Version(org.elasticsearch.Version) NetworkService(org.elasticsearch.common.network.NetworkService) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService)

Aggregations

NetworkService (org.elasticsearch.common.network.NetworkService)38 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)26 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)25 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)19 Settings (org.elasticsearch.common.settings.Settings)19 MockTransportService (org.elasticsearch.test.transport.MockTransportService)17 IOException (java.io.IOException)15 MockTcpTransport (org.elasticsearch.transport.MockTcpTransport)15 Transport (org.elasticsearch.transport.Transport)14 TransportAddress (org.elasticsearch.common.transport.TransportAddress)13 Before (org.junit.Before)13 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)12 TransportService (org.elasticsearch.transport.TransportService)12 BigArrays (org.elasticsearch.common.util.BigArrays)11 ThreadPool (org.elasticsearch.threadpool.ThreadPool)11 BoundTransportAddress (org.elasticsearch.common.transport.BoundTransportAddress)10 TimeValue (org.elasticsearch.common.unit.TimeValue)10 Collections (java.util.Collections)9 TimeUnit (java.util.concurrent.TimeUnit)9 Logger (org.apache.logging.log4j.Logger)9