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()));
}
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);
}
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());
}
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));
}
}
}
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;
}
Aggregations