Search in sources :

Example 16 with MaxSizeConfig

use of com.hazelcast.config.MaxSizeConfig in project hazelcast by hazelcast.

the class EventPublishOrderWithEvictionTest method createMap.

private <K, V> IMap<K, V> createMap(int maxSize) {
    String mapName = randomMapName();
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setSize(maxSize);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    mapConfig.setMinEvictionCheckMillis(0);
    return createHazelcastInstance(config).getMap(mapName);
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) Config(com.hazelcast.config.Config) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 17 with MaxSizeConfig

use of com.hazelcast.config.MaxSizeConfig in project hazelcast by hazelcast.

the class EvictionTest method testEvictionSpeedTestPerPartition.

@Test
public void testEvictionSpeedTestPerPartition() throws InterruptedException {
    final int k = 2;
    final int size = 100;
    final CountDownLatch latch = new CountDownLatch(k);
    final String mapName = "testEvictionSpeedTestPerPartition";
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setEvictionPercentage(25);
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setMaxSizePolicy(PER_PARTITION);
    maxSizeConfig.setSize(size);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
    final HazelcastInstance[] instances = factory.newInstances(config);
    final int pNum = instances[0].getPartitionService().getPartitions().size();
    final AtomicBoolean error = new AtomicBoolean(false);
    new Thread() {

        final IMap map = instances[0].getMap(mapName);

        public void run() {
            try {
                Thread.sleep(1000);
                while (latch.getCount() != 0) {
                    try {
                        int msize = map.size();
                        if (msize > (size * pNum * 1.2)) {
                            error.set(true);
                        }
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }.start();
    for (int i = 0; i < k; i++) {
        final IMap<String, Integer> map = instances[i].getMap(mapName);
        new Thread() {

            public void run() {
                for (int j = 0; j < 10000; j++) {
                    map.put(k + "-" + j, j);
                }
                latch.countDown();
            }
        }.start();
    }
    assertOpenEventually(latch);
    assertFalse("map was not evicted properly!", error.get());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) CountDownLatch(java.util.concurrent.CountDownLatch) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with MaxSizeConfig

use of com.hazelcast.config.MaxSizeConfig in project hazelcast by hazelcast.

the class EvictionTest method testEvictionLFU2.

@Test
public void testEvictionLFU2() {
    final int size = 10000;
    final String mapName = randomMapName("testEvictionLFU2");
    Config cfg = getConfig();
    cfg.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    MapConfig mc = cfg.getMapConfig(mapName);
    mc.setEvictionPolicy(EvictionPolicy.LFU);
    mc.setEvictionPercentage(90);
    MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_NODE);
    msc.setSize(size);
    mc.setMaxSizeConfig(msc);
    HazelcastInstance node = createHazelcastInstance();
    IMap<Object, Object> map = node.getMap(mapName);
    for (int i = 0; i < size; i++) {
        map.put(i, i);
        if (i < 100 || i >= size - 100) {
            map.get(i);
        }
    }
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 100; j++) {
            assertNotNull(map.get(j));
        }
        for (int j = size - 100; j < size; j++) {
            assertNotNull(map.get(j));
        }
    }
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 19 with MaxSizeConfig

use of com.hazelcast.config.MaxSizeConfig in project hazelcast by hazelcast.

the class EvictionTest method newConfig.

private Config newConfig(String mapName, int maxSize, MaxSizeConfig.MaxSizePolicy maxSizePolicy) {
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName + "*");
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig(maxSize, maxSizePolicy);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setMinEvictionCheckMillis(0);
    config.addMapConfig(mapConfig);
    return config;
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) NearCacheConfig(com.hazelcast.config.NearCacheConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 20 with MaxSizeConfig

use of com.hazelcast.config.MaxSizeConfig in project hazelcast by hazelcast.

the class DynamicMapConfigTest method createMapConfig.

private MapConfig createMapConfig() {
    MapConfig mapConfig = new MapConfig();
    mapConfig.setTimeToLiveSeconds(100);
    mapConfig.setMaxIdleSeconds(22);
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setEvictionPercentage(35);
    mapConfig.setMinEvictionCheckMillis(199);
    mapConfig.setReadBackupData(false);
    mapConfig.setBackupCount(3);
    mapConfig.setAsyncBackupCount(2);
    mapConfig.setMaxSizeConfig(new MaxSizeConfig(111, MaxSizeConfig.MaxSizePolicy.FREE_HEAP_SIZE));
    return mapConfig;
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig)

Aggregations

MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)26 MapConfig (com.hazelcast.config.MapConfig)18 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 Config (com.hazelcast.config.Config)13 ParallelTest (com.hazelcast.test.annotation.ParallelTest)13 HazelcastInstance (com.hazelcast.core.HazelcastInstance)9 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)7 NearCacheConfig (com.hazelcast.config.NearCacheConfig)7 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)5 NightlyTest (com.hazelcast.test.annotation.NightlyTest)5 IMap (com.hazelcast.core.IMap)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 MapStoreConfig (com.hazelcast.config.MapStoreConfig)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 EvictionPolicy (com.hazelcast.config.EvictionPolicy)1 GroupConfig (com.hazelcast.config.GroupConfig)1 MapIndexConfig (com.hazelcast.config.MapIndexConfig)1 MultiMapConfig (com.hazelcast.config.MultiMapConfig)1