Search in sources :

Example 6 with MaxSizeConfig

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

the class EvictionTest method testEvictionLRU_statisticsDisabled.

@Test
public void testEvictionLRU_statisticsDisabled() {
    final int nodeCount = 2;
    final int size = 100000;
    final String mapName = randomMapName("_testEvictionLRU_statisticsDisabled_");
    Config cfg = getConfig();
    cfg.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
    MapConfig mc = cfg.getMapConfig(mapName);
    mc.setStatisticsEnabled(false);
    mc.setEvictionPolicy(EvictionPolicy.LRU);
    mc.setEvictionPercentage(10);
    MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_NODE);
    msc.setSize(size);
    mc.setMaxSizeConfig(msc);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = factory.newInstances(cfg);
    IMap<Object, Object> map = instances[0].getMap(mapName);
    for (int i = 0; i < size; i++) {
        map.put(i, i);
        if (i < size / 2) {
            map.get(i);
        }
    }
    // give some time to eviction thread run.
    sleepSeconds(3);
    int recentlyUsedEvicted = 0;
    for (int i = 0; i < size / 2; i++) {
        if (map.get(i) == null) {
            recentlyUsedEvicted++;
        }
    }
    assertEquals(0, recentlyUsedEvicted);
}
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) 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 7 with MaxSizeConfig

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

the class EvictionTest method testEvictionSpeedTest.

// current eviction check period is 1 second.
// about 30000 records can be put in one second, so the size should be adapted
@Test
public void testEvictionSpeedTest() throws InterruptedException {
    final int k = 3;
    final int size = 10000;
    final CountDownLatch latch = new CountDownLatch(k);
    final String mapName = "testEvictionSpeedTest";
    Config config = getConfig();
    final MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setEvictionPercentage(25);
    final MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.PER_NODE);
    maxSizeConfig.setSize(size);
    mapConfig.setMaxSizeConfig(maxSizeConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
    final HazelcastInstance[] instances = factory.newInstances(config);
    final AtomicBoolean success = new AtomicBoolean(true);
    new Thread() {

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

        public void run() {
            try {
                Thread.sleep(1000);
                while (latch.getCount() != 0) {
                    try {
                        int mapSize = map.size();
                        if (mapSize > (size * k + size * k * 10 / 100)) {
                            success.set(false);
                            break;
                        }
                        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 < size; j++) {
                    map.put(k + "-" + j, j);
                }
                latch.countDown();
            }
        }.start();
    }
    assertTrue(latch.await(10, TimeUnit.MINUTES));
    assertTrue(success.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 8 with MaxSizeConfig

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

the class EvictionMaxSizePolicyTest method createConfig.

Config createConfig(MaxSizeConfig.MaxSizePolicy maxSizePolicy, int maxSize, String mapName) {
    Config config = getConfig();
    config.setProperty(GroupProperty.PARTITION_COUNT.getName(), String.valueOf(PARTITION_COUNT));
    MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(maxSizePolicy);
    msc.setSize(maxSize);
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
    mapConfig.setEvictionPercentage(25);
    mapConfig.setMaxSizeConfig(msc);
    mapConfig.setMinEvictionCheckMillis(0L);
    return config;
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig)

Example 9 with MaxSizeConfig

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

the class MapMaxSizeConfigTest method setMaxSize_withConstructor_toZero.

@Test
public void setMaxSize_withConstructor_toZero() throws Exception {
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig(0, MaxSizeConfig.MaxSizePolicy.PER_NODE);
    assertEquals(Integer.MAX_VALUE, maxSizeConfig.getSize());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 10 with MaxSizeConfig

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

the class MapMaxSizeConfigTest method setMaxSize_withConstructor_toNegative.

@Test
public void setMaxSize_withConstructor_toNegative() throws Exception {
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig(-2131, MaxSizeConfig.MaxSizePolicy.PER_NODE);
    assertEquals(Integer.MAX_VALUE, maxSizeConfig.getSize());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

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