Search in sources :

Example 6 with ThreadPool

use of org.elasticsearch.threadpool.ThreadPool in project crate by crate.

the class RepositoryServiceTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    threadPool = new ThreadPool("dummy");
}
Also used : ThreadPool(org.elasticsearch.threadpool.ThreadPool) Before(org.junit.Before)

Example 7 with ThreadPool

use of org.elasticsearch.threadpool.ThreadPool in project crate by crate.

the class DecommissioningServiceTest method setUp.

@Before
public void setUp() throws Exception {
    NodeSettingsService settingsService = new NodeSettingsService(Settings.EMPTY);
    threadPool = mock(ThreadPool.class, Answers.RETURNS_MOCKS.get());
    jobsLogs = new JobsLogs(() -> true);
    sqlOperations = mock(SQLOperations.class, Answers.RETURNS_MOCKS.get());
    decommissioningService = new TestableDecommissioningService(Settings.EMPTY, new NoopClusterService(), jobsLogs, threadPool, settingsService, sqlOperations, mock(TransportClusterHealthAction.class), mock(TransportClusterUpdateSettingsAction.class));
}
Also used : ThreadPool(org.elasticsearch.threadpool.ThreadPool) JobsLogs(io.crate.operation.collect.stats.JobsLogs) NodeSettingsService(org.elasticsearch.node.settings.NodeSettingsService) SQLOperations(io.crate.action.sql.SQLOperations) NoopClusterService(org.elasticsearch.test.cluster.NoopClusterService) Before(org.junit.Before)

Example 8 with ThreadPool

use of org.elasticsearch.threadpool.ThreadPool 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 9 with ThreadPool

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

the class RetryTests method blockExecutor.

/**
     * Blocks the named executor by getting its only thread running a task blocked on a CyclicBarrier and fills the queue with a noop task.
     * So requests to use this queue should get {@link EsRejectedExecutionException}s.
     */
private CyclicBarrier blockExecutor(String name) throws Exception {
    ThreadPool threadPool = getInstanceFromNode(ThreadPool.class);
    CyclicBarrier barrier = new CyclicBarrier(2);
    logger.info("Blocking the [{}] executor", name);
    threadPool.executor(name).execute(() -> {
        try {
            threadPool.executor(name).execute(() -> {
            });
            barrier.await();
            logger.info("Blocked the [{}] executor", name);
            barrier.await();
            logger.info("Unblocking the [{}] executor", name);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
    barrier.await();
    blockedExecutors.add(barrier);
    return barrier;
}
Also used : ThreadPool(org.elasticsearch.threadpool.ThreadPool) EsRejectedExecutionException(org.elasticsearch.common.util.concurrent.EsRejectedExecutionException) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 10 with ThreadPool

use of org.elasticsearch.threadpool.ThreadPool 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)

Aggregations

ThreadPool (org.elasticsearch.threadpool.ThreadPool)73 Settings (org.elasticsearch.common.settings.Settings)47 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)45 TimeUnit (java.util.concurrent.TimeUnit)25 Before (org.junit.Before)24 IOException (java.io.IOException)22 TimeValue (org.elasticsearch.common.unit.TimeValue)22 Collections (java.util.Collections)21 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)21 ClusterState (org.elasticsearch.cluster.ClusterState)20 BigArrays (org.elasticsearch.common.util.BigArrays)20 TransportService (org.elasticsearch.transport.TransportService)19 List (java.util.List)18 ESTestCase (org.elasticsearch.test.ESTestCase)18 CountDownLatch (java.util.concurrent.CountDownLatch)17 Version (org.elasticsearch.Version)17 NamedWriteableRegistry (org.elasticsearch.common.io.stream.NamedWriteableRegistry)17 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 Arrays (java.util.Arrays)15 HashSet (java.util.HashSet)15