use of org.opensearch.node.Node in project OpenSearch by opensearch-project.
the class IndicesServiceCloseTests method testCloseAfterRequestHasUsedQueryCache.
public void testCloseAfterRequestHasUsedQueryCache() throws Exception {
Node node = startNode();
IndicesService indicesService = node.injector().getInstance(IndicesService.class);
assertEquals(1, indicesService.indicesRefCount.refCount());
assertAcked(node.client().admin().indices().prepareCreate("test").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1).put(SETTING_NUMBER_OF_REPLICAS, 0).put(IndexModule.INDEX_QUERY_CACHE_EVERYTHING_SETTING.getKey(), true)));
node.client().prepareIndex("test").setId("1").setSource(Collections.singletonMap("foo", 3L)).get();
OpenSearchAssertions.assertAllSuccessful(node.client().admin().indices().prepareRefresh("test").get());
assertEquals(2, indicesService.indicesRefCount.refCount());
IndicesQueryCache cache = indicesService.getIndicesQueryCache();
IndexService indexService = indicesService.iterator().next();
IndexShard shard = indexService.getShard(0);
Engine.Searcher searcher = shard.acquireSearcher("test");
assertEquals(1, searcher.getIndexReader().maxDoc());
Query query = LongPoint.newRangeQuery("foo", 0, 5);
assertEquals(0L, cache.getStats(shard.shardId()).getCacheSize());
searcher.count(query);
assertEquals(1L, cache.getStats(shard.shardId()).getCacheSize());
searcher.close();
assertEquals(2, indicesService.indicesRefCount.refCount());
assertEquals(1L, cache.getStats(shard.shardId()).getCacheSize());
node.close();
assertEquals(0, indicesService.indicesRefCount.refCount());
assertEquals(0L, cache.getStats(shard.shardId()).getCacheSize());
}
Aggregations