Skip to content

Commit 09ecf8a

Browse files
spotless
Signed-off-by: Kiran Prakash <awskiran@amazon.com>
1 parent bf11aad commit 09ecf8a

File tree

1 file changed

+55
-55
lines changed

1 file changed

+55
-55
lines changed

server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java

+55-55
Original file line numberDiff line numberDiff line change
@@ -982,61 +982,61 @@ public void testStaleKeysCleanup_NoIntervalSettingFallsBackAppropriately() throw
982982
assertEquals(expectedThirdCachedEntrySize, currentMemorySize);
983983
}
984984

985-
// when staleness threshold is high, it should NOT clean-up
986-
public void testStaleKeysCleanup_ThresholdUpdates() throws Exception {
987-
Instant start = Instant.now();
988-
long thresholdInMillis = 1_500;
989-
String node = internalCluster().startNode(
990-
Settings.builder()
991-
.put(IndicesRequestCache.SETTING_INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING, 0.90)
992-
.put(IndicesRequestCache.SETTING_INDICES_REQUEST_CACHE_CLEAN_INTERVAL_SETTING, TimeValue.timeValueMillis(thresholdInMillis))
993-
);
994-
String index = "index";
995-
Client client = client(node);
996-
setupIndex(client, index);
997-
998-
// create first cache entry
999-
createCacheEntry(client, index, "hello");
1000-
assertCacheState(client, index, 0, 1);
1001-
long expectedFirstCachedItemEntrySize = getRequestCacheStats(client, index).getMemorySizeInBytes();
1002-
assertTrue(expectedFirstCachedItemEntrySize > 0);
1003-
1004-
// create second cache entry
1005-
createCacheEntry(client, index, "there");
1006-
assertCacheState(client, "index", 0, 2);
1007-
assertEquals(expectedFirstCachedItemEntrySize * 2, getRequestCacheStats(client, "index").getMemorySizeInBytes());
1008-
1009-
// force refresh so that it creates 2 stale keys in the cache for the cache cleaner to pick up.
1010-
flushAndRefresh("index");
1011-
client().prepareIndex("index").setId("1").setSource("k", "good bye");
1012-
ensureSearchable("index");
1013-
1014-
// create another entry
1015-
createCacheEntry(client, index, "hello1");
1016-
assertCacheState(client, "index", 0, 3);
1017-
long cacheSizeBeforeCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes();
1018-
assertTrue(cacheSizeBeforeCleanup > expectedFirstCachedItemEntrySize * 2);
1019-
assertEquals(cacheSizeBeforeCleanup, expectedFirstCachedItemEntrySize * 3, 2);
1020-
1021-
Instant end = Instant.now();
1022-
long elapsedTimeMillis = Duration.between(start, end).toMillis();
1023-
// if this test is flaky, increase the sleep time.
1024-
long sleepTime = (thresholdInMillis - elapsedTimeMillis) + 2_000;
1025-
Thread.sleep(sleepTime);
1026-
1027-
// cache cleaner should have skipped the cleanup
1028-
long cacheSizeAfterCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes();
1029-
assertEquals(cacheSizeBeforeCleanup, cacheSizeAfterCleanup);
1030-
1031-
// Set indices.requests.cache.cleanup.staleness_threshold to "10%"
1032-
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
1033-
updateSettingsRequest.persistentSettings(Settings.builder().put(INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING.getKey(), 0.10));
1034-
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
1035-
1036-
Thread.sleep(1_500);
1037-
cacheSizeAfterCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes();
1038-
assertTrue(cacheSizeBeforeCleanup > cacheSizeAfterCleanup);
1039-
}
985+
// when staleness threshold is high, it should NOT clean-up
986+
public void testStaleKeysCleanup_ThresholdUpdates() throws Exception {
987+
Instant start = Instant.now();
988+
long thresholdInMillis = 1_500;
989+
String node = internalCluster().startNode(
990+
Settings.builder()
991+
.put(IndicesRequestCache.SETTING_INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING, 0.90)
992+
.put(IndicesRequestCache.SETTING_INDICES_REQUEST_CACHE_CLEAN_INTERVAL_SETTING, TimeValue.timeValueMillis(thresholdInMillis))
993+
);
994+
String index = "index";
995+
Client client = client(node);
996+
setupIndex(client, index);
997+
998+
// create first cache entry
999+
createCacheEntry(client, index, "hello");
1000+
assertCacheState(client, index, 0, 1);
1001+
long expectedFirstCachedItemEntrySize = getRequestCacheStats(client, index).getMemorySizeInBytes();
1002+
assertTrue(expectedFirstCachedItemEntrySize > 0);
1003+
1004+
// create second cache entry
1005+
createCacheEntry(client, index, "there");
1006+
assertCacheState(client, "index", 0, 2);
1007+
assertEquals(expectedFirstCachedItemEntrySize * 2, getRequestCacheStats(client, "index").getMemorySizeInBytes());
1008+
1009+
// force refresh so that it creates 2 stale keys in the cache for the cache cleaner to pick up.
1010+
flushAndRefresh("index");
1011+
client().prepareIndex("index").setId("1").setSource("k", "good bye");
1012+
ensureSearchable("index");
1013+
1014+
// create another entry
1015+
createCacheEntry(client, index, "hello1");
1016+
assertCacheState(client, "index", 0, 3);
1017+
long cacheSizeBeforeCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes();
1018+
assertTrue(cacheSizeBeforeCleanup > expectedFirstCachedItemEntrySize * 2);
1019+
assertEquals(cacheSizeBeforeCleanup, expectedFirstCachedItemEntrySize * 3, 2);
1020+
1021+
Instant end = Instant.now();
1022+
long elapsedTimeMillis = Duration.between(start, end).toMillis();
1023+
// if this test is flaky, increase the sleep time.
1024+
long sleepTime = (thresholdInMillis - elapsedTimeMillis) + 2_000;
1025+
Thread.sleep(sleepTime);
1026+
1027+
// cache cleaner should have skipped the cleanup
1028+
long cacheSizeAfterCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes();
1029+
assertEquals(cacheSizeBeforeCleanup, cacheSizeAfterCleanup);
1030+
1031+
// Set indices.requests.cache.cleanup.staleness_threshold to "10%"
1032+
ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest();
1033+
updateSettingsRequest.persistentSettings(Settings.builder().put(INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING.getKey(), 0.10));
1034+
assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet());
1035+
1036+
Thread.sleep(1_500);
1037+
cacheSizeAfterCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes();
1038+
assertTrue(cacheSizeBeforeCleanup > cacheSizeAfterCleanup);
1039+
}
10401040

10411041
private void setupIndex(Client client, String index) throws Exception {
10421042
assertAcked(

0 commit comments

Comments
 (0)