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);
}
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);
}
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);
}
Aggregations