Skip to content

Commit

Permalink
revert the test removal
Browse files Browse the repository at this point in the history
Signed-off-by: Kiran Prakash <[email protected]>
  • Loading branch information
kiranprakash154 committed Jun 12, 2024
1 parent e89706a commit 09defd5
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,58 @@ public void testBasicOperationsCache() throws Exception {
assertEquals(0, cache.numRegisteredCloseListeners());
}

public void testBasicOperationsCacheWithFeatureFlag() throws Exception {
threadPool = getThreadPool();
Settings settings = Settings.builder().put(super.featureFlagSettings()).put(FeatureFlags.PLUGGABLE_CACHE, "true").build();
cache = getIndicesRequestCache(settings);
writer.addDocument(newDoc(0, "foo"));
DirectoryReader reader = getReader(writer, indexShard.shardId());

// initial cache
IndicesService.IndexShardCacheEntity entity = new IndicesService.IndexShardCacheEntity(indexShard);
Loader loader = new Loader(reader, 0);
BytesReference value = cache.getOrCompute(entity, loader, reader, getTermBytes());
assertEquals("foo", value.streamInput().readString());
ShardRequestCache requestCacheStats = indexShard.requestCache();
assertEquals(0, requestCacheStats.stats().getHitCount());
assertEquals(1, requestCacheStats.stats().getMissCount());
assertEquals(0, requestCacheStats.stats().getEvictions());
assertFalse(loader.loadedFromCache);
assertEquals(1, cache.count());

// cache hit
entity = new IndicesService.IndexShardCacheEntity(indexShard);
loader = new Loader(reader, 0);
value = cache.getOrCompute(entity, loader, reader, getTermBytes());
assertEquals("foo", value.streamInput().readString());
requestCacheStats = indexShard.requestCache();
assertEquals(1, requestCacheStats.stats().getHitCount());
assertEquals(1, requestCacheStats.stats().getMissCount());
assertEquals(0, requestCacheStats.stats().getEvictions());
assertTrue(loader.loadedFromCache);
assertEquals(1, cache.count());
assertTrue(requestCacheStats.stats().getMemorySize().bytesAsInt() > value.length());
assertEquals(1, cache.numRegisteredCloseListeners());

// Closing the cache doesn't modify an already returned CacheEntity
if (randomBoolean()) {
reader.close();
} else {
indexShard.close("test", true, true); // closed shard but reader is still open
cache.clear(entity);
}
cache.cacheCleanupManager.cleanCache();
assertEquals(1, requestCacheStats.stats().getHitCount());
assertEquals(1, requestCacheStats.stats().getMissCount());
assertEquals(0, requestCacheStats.stats().getEvictions());
assertTrue(loader.loadedFromCache);
assertEquals(0, cache.count());
assertEquals(0, requestCacheStats.stats().getMemorySize().bytesAsInt());

IOUtils.close(reader);
assertEquals(0, cache.numRegisteredCloseListeners());
}

public void testCacheDifferentReaders() throws Exception {
threadPool = getThreadPool();
cache = getIndicesRequestCache(Settings.EMPTY);
Expand Down

0 comments on commit 09defd5

Please sign in to comment.