Search in sources :

Example 6 with TestThreadPool

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

the class AbstractAsyncBulkByScrollActionTestCase method setupForTest.

@Before
public void setupForTest() {
    threadPool = new TestThreadPool(getTestName());
    task = new WorkingBulkByScrollTask(1, "test", "test", "test", TaskId.EMPTY_TASK_ID, null, 0);
}
Also used : TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 7 with TestThreadPool

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

the class AbstractSimpleTransportTestCase method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    threadPool = new TestThreadPool(getClass().getName());
    clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    // this one supports dynamic tracer updates
    serviceA = buildService("TS_A", version0, clusterSettings);
    nodeA = serviceA.getLocalNode();
    // this one doesn't support dynamic tracer updates
    serviceB = buildService("TS_B", version1, null);
    nodeB = serviceB.getLocalNode();
    // wait till all nodes are properly connected and the event has been sent, so tests in this class
    // will not get this callback called on the connections done in this setup
    final CountDownLatch latch = new CountDownLatch(2);
    TransportConnectionListener waitForConnection = new TransportConnectionListener() {

        @Override
        public void onNodeConnected(DiscoveryNode node) {
            latch.countDown();
        }

        @Override
        public void onNodeDisconnected(DiscoveryNode node) {
            fail("disconnect should not be called " + node);
        }
    };
    serviceA.addConnectionListener(waitForConnection);
    serviceB.addConnectionListener(waitForConnection);
    int numHandshakes = 1;
    serviceA.connectToNode(nodeB);
    serviceB.connectToNode(nodeA);
    assertNumHandshakes(numHandshakes, serviceA.getOriginalTransport());
    assertNumHandshakes(numHandshakes, serviceB.getOriginalTransport());
    assertThat("failed to wait for all nodes to connect", latch.await(5, TimeUnit.SECONDS), equalTo(true));
    serviceA.removeConnectionListener(waitForConnection);
    serviceB.removeConnectionListener(waitForConnection);
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) ClusterSettings(org.elasticsearch.common.settings.ClusterSettings) TestThreadPool(org.elasticsearch.threadpool.TestThreadPool) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Example 8 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 9 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 10 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)

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