Search in sources :

Example 21 with Node

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());
}
Also used : Query(org.apache.lucene.search.Query) IndexService(org.opensearch.index.IndexService) Node(org.opensearch.node.Node) MockNode(org.opensearch.node.MockNode) NodeRoles.dataNode(org.opensearch.test.NodeRoles.dataNode) IndexShard(org.opensearch.index.shard.IndexShard) Engine(org.opensearch.index.engine.Engine)

Aggregations

Node (org.opensearch.node.Node)21 MockNode (org.opensearch.node.MockNode)15 Settings (org.opensearch.common.settings.Settings)12 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)10 NodeRoles.dataNode (org.opensearch.test.NodeRoles.dataNode)10 ArrayList (java.util.ArrayList)9 IndexService (org.opensearch.index.IndexService)9 Collections (java.util.Collections)8 List (java.util.List)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 IndexShard (org.opensearch.index.shard.IndexShard)8 IOException (java.io.IOException)7 Set (java.util.Set)7 TimeUnit (java.util.concurrent.TimeUnit)7 Collectors (java.util.stream.Collectors)7 Logger (org.apache.logging.log4j.Logger)7 Matchers.equalTo (org.hamcrest.Matchers.equalTo)7 TimeValue (org.opensearch.common.unit.TimeValue)7 UncheckedIOException (java.io.UncheckedIOException)6 Path (java.nio.file.Path)6