Search in sources :

Example 1 with PER_PARTITION

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);
    }
}
Also used : Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) PARTITION_COUNT(com.hazelcast.spi.properties.ClusterProperty.PARTITION_COUNT) Assert.assertNotNull(org.junit.Assert.assertNotNull) HazelcastTestSupport(com.hazelcast.test.HazelcastTestSupport) RunWith(org.junit.runner.RunWith) EntryView(com.hazelcast.core.EntryView) Test(org.junit.Test) MapEvictionPolicyComparator(com.hazelcast.map.MapEvictionPolicyComparator) Category(org.junit.experimental.categories.Category) PER_PARTITION(com.hazelcast.config.MaxSizePolicy.PER_PARTITION) String.format(java.lang.String.format) CountDownLatch(java.util.concurrent.CountDownLatch) SAMPLE_COUNT(com.hazelcast.map.impl.eviction.Evictor.SAMPLE_COUNT) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Assert.assertFalse(org.junit.Assert.assertFalse) HazelcastParallelClassRunner(com.hazelcast.test.HazelcastParallelClassRunner) EntryEvictedListener(com.hazelcast.map.listener.EntryEvictedListener) Queue(java.util.Queue) IMap(com.hazelcast.map.IMap) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Config (com.hazelcast.config.Config)1 PER_PARTITION (com.hazelcast.config.MaxSizePolicy.PER_PARTITION)1 EntryView (com.hazelcast.core.EntryView)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1 IMap (com.hazelcast.map.IMap)1 MapEvictionPolicyComparator (com.hazelcast.map.MapEvictionPolicyComparator)1 SAMPLE_COUNT (com.hazelcast.map.impl.eviction.Evictor.SAMPLE_COUNT)1 EntryEvictedListener (com.hazelcast.map.listener.EntryEvictedListener)1 PARTITION_COUNT (com.hazelcast.spi.properties.ClusterProperty.PARTITION_COUNT)1 HazelcastParallelClassRunner (com.hazelcast.test.HazelcastParallelClassRunner)1 HazelcastTestSupport (com.hazelcast.test.HazelcastTestSupport)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 String.format (java.lang.String.format)1 Queue (java.util.Queue)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TestCase.assertTrue (junit.framework.TestCase.assertTrue)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1