remove event types
We only have removal events. The additional complexity of having a generic interface for many different event types does not pay off.
This commit is contained in:
@@ -15,7 +15,6 @@ import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import org.lucares.utils.cache.HotEntryCache.EventType;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -41,11 +40,11 @@ public class HotEntryCacheTest {
|
||||
final HotEntryCache<String, String> cache = new HotEntryCache<>(Duration.ofMillis(1), "cache-" + ++cacheId);
|
||||
HotEntryCache.setMinSleepPeriod(Duration.ofMillis(1));
|
||||
HotEntryCache.setMaxSleepPeriod(Duration.ofMillis(10));
|
||||
cache.addListener(entry -> {
|
||||
Assert.assertEquals(entry.getKey(), key);
|
||||
Assert.assertEquals(entry.getValue(), value);
|
||||
cache.addListener((k, v) -> {
|
||||
Assert.assertEquals(k, key);
|
||||
Assert.assertEquals(v, value);
|
||||
latch.countDown();
|
||||
}, EventType.EVICTED);
|
||||
});
|
||||
|
||||
cache.put(key, value);
|
||||
final boolean listenerCalled = latch.await(100, TimeUnit.MILLISECONDS);
|
||||
@@ -125,9 +124,9 @@ public class HotEntryCacheTest {
|
||||
final HotEntryCache<String, String> cache = new HotEntryCache<>(timeToLive, clock);
|
||||
|
||||
final CompletableFuture<String> evictionEventFuture = new CompletableFuture<>();
|
||||
cache.addListener(event -> {
|
||||
evictionEventFuture.complete(event.getValue());
|
||||
}, EventType.EVICTED);
|
||||
cache.addListener((key, value) -> {
|
||||
evictionEventFuture.complete(value);
|
||||
});
|
||||
|
||||
cache.put("key", "value1");
|
||||
|
||||
@@ -146,7 +145,7 @@ public class HotEntryCacheTest {
|
||||
final HotEntryCache<String, String> cache = new HotEntryCache<>(Duration.ofSeconds(10));
|
||||
|
||||
final List<String> removedValues = new ArrayList<>();
|
||||
cache.addListener(event -> removedValues.add(event.getValue()), EventType.REMOVED);
|
||||
cache.addListener((key, value) -> removedValues.add(value));
|
||||
|
||||
cache.put("key", "value1");
|
||||
|
||||
@@ -162,7 +161,7 @@ public class HotEntryCacheTest {
|
||||
final HotEntryCache<String, String> cache = new HotEntryCache<>(Duration.ofSeconds(10));
|
||||
|
||||
final List<String> removedValues = new ArrayList<>();
|
||||
cache.addListener(event -> removedValues.add(event.getValue()), EventType.REMOVED);
|
||||
cache.addListener((key, value) -> removedValues.add(value));
|
||||
|
||||
cache.put("key1", "value1");
|
||||
cache.put("key2", "value2");
|
||||
@@ -181,9 +180,9 @@ public class HotEntryCacheTest {
|
||||
final HotEntryCache<String, String> cache = new HotEntryCache<>(timeToLive, clock);
|
||||
|
||||
final CompletableFuture<String> evictionEventFuture = new CompletableFuture<>();
|
||||
cache.addListener(event -> {
|
||||
evictionEventFuture.complete(event.getValue());
|
||||
}, EventType.EVICTED);
|
||||
cache.addListener((key, value) -> {
|
||||
evictionEventFuture.complete(value);
|
||||
});
|
||||
|
||||
// add value
|
||||
cache.put("key", "value1");
|
||||
@@ -305,9 +304,9 @@ public class HotEntryCacheTest {
|
||||
final Duration timeToLive = Duration.ofSeconds(1);
|
||||
final HotEntryCache<String, String> cache = new HotEntryCache<>(timeToLive);
|
||||
|
||||
cache.addListener(event -> {
|
||||
System.out.println(Instant.now() + " evicting: " + event);
|
||||
}, EventType.EVICTED);
|
||||
cache.addListener((key, value) -> {
|
||||
System.out.println(Instant.now() + " evicting: " + key + " -> " + value);
|
||||
});
|
||||
cache.put("key", "value that is touched");
|
||||
for (int i = 0; i < 20; i++) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user