Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tiered Caching] Fix test testComputeIfAbsentWithFactoryBasedCacheCreation #12700

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ public void onRemoval(RemovalNotification<K, V> notification) {
.setValueType(builder.cacheConfig.getValueType())
.setSettings(builder.cacheConfig.getSettings())
.setWeigher(builder.cacheConfig.getWeigher())
.setMaxSizeInBytes(builder.cacheConfig.getMaxSizeInBytes()) // TODO: Part of a workaround for an issue in TSC. Overall fix
// coming soon
.setMaxSizeInBytes(builder.cacheConfig.getMaxSizeInBytes())
.setExpireAfterAccess(builder.cacheConfig.getExpireAfterAccess())
.build(),
builder.cacheType,
builder.cacheFactories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ public void testComputeIfAbsentWithFactoryBasedCacheCreation() throws Exception
.getKey(),
onHeapCacheSize * keyValueSize + "b"
)
.put(
CacheSettings.getConcreteStoreNameSettingForCacheType(CacheType.INDICES_REQUEST_CACHE).getKey(),
TieredSpilloverCache.TieredSpilloverCacheFactory.TIERED_SPILLOVER_CACHE_NAME
)
.put(FeatureFlags.PLUGGABLE_CACHE, "true")
.build();

ICache<String, String> tieredSpilloverICache = new TieredSpilloverCache.TieredSpilloverCacheFactory().create(
Expand All @@ -127,12 +132,8 @@ public void testComputeIfAbsentWithFactoryBasedCacheCreation() throws Exception
.setWeigher((k, v) -> keyValueSize)
.setRemovalListener(removalListener)
.setSettings(settings)
.setCachedResultParser(new Function<String, CachedQueryResult.PolicyValues>() {
@Override
public CachedQueryResult.PolicyValues apply(String s) {
return new CachedQueryResult.PolicyValues(20_000_000L);
}
}) // Values will always appear to have taken 20_000_000 ns = 20 ms to compute
.setCachedResultParser(s -> new CachedQueryResult.PolicyValues(20_000_000L)) // Values will always appear to have taken
// 20_000_000 ns = 20 ms to compute
.build(),
CacheType.INDICES_REQUEST_CACHE,
Map.of(
Expand All @@ -145,20 +146,15 @@ public CachedQueryResult.PolicyValues apply(String s) {

TieredSpilloverCache<String, String> tieredSpilloverCache = (TieredSpilloverCache<String, String>) tieredSpilloverICache;

// Put values in cache more than it's size and cause evictions from onHeap.
int numOfItems1 = randomIntBetween(onHeapCacheSize + 1, totalSize);
List<String> onHeapKeys = new ArrayList<>();
List<String> diskTierKeys = new ArrayList<>();
for (int iter = 0; iter < numOfItems1; iter++) {
String key = UUID.randomUUID().toString();
LoadAwareCacheLoader<String, String> tieredCacheLoader = getLoadAwareCacheLoader();
tieredSpilloverCache.computeIfAbsent(key, tieredCacheLoader);
}
tieredSpilloverCache.getOnHeapCache().keys().forEach(onHeapKeys::add);
tieredSpilloverCache.getDiskCache().keys().forEach(diskTierKeys::add);

assertEquals(tieredSpilloverCache.getOnHeapCache().count(), onHeapKeys.size());
assertEquals(tieredSpilloverCache.getDiskCache().count(), diskTierKeys.size());
// Verify on heap cache size.
assertEquals(onHeapCacheSize, tieredSpilloverCache.getOnHeapCache().count());
assertEquals(numOfItems1 - onHeapCacheSize, tieredSpilloverCache.getDiskCache().count());
}

public void testWithFactoryCreationWithOnHeapCacheNotPresent() {
Expand All @@ -180,6 +176,11 @@ public void testWithFactoryCreationWithOnHeapCacheNotPresent() {
.getKey(),
onHeapCacheSize * keyValueSize + "b"
)
.put(
CacheSettings.getConcreteStoreNameSettingForCacheType(CacheType.INDICES_REQUEST_CACHE).getKey(),
TieredSpilloverCache.TieredSpilloverCacheFactory.TIERED_SPILLOVER_CACHE_NAME
)
.put(FeatureFlags.PLUGGABLE_CACHE, "true")
.build();

IllegalArgumentException ex = assertThrows(
Expand Down
Loading