use of org.opensearch.indices.IndicesRequestCache.Key in project OpenSearch by opensearch-project.
the class IndicesServiceCloseTests method testCloseWhileOngoingRequestUsesRequestCache.
public void testCloseWhileOngoingRequestUsesRequestCache() 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());
IndicesRequestCache cache = indicesService.indicesRequestCache;
IndexService indexService = indicesService.iterator().next();
IndexShard shard = indexService.getShard(0);
Engine.Searcher searcher = shard.acquireSearcher("test");
assertEquals(1, searcher.getIndexReader().maxDoc());
node.close();
assertEquals(1, indicesService.indicesRefCount.refCount());
assertEquals(0L, cache.count());
IndicesRequestCache.CacheEntity cacheEntity = new IndicesRequestCache.CacheEntity() {
@Override
public long ramBytesUsed() {
return 42;
}
@Override
public void onCached(Key key, BytesReference value) {
}
@Override
public boolean isOpen() {
return true;
}
@Override
public Object getCacheIdentity() {
return this;
}
@Override
public void onHit() {
}
@Override
public void onMiss() {
}
@Override
public void onRemoval(RemovalNotification<Key, BytesReference> notification) {
}
};
cache.getOrCompute(cacheEntity, () -> new BytesArray("bar"), searcher.getDirectoryReader(), new BytesArray("foo"));
assertEquals(1L, cache.count());
searcher.close();
assertEquals(0, indicesService.indicesRefCount.refCount());
assertEquals(0L, cache.count());
}
Aggregations