From 09ecf8a69e22f2f2f09d18c50e55a789dd258d82 Mon Sep 17 00:00:00 2001 From: Kiran Prakash Date: Fri, 29 Mar 2024 12:12:58 -0700 Subject: [PATCH] spotless Signed-off-by: Kiran Prakash --- .../indices/IndicesRequestCacheIT.java | 110 +++++++++--------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java index c06c6ce7b8b96..c20b994402143 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/IndicesRequestCacheIT.java @@ -982,61 +982,61 @@ public void testStaleKeysCleanup_NoIntervalSettingFallsBackAppropriately() throw assertEquals(expectedThirdCachedEntrySize, currentMemorySize); } - // when staleness threshold is high, it should NOT clean-up - public void testStaleKeysCleanup_ThresholdUpdates() throws Exception { - Instant start = Instant.now(); - long thresholdInMillis = 1_500; - String node = internalCluster().startNode( - Settings.builder() - .put(IndicesRequestCache.SETTING_INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING, 0.90) - .put(IndicesRequestCache.SETTING_INDICES_REQUEST_CACHE_CLEAN_INTERVAL_SETTING, TimeValue.timeValueMillis(thresholdInMillis)) - ); - String index = "index"; - Client client = client(node); - setupIndex(client, index); - - // create first cache entry - createCacheEntry(client, index, "hello"); - assertCacheState(client, index, 0, 1); - long expectedFirstCachedItemEntrySize = getRequestCacheStats(client, index).getMemorySizeInBytes(); - assertTrue(expectedFirstCachedItemEntrySize > 0); - - // create second cache entry - createCacheEntry(client, index, "there"); - assertCacheState(client, "index", 0, 2); - assertEquals(expectedFirstCachedItemEntrySize * 2, getRequestCacheStats(client, "index").getMemorySizeInBytes()); - - // force refresh so that it creates 2 stale keys in the cache for the cache cleaner to pick up. - flushAndRefresh("index"); - client().prepareIndex("index").setId("1").setSource("k", "good bye"); - ensureSearchable("index"); - - // create another entry - createCacheEntry(client, index, "hello1"); - assertCacheState(client, "index", 0, 3); - long cacheSizeBeforeCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes(); - assertTrue(cacheSizeBeforeCleanup > expectedFirstCachedItemEntrySize * 2); - assertEquals(cacheSizeBeforeCleanup, expectedFirstCachedItemEntrySize * 3, 2); - - Instant end = Instant.now(); - long elapsedTimeMillis = Duration.between(start, end).toMillis(); - // if this test is flaky, increase the sleep time. - long sleepTime = (thresholdInMillis - elapsedTimeMillis) + 2_000; - Thread.sleep(sleepTime); - - // cache cleaner should have skipped the cleanup - long cacheSizeAfterCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes(); - assertEquals(cacheSizeBeforeCleanup, cacheSizeAfterCleanup); - - // Set indices.requests.cache.cleanup.staleness_threshold to "10%" - ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); - updateSettingsRequest.persistentSettings(Settings.builder().put(INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING.getKey(), 0.10)); - assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); - - Thread.sleep(1_500); - cacheSizeAfterCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes(); - assertTrue(cacheSizeBeforeCleanup > cacheSizeAfterCleanup); - } + // when staleness threshold is high, it should NOT clean-up + public void testStaleKeysCleanup_ThresholdUpdates() throws Exception { + Instant start = Instant.now(); + long thresholdInMillis = 1_500; + String node = internalCluster().startNode( + Settings.builder() + .put(IndicesRequestCache.SETTING_INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING, 0.90) + .put(IndicesRequestCache.SETTING_INDICES_REQUEST_CACHE_CLEAN_INTERVAL_SETTING, TimeValue.timeValueMillis(thresholdInMillis)) + ); + String index = "index"; + Client client = client(node); + setupIndex(client, index); + + // create first cache entry + createCacheEntry(client, index, "hello"); + assertCacheState(client, index, 0, 1); + long expectedFirstCachedItemEntrySize = getRequestCacheStats(client, index).getMemorySizeInBytes(); + assertTrue(expectedFirstCachedItemEntrySize > 0); + + // create second cache entry + createCacheEntry(client, index, "there"); + assertCacheState(client, "index", 0, 2); + assertEquals(expectedFirstCachedItemEntrySize * 2, getRequestCacheStats(client, "index").getMemorySizeInBytes()); + + // force refresh so that it creates 2 stale keys in the cache for the cache cleaner to pick up. + flushAndRefresh("index"); + client().prepareIndex("index").setId("1").setSource("k", "good bye"); + ensureSearchable("index"); + + // create another entry + createCacheEntry(client, index, "hello1"); + assertCacheState(client, "index", 0, 3); + long cacheSizeBeforeCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes(); + assertTrue(cacheSizeBeforeCleanup > expectedFirstCachedItemEntrySize * 2); + assertEquals(cacheSizeBeforeCleanup, expectedFirstCachedItemEntrySize * 3, 2); + + Instant end = Instant.now(); + long elapsedTimeMillis = Duration.between(start, end).toMillis(); + // if this test is flaky, increase the sleep time. + long sleepTime = (thresholdInMillis - elapsedTimeMillis) + 2_000; + Thread.sleep(sleepTime); + + // cache cleaner should have skipped the cleanup + long cacheSizeAfterCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes(); + assertEquals(cacheSizeBeforeCleanup, cacheSizeAfterCleanup); + + // Set indices.requests.cache.cleanup.staleness_threshold to "10%" + ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest(); + updateSettingsRequest.persistentSettings(Settings.builder().put(INDICES_REQUEST_CACHE_STALENESS_THRESHOLD_SETTING.getKey(), 0.10)); + assertAcked(client().admin().cluster().updateSettings(updateSettingsRequest).actionGet()); + + Thread.sleep(1_500); + cacheSizeAfterCleanup = getRequestCacheStats(client, "index").getMemorySizeInBytes(); + assertTrue(cacheSizeBeforeCleanup > cacheSizeAfterCleanup); + } private void setupIndex(Client client, String index) throws Exception { assertAcked(