Search in sources :

Example 11 with MaxSizeConfig

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

the class MapMaxSizeConfigTest method setMaxSize_withConstructor_toPositive.

@Test
public void setMaxSize_withConstructor_toPositive() throws Exception {
    final int expectedMaxSize = 123456;
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig(expectedMaxSize, MaxSizeConfig.MaxSizePolicy.PER_NODE);
    assertEquals(expectedMaxSize, 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 12 with MaxSizeConfig

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

the class EvictionTest method testEvictionLFUInternal.

/**
     * This test is only testing occurrence of LFU eviction.
     */
protected void testEvictionLFUInternal(boolean disableStats) {
    int mapMaxSize = 10000;
    String mapName = randomMapName();
    MaxSizeConfig msc = new MaxSizeConfig();
    msc.setMaxSizePolicy(PER_NODE);
    msc.setSize(mapMaxSize);
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setStatisticsEnabled(disableStats);
    mapConfig.setEvictionPolicy(LFU);
    mapConfig.setMinEvictionCheckMillis(0);
    mapConfig.setMaxSizeConfig(msc);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap<Object, Object> map = node.getMap(mapName);
    for (int i = 0; i < 2 * mapMaxSize; i++) {
        map.put(i, i);
    }
    int mapSize = map.size();
    assertTrue("Eviction did not work, map size " + mapSize + " should be smaller than allowed max size = " + mapMaxSize, mapSize < mapMaxSize);
}
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)

Example 13 with MaxSizeConfig

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

the class MapStoreEvictionTest method newConfig.

private Config newConfig(String mapName, boolean sizeLimited, MapStoreConfig.InitialLoadMode loadMode) {
    Config cfg = new Config();
    cfg.setGroupConfig(new GroupConfig(getClass().getSimpleName()));
    cfg.setProperty("hazelcast.partition.count", "5");
    MapStoreConfig mapStoreConfig = new MapStoreConfig().setImplementation(loader).setInitialLoadMode(loadMode);
    MapConfig mapConfig = cfg.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);
    if (sizeLimited) {
        MaxSizeConfig maxSizeConfig = new MaxSizeConfig(MAX_SIZE_PER_NODE, MaxSizeConfig.MaxSizePolicy.PER_NODE);
        mapConfig.setMaxSizeConfig(maxSizeConfig);
        mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
        mapConfig.setMinEvictionCheckMillis(0);
    }
    return cfg;
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) GroupConfig(com.hazelcast.config.GroupConfig) Config(com.hazelcast.config.Config) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) GroupConfig(com.hazelcast.config.GroupConfig) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapConfig(com.hazelcast.config.MapConfig)

Example 14 with MaxSizeConfig

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

the class PluggableMemoryInfoAccessorTest method testPluggedMemoryInfoAccessorUsed.

/**
     * Used {@link ZeroMemoryInfoAccessor} to evict every put, map should not contain any entry after this test run.
     */
@Test
public void testPluggedMemoryInfoAccessorUsed() throws Exception {
    MaxSizeConfig maxSizeConfig = new MaxSizeConfig();
    maxSizeConfig.setMaxSizePolicy(FREE_HEAP_PERCENTAGE);
    maxSizeConfig.setSize(50);
    Config config = getConfig();
    config.getMapConfig("test").setEvictionPolicy(LFU).setMaxSizeConfig(maxSizeConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IMap map = node.getMap("test");
    for (int i = 0; i < 1000; i++) {
        map.put(i, i);
    }
    assertEquals(0, map.size());
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) IMap(com.hazelcast.core.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with MaxSizeConfig

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

the class HazelcastTicketRegistryConfiguration method createMapConfig.

private MapConfig createMapConfig(final TicketDefinition definition) {
    final HazelcastProperties hz = casProperties.getTicket().getRegistry().getHazelcast();
    final HazelcastProperties.Cluster cluster = hz.getCluster();
    final EvictionPolicy evictionPolicy = EvictionPolicy.valueOf(cluster.getEvictionPolicy());
    LOGGER.debug("Creating Hazelcast map configuration for [{}] with idle timeout [{}] second(s)", definition.getProperties().getStorageName(), definition.getProperties().getStorageTimeout());
    return new MapConfig().setName(definition.getProperties().getStorageName()).setMaxIdleSeconds((int) definition.getProperties().getStorageTimeout()).setBackupCount(cluster.getBackupCount()).setAsyncBackupCount(cluster.getAsyncBackupCount()).setEvictionPolicy(evictionPolicy).setMaxSizeConfig(new MaxSizeConfig().setMaxSizePolicy(MaxSizeConfig.MaxSizePolicy.valueOf(cluster.getMaxSizePolicy())).setSize(cluster.getMaxHeapSizePercentage()));
}
Also used : HazelcastProperties(org.apereo.cas.configuration.model.support.hazelcast.HazelcastProperties) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) EvictionPolicy(com.hazelcast.config.EvictionPolicy) 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