Skip to content

Commit

Permalink
Added convenience fns to set up for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Alfonsi committed Oct 19, 2023
1 parent 83d1063 commit 85890e1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,15 @@ long count() {
return tieredCacheService.count();
}

long count(TierType tierType) {
return tieredCacheService.count(tierType);
}

int numRegisteredCloseListeners() { // for testing
return registeredClosedListeners.size();
}

/*public void closeDiskTier() {
tieredCacheHandler.closeDiskTier();
}*/
public void closeDiskTier() {
tieredCacheService.closeDiskTier();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public interface TieredCacheService<K, V> {

long count();

long count(TierType tierType);

OnHeapCachingTier<K, V> getOnHeapCachingTier();

Optional<DiskCachingTier<K, V>> getDiskCachingTier();

void closeDiskTier();
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ public long count() {
return totalCount;
}

@Override
public long count(TierType tierType) {
for (CachingTier<K, V> cachingTier : cachingTierList) {
if (cachingTier.getTierType() == tierType) {
return cachingTier.count();
}
}
return -1L;
}

/**
* Called whenever an item is evicted from any cache tier. If the item was evicted from onHeap cache, it is moved
* to disk tier cache. In case it was evicted from disk tier cache, it will discarded.
Expand Down Expand Up @@ -165,6 +175,15 @@ private void setRemovalListeners() {
}
}

/**
* Close the ehcache disk tier, if there is one.
*/
public void closeDiskTier() {
if (diskCachingTier.isPresent()) {
diskCachingTier.get().close();
}
}

private Function<K, CacheValue<V>> getValueFromTierCache(boolean trackStats) {
return key -> {
for (CachingTier<K, V> cachingTier : cachingTierList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,8 @@ public void testEhcacheConcurrency() throws Exception {
assertNotNull(value);
}

//System.out.println("heap size " + cache.count(TierType.ON_HEAP));
//System.out.println("disk size " + cache.count(TierType.DISK));
System.out.println("heap size " + cache.count(TierType.ON_HEAP));
System.out.println("disk size " + cache.count(TierType.DISK));
System.out.println("disk misses " + requestCacheStats.stats(TierType.DISK).getMissCount());
System.out.println("disk hits " + requestCacheStats.stats(TierType.DISK).getHitCount());
/*System.out.println("disk num gets " + cache.tieredCacheHandler.getDiskCachingTier().numGets);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,5 +454,15 @@ public TierType getTierType() {
public void onRemoval(RemovalNotification<K, V> notification) {
this.removalListener.onRemoval(notification);
}

@Override
public double getTimeMillisEWMA() {
return 0.0;
}

@Override
public void close() {

}
}
}

0 comments on commit 85890e1

Please sign in to comment.