use of org.elasticsearch.threadpool.ThreadPool 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.ThreadPool 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);
}
use of org.elasticsearch.threadpool.ThreadPool in project elasticsearch by elastic.
the class IndexShardTestCase method newShard.
/**
* creates a new initializing shard.
*
* @param routing shard routing to use
* @param shardPath path to use for shard data
* @param indexMetaData indexMetaData for the shard, including any mapping
* @param indexSearcherWrapper an optional wrapper to be used during searchers
* @param listeners an optional set of listeners to add to the shard
*/
protected IndexShard newShard(ShardRouting routing, ShardPath shardPath, IndexMetaData indexMetaData, @Nullable IndexSearcherWrapper indexSearcherWrapper, Runnable globalCheckpointSyncer, @Nullable EngineFactory engineFactory, IndexingOperationListener... listeners) throws IOException {
final Settings nodeSettings = Settings.builder().put("node.name", routing.currentNodeId()).build();
final IndexSettings indexSettings = new IndexSettings(indexMetaData, nodeSettings);
final IndexShard indexShard;
final Store store = createStore(indexSettings, shardPath);
boolean success = false;
try {
IndexCache indexCache = new IndexCache(indexSettings, new DisabledQueryCache(indexSettings), null);
MapperService mapperService = MapperTestUtils.newMapperService(xContentRegistry(), createTempDir(), indexSettings.getSettings());
mapperService.merge(indexMetaData, MapperService.MergeReason.MAPPING_RECOVERY, true);
SimilarityService similarityService = new SimilarityService(indexSettings, Collections.emptyMap());
final IndexEventListener indexEventListener = new IndexEventListener() {
};
final Engine.Warmer warmer = searcher -> {
};
IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(nodeSettings, new IndexFieldDataCache.Listener() {
});
IndexFieldDataService indexFieldDataService = new IndexFieldDataService(indexSettings, indicesFieldDataCache, new NoneCircuitBreakerService(), mapperService);
indexShard = new IndexShard(routing, indexSettings, shardPath, store, indexCache, mapperService, similarityService, indexFieldDataService, engineFactory, indexEventListener, indexSearcherWrapper, threadPool, BigArrays.NON_RECYCLING_INSTANCE, warmer, globalCheckpointSyncer, Collections.emptyList(), Arrays.asList(listeners));
success = true;
} finally {
if (success == false) {
IOUtils.close(store);
}
}
return indexShard;
}
Aggregations