Search in sources :

Example 21 with TestThreadPool

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

the class IndexShardTestCase method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(getClass().getName());
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool)

Example 22 with TestThreadPool

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

the class NetworkModuleTests method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(NetworkModuleTests.class.getName());
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool)

Example 23 with TestThreadPool

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

the class PrioritizedExecutorsTests method testTimeoutCleanup.

public void testTimeoutCleanup() throws Exception {
    ThreadPool threadPool = new TestThreadPool("test");
    final ScheduledThreadPoolExecutor timer = (ScheduledThreadPoolExecutor) threadPool.scheduler();
    final AtomicBoolean timeoutCalled = new AtomicBoolean();
    PrioritizedEsThreadPoolExecutor executor = EsExecutors.newSinglePrioritizing(getTestName(), EsExecutors.daemonThreadFactory(getTestName()), holder);
    final CountDownLatch invoked = new CountDownLatch(1);
    executor.execute(new Runnable() {

        @Override
        public void run() {
            invoked.countDown();
        }
    }, timer, TimeValue.timeValueHours(1), new Runnable() {

        @Override
        public void run() {
            // We should never get here
            timeoutCalled.set(true);
        }
    });
    invoked.await();
    // the timeout handler is added post execution (and quickly cancelled). We have allow for this
    // and use assert busy
    assertBusy(new Runnable() {

        @Override
        public void run() {
            assertThat(timer.getQueue().size(), equalTo(0));
        }
    }, 5, TimeUnit.SECONDS);
    assertThat(timeoutCalled.get(), equalTo(false));
    assertTrue(terminate(executor));
    assertTrue(terminate(threadPool));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 24 with TestThreadPool

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

the class FileBasedUnicastHostsProviderTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(FileBasedUnicastHostsProviderTests.class.getName());
    executorService = Executors.newSingleThreadExecutor();
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 25 with TestThreadPool

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

the class NettyTransportMultiPortTests method testThatNettyCanBindToMultiplePorts.

public void testThatNettyCanBindToMultiplePorts() throws Exception {
    Settings settings = Settings.builder().put("network.host", host).put(TransportSettings.PORT.getKey(), // will not actually bind to this
    22).put("transport.profiles.default.port", 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