use of com.hazelcast.config.MaxSizePolicy.PER_PARTITION in project hazelcast by hazelcast.
the class CustomEvictionPolicyComparatorTest method custom_eviction_policy_removes_correct_entries.
@Test
public void custom_eviction_policy_removes_correct_entries() {
int sampleCount = SAMPLE_COUNT;
Config config = getConfig();
config.setProperty(PARTITION_COUNT.getName(), "1");
config.getMapConfig(mapName).getEvictionConfig().setComparator(new OddEvictor()).setMaxSizePolicy(PER_PARTITION).setSize(sampleCount);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, Integer> map = instance.getMap(mapName);
final CountDownLatch eventLatch = new CountDownLatch(1);
final Queue<Integer> evictedKeys = new ConcurrentLinkedQueue<>();
map.addEntryListener((EntryEvictedListener<Integer, Integer>) event -> {
evictedKeys.add(event.getKey());
eventLatch.countDown();
}, false);
for (int i = 0; i < sampleCount + 1; i++) {
map.put(i, i);
}
assertOpenEventually("No eviction occurred", eventLatch);
for (Integer key : evictedKeys) {
assertTrue(format("Evicted key should be an odd number, but found %d", key), key % 2 != 0);
}
}
Aggregations