Search in sources :

Example 46 with TestThreadPool

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

the class IndicesClusterStateServiceRandomUpdatesTests method setUp.

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

Example 47 with TestThreadPool

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

the class ResourceWatcherServiceTests method testHandle.

public void testHandle() throws Exception {
    ThreadPool threadPool = new TestThreadPool("test");
    Settings settings = Settings.builder().build();
    ResourceWatcherService service = new ResourceWatcherService(settings, threadPool);
    ResourceWatcher watcher = new ResourceWatcher() {

        @Override
        public void init() {
        }

        @Override
        public void checkAndNotify() {
        }
    };
    // checking default freq
    WatcherHandle handle = service.add(watcher);
    assertThat(handle, notNullValue());
    assertThat(handle.frequency(), equalTo(ResourceWatcherService.Frequency.MEDIUM));
    assertThat(service.lowMonitor.watchers.size(), is(0));
    assertThat(service.highMonitor.watchers.size(), is(0));
    assertThat(service.mediumMonitor.watchers.size(), is(1));
    handle.stop();
    assertThat(service.mediumMonitor.watchers.size(), is(0));
    handle.resume();
    assertThat(service.mediumMonitor.watchers.size(), is(1));
    handle.stop();
    // checking custom freq
    handle = service.add(watcher, ResourceWatcherService.Frequency.HIGH);
    assertThat(handle, notNullValue());
    assertThat(handle.frequency(), equalTo(ResourceWatcherService.Frequency.HIGH));
    assertThat(service.lowMonitor.watchers.size(), is(0));
    assertThat(service.mediumMonitor.watchers.size(), is(0));
    assertThat(service.highMonitor.watchers.size(), is(1));
    handle.stop();
    assertThat(service.highMonitor.watchers.size(), is(0));
    handle.resume();
    assertThat(service.highMonitor.watchers.size(), is(1));
    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)

Example 48 with TestThreadPool

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

the class ResourceWatcherServiceTests method testSettings.

public void testSettings() throws Exception {
    ThreadPool threadPool = new TestThreadPool("test");
    // checking the defaults
    Settings settings = Settings.builder().build();
    ResourceWatcherService service = new ResourceWatcherService(settings, threadPool);
    assertThat(service.highMonitor.interval, is(ResourceWatcherService.Frequency.HIGH.interval));
    assertThat(service.mediumMonitor.interval, is(ResourceWatcherService.Frequency.MEDIUM.interval));
    assertThat(service.lowMonitor.interval, is(ResourceWatcherService.Frequency.LOW.interval));
    // checking bwc
    settings = Settings.builder().put("resource.reload.interval", // only applies to medium
    "40s").build();
    service = new ResourceWatcherService(settings, threadPool);
    assertThat(service.highMonitor.interval.millis(), is(timeValueSeconds(5).millis()));
    assertThat(service.mediumMonitor.interval.millis(), is(timeValueSeconds(40).millis()));
    assertThat(service.lowMonitor.interval.millis(), is(timeValueSeconds(60).millis()));
    // checking custom
    settings = Settings.builder().put("resource.reload.interval.high", "10s").put("resource.reload.interval.medium", "20s").put("resource.reload.interval.low", "30s").build();
    service = new ResourceWatcherService(settings, threadPool);
    assertThat(service.highMonitor.interval.millis(), is(timeValueSeconds(10).millis()));
    assertThat(service.mediumMonitor.interval.millis(), is(timeValueSeconds(20).millis()));
    assertThat(service.lowMonitor.interval.millis(), is(timeValueSeconds(30).millis()));
    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)

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