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