@@ -42,7 +42,7 @@ public void testComputeIfAbsentWithoutAnyOnHeapCacheEviction() throws Exception
42
42
43
43
MockCacheRemovalListener <String , String > removalListener = new MockCacheRemovalListener <>();
44
44
TieredSpilloverCache <String , String > tieredSpilloverCache = intializeTieredSpilloverCache (
45
- onHeapCacheSize ,
45
+ keyValueSize ,
46
46
randomIntBetween (1 , 4 ),
47
47
removalListener ,
48
48
Settings .builder ()
@@ -142,10 +142,6 @@ public void testComputeIfAbsentWithFactoryBasedCacheCreation() throws Exception
142
142
LoadAwareCacheLoader <String , String > tieredCacheLoader = getLoadAwareCacheLoader ();
143
143
tieredSpilloverCache .computeIfAbsent (key , tieredCacheLoader );
144
144
}
145
- long actualDiskCacheSize = tieredSpilloverCache .getDiskCache ().count ();
146
- assertEquals (actualDiskCacheSize , removalListener .evictionsMetric .count ()); // Evictions from onHeap equal to
147
- // disk cache size.
148
-
149
145
tieredSpilloverCache .getOnHeapCache ().keys ().forEach (onHeapKeys ::add );
150
146
tieredSpilloverCache .getDiskCache ().keys ().forEach (diskTierKeys ::add );
151
147
@@ -290,9 +286,6 @@ public void testComputeIfAbsentWithEvictionsFromOnHeapCache() throws Exception {
290
286
LoadAwareCacheLoader <String , String > tieredCacheLoader = getLoadAwareCacheLoader ();
291
287
tieredSpilloverCache .computeIfAbsent (key , tieredCacheLoader );
292
288
}
293
- long actualDiskCacheSize = tieredSpilloverCache .getDiskCache ().count ();
294
- assertEquals (actualDiskCacheSize , removalListener .evictionsMetric .count ()); // Evictions from onHeap equal to
295
- // disk cache size.
296
289
297
290
tieredSpilloverCache .getOnHeapCache ().keys ().forEach (onHeapKeys ::add );
298
291
tieredSpilloverCache .getDiskCache ().keys ().forEach (diskTierKeys ::add );
@@ -328,15 +321,15 @@ public void testComputeIfAbsentWithEvictionsFromOnHeapCache() throws Exception {
328
321
}
329
322
}
330
323
331
- public void testComputeIfAbsentWithEvictionsFromBothTier () throws Exception {
324
+ public void testComputeIfAbsentWithEvictionsFromTieredCache () throws Exception {
332
325
int onHeapCacheSize = randomIntBetween (10 , 30 );
333
326
int diskCacheSize = randomIntBetween (onHeapCacheSize + 1 , 100 );
334
327
int totalSize = onHeapCacheSize + diskCacheSize ;
335
328
int keyValueSize = 50 ;
336
329
337
330
MockCacheRemovalListener <String , String > removalListener = new MockCacheRemovalListener <>();
338
331
TieredSpilloverCache <String , String > tieredSpilloverCache = intializeTieredSpilloverCache (
339
- onHeapCacheSize ,
332
+ keyValueSize ,
340
333
diskCacheSize ,
341
334
removalListener ,
342
335
Settings .builder ()
@@ -349,13 +342,13 @@ public void testComputeIfAbsentWithEvictionsFromBothTier() throws Exception {
349
342
.build (),
350
343
0
351
344
);
352
-
353
345
int numOfItems = randomIntBetween (totalSize + 1 , totalSize * 3 );
354
346
for (int iter = 0 ; iter < numOfItems ; iter ++) {
355
347
LoadAwareCacheLoader <String , String > tieredCacheLoader = getLoadAwareCacheLoader ();
356
348
tieredSpilloverCache .computeIfAbsent (UUID .randomUUID ().toString (), tieredCacheLoader );
357
349
}
358
- assertTrue (removalListener .evictionsMetric .count () > 0 );
350
+ int evictions = numOfItems - (totalSize );
351
+ assertEquals (evictions , removalListener .evictionsMetric .count ());
359
352
}
360
353
361
354
public void testGetAndCount () throws Exception {
@@ -366,7 +359,7 @@ public void testGetAndCount() throws Exception {
366
359
367
360
MockCacheRemovalListener <String , String > removalListener = new MockCacheRemovalListener <>();
368
361
TieredSpilloverCache <String , String > tieredSpilloverCache = intializeTieredSpilloverCache (
369
- onHeapCacheSize ,
362
+ keyValueSize ,
370
363
diskCacheSize ,
371
364
removalListener ,
372
365
Settings .builder ()
@@ -418,7 +411,7 @@ public void testPut() {
418
411
419
412
MockCacheRemovalListener <String , String > removalListener = new MockCacheRemovalListener <>();
420
413
TieredSpilloverCache <String , String > tieredSpilloverCache = intializeTieredSpilloverCache (
421
- onHeapCacheSize ,
414
+ keyValueSize ,
422
415
diskCacheSize ,
423
416
removalListener ,
424
417
Settings .builder ()
@@ -519,7 +512,7 @@ public void testInvalidate() {
519
512
520
513
MockCacheRemovalListener <String , String > removalListener = new MockCacheRemovalListener <>();
521
514
TieredSpilloverCache <String , String > tieredSpilloverCache = intializeTieredSpilloverCache (
522
- onHeapCacheSize ,
515
+ keyValueSize ,
523
516
diskCacheSize ,
524
517
removalListener ,
525
518
Settings .builder ()
@@ -744,7 +737,7 @@ public String load(String key) {
744
737
assertEquals (1 , numberOfTimesKeyLoaded ); // It should be loaded only once.
745
738
}
746
739
747
- public void testConcurrencyForEvictionFlow () throws Exception {
740
+ public void testConcurrencyForEvictionFlowFromOnHeapToDiskTier () throws Exception {
748
741
int diskCacheSize = randomIntBetween (450 , 800 );
749
742
750
743
MockCacheRemovalListener <String , String > removalListener = new MockCacheRemovalListener <>();
@@ -828,7 +821,6 @@ public String load(String key) {
828
821
countDownLatch .await ();
829
822
assertNotNull (actualValue .get ());
830
823
countDownLatch1 .await ();
831
- assertEquals (1 , removalListener .evictionsMetric .count ());
832
824
assertEquals (1 , tieredSpilloverCache .getOnHeapCache ().count ());
833
825
assertEquals (1 , onDiskCache .count ());
834
826
assertNotNull (onDiskCache .get (keyToBeEvicted ));
@@ -883,7 +875,6 @@ private TieredSpilloverCache<String, String> intializeTieredSpilloverCache(
883
875
.build ()
884
876
)
885
877
.build ();
886
-
887
878
ICache .Factory mockDiskCacheFactory = new MockDiskCache .MockDiskCacheFactory (diskDeliberateDelay , diskCacheSize );
888
879
889
880
return new TieredSpilloverCache .Builder <String , String >().setCacheType (CacheType .INDICES_REQUEST_CACHE )
0 commit comments