Search in sources :

Example 1 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class TCPTransportTests method testCompressRequest.

public void testCompressRequest() throws IOException {
    final boolean compressed = randomBoolean();
    final AtomicBoolean called = new AtomicBoolean(false);
    Req request = new Req(randomRealisticUnicodeOfLengthBetween(10, 100));
    ThreadPool threadPool = new TestThreadPool(TCPTransportTests.class.getName());
    try {
        TcpTransport transport = new TcpTransport("test", Settings.builder().put("transport.tcp.compress", compressed).build(), threadPool, new BigArrays(Settings.EMPTY, null), null, null, null) {

            @Override
            protected InetSocketAddress getLocalAddress(Object o) {
                return null;
            }

            @Override
            protected Object bind(String name, InetSocketAddress address) throws IOException {
                return null;
            }

            @Override
            protected void closeChannels(List channel) throws IOException {
            }

            @Override
            protected void sendMessage(Object o, BytesReference reference, Runnable sendListener) throws IOException {
                StreamInput streamIn = reference.streamInput();
                streamIn.skip(TcpHeader.MARKER_BYTES_SIZE);
                int len = streamIn.readInt();
                long requestId = streamIn.readLong();
                assertEquals(42, requestId);
                byte status = streamIn.readByte();
                Version version = Version.fromId(streamIn.readInt());
                assertEquals(Version.CURRENT, version);
                assertEquals(compressed, TransportStatus.isCompress(status));
                called.compareAndSet(false, true);
                if (compressed) {
                    final int bytesConsumed = TcpHeader.HEADER_SIZE;
                    streamIn = CompressorFactory.compressor(reference.slice(bytesConsumed, reference.length() - bytesConsumed)).streamInput(streamIn);
                }
                threadPool.getThreadContext().readHeaders(streamIn);
                assertEquals("foobar", streamIn.readString());
                Req readReq = new Req("");
                readReq.readFrom(streamIn);
                assertEquals(request.value, readReq.value);
            }

            @Override
            protected NodeChannels connectToChannels(DiscoveryNode node, ConnectionProfile profile) throws IOException {
                return new NodeChannels(node, new Object[profile.getNumConnections()], profile);
            }

            @Override
            protected boolean isOpen(Object o) {
                return false;
            }

            @Override
            public long serverOpen() {
                return 0;
            }

            @Override
            public NodeChannels getConnection(DiscoveryNode node) {
                return new NodeChannels(node, new Object[MockTcpTransport.LIGHT_PROFILE.getNumConnections()], MockTcpTransport.LIGHT_PROFILE);
            }
        };
        DiscoveryNode node = new DiscoveryNode("foo", buildNewFakeTransportAddress(), Version.CURRENT);
        Transport.Connection connection = transport.getConnection(node);
        connection.sendRequest(42, "foobar", request, TransportRequestOptions.EMPTY);
        assertTrue(called.get());
    } finally {
        ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS);
    }
}
Also used : BytesReference(org.elasticsearch.common.bytes.BytesReference) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) InetSocketAddress(java.net.InetSocketAddress) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BigArrays(org.elasticsearch.common.util.BigArrays) Version(org.elasticsearch.Version) StreamInput(org.elasticsearch.common.io.stream.StreamInput) List(java.util.List)

Example 2 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class Netty4HttpServerTransportTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    threadPool = new TestThreadPool("test");
    bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
}
Also used : NetworkService(org.elasticsearch.common.network.NetworkService) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 3 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class Netty4HttpServerPipeliningTests method setup.

@Before
public void setup() throws Exception {
    networkService = new NetworkService(Settings.EMPTY, Collections.emptyList());
    threadPool = new TestThreadPool("test");
    bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
}
Also used : NetworkService(org.elasticsearch.common.network.NetworkService) MockBigArrays(org.elasticsearch.common.util.MockBigArrays) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) NoneCircuitBreakerService(org.elasticsearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 4 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class NettyTransportMultiPortTests method testThatProfileWithoutValidNameIsIgnored.

public void testThatProfileWithoutValidNameIsIgnored() throws Exception {
    Settings settings = Settings.builder().put("network.host", host).put(TransportSettings.PORT.getKey(), 0).put("transport.profiles." + TransportService.DIRECT_RESPONSE_PROFILE + ".port", // will not actually bind to this
    22).put("transport.profiles..port", // will not actually bind to this
    23).build();
    ThreadPool threadPool = new TestThreadPool("tst");
    try (TcpTransport<?> transport = startTransport(settings, threadPool)) {
        assertEquals(0, transport.profileBoundAddresses().size());
        assertEquals(1, transport.boundAddress().boundAddresses().length);
    } finally {
        terminate(threadPool);
    }
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Settings(org.elasticsearch.common.settings.Settings) TransportSettings(org.elasticsearch.transport.TransportSettings)

Example 5 with TestThreadPool

use of org.elasticsearch.threadpool.TestThreadPool in project elasticsearch by elastic.

the class NettyTransportMultiPortTests method testThatDefaultProfileInheritsFromStandardSettings.

public void testThatDefaultProfileInheritsFromStandardSettings() throws Exception {
    Settings settings = Settings.builder().put("network.host", host).put(TransportSettings.PORT.getKey(), 0).put("transport.profiles.client1.port", 0).build();
    ThreadPool threadPool = new TestThreadPool("tst");
    try (TcpTransport<?> transport = startTransport(settings, threadPool)) {
        assertEquals(1, transport.profileBoundAddresses().size());
        assertEquals(1, transport.boundAddress().boundAddresses().length);
    } finally {
        terminate(threadPool);
    }
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Settings(org.elasticsearch.common.settings.Settings) TransportSettings(org.elasticsearch.transport.TransportSettings)

Aggregations

TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)48 ThreadPool (org.elasticsearch.threadpool.ThreadPool)21 Before (org.junit.Before)18 Settings (org.elasticsearch.common.settings.Settings)15 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)8 IOException (java.io.IOException)7 TimeValue (org.elasticsearch.common.unit.TimeValue)7 ClusterService (org.elasticsearch.cluster.service.ClusterService)6 AbstractRunnable (org.elasticsearch.common.util.concurrent.AbstractRunnable)6 NoneCircuitBreakerService (org.elasticsearch.indices.breaker.NoneCircuitBreakerService)6 TransportSettings (org.elasticsearch.transport.TransportSettings)6 ScheduledFuture (java.util.concurrent.ScheduledFuture)5 ClusterSettings (org.elasticsearch.common.settings.ClusterSettings)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 NetworkService (org.elasticsearch.common.network.NetworkService)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 ExecutionException (java.util.concurrent.ExecutionException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3