Search in sources :

Example 91 with MapConfig

use of com.hazelcast.config.MapConfig 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)

Example 92 with MapConfig

use of com.hazelcast.config.MapConfig 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 93 with MapConfig

use of com.hazelcast.config.MapConfig 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 94 with MapConfig

use of com.hazelcast.config.MapConfig 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 95 with MapConfig

use of com.hazelcast.config.MapConfig 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)

Aggregations

MapConfig (com.hazelcast.config.MapConfig)178 Config (com.hazelcast.config.Config)123 HazelcastInstance (com.hazelcast.core.HazelcastInstance)78 Test (org.junit.Test)75 QuickTest (com.hazelcast.test.annotation.QuickTest)68 ParallelTest (com.hazelcast.test.annotation.ParallelTest)62 MapStoreConfig (com.hazelcast.config.MapStoreConfig)43 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)41 NearCacheConfig (com.hazelcast.config.NearCacheConfig)27 MaxSizeConfig (com.hazelcast.config.MaxSizeConfig)26 MapIndexConfig (com.hazelcast.config.MapIndexConfig)20 QuorumConfig (com.hazelcast.config.QuorumConfig)19 EntryListenerConfig (com.hazelcast.config.EntryListenerConfig)18 QueryCacheConfig (com.hazelcast.config.QueryCacheConfig)16 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)14 NightlyTest (com.hazelcast.test.annotation.NightlyTest)12 PartitionedCluster (com.hazelcast.quorum.PartitionedCluster)10 CountDownLatch (java.util.concurrent.CountDownLatch)10 BeforeClass (org.junit.BeforeClass)10 AssertTask (com.hazelcast.test.AssertTask)9