use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class MapLockTest method testLockOwnership.
@Test(expected = IllegalMonitorStateException.class)
public void testLockOwnership() throws Exception {
final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
final Config config = getConfig();
String name = randomString();
final HazelcastInstance node1 = nodeFactory.newHazelcastInstance(config);
final HazelcastInstance node2 = nodeFactory.newHazelcastInstance(config);
final IMap<Integer, Object> map1 = node1.getMap(name);
final IMap<Integer, Object> map2 = node2.getMap(name);
map1.lock(1);
map2.unlock(1);
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class EvictionTest method testMapRecordIdleEviction.
@Test
public void testMapRecordIdleEviction() throws InterruptedException {
final String mapName = randomMapName("testMapRecordIdleEviction");
final int maxIdleSeconds = 1;
final int size = 100;
Config config = getConfig();
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.setMaxIdleSeconds(maxIdleSeconds);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, Integer> map = instance.getMap(mapName);
for (int i = 0; i < size; i++) {
map.put(i, i);
}
assertSizeEventually(0, map);
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class EvictionTest method testLastAddedKey_canBeEvicted_whenFreeHeapNeeded.
/**
* Eviction of last added key can only be triggered with one of heap based max-size-policies.
*/
@Test
public void testLastAddedKey_canBeEvicted_whenFreeHeapNeeded() {
// don't use getConfig(), this test is OSS specific
Config config = new Config();
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
config.getMapConfig("test").setEvictionPolicy(LFU).getMaxSizeConfig().setSize(90).setMaxSizePolicy(FREE_HEAP_PERCENTAGE);
HazelcastInstance node = createHazelcastInstance(config);
IMap<Integer, Integer> map = node.getMap("test");
final AtomicReference<Integer> evictedKey = new AtomicReference<Integer>(null);
map.addEntryListener(new EntryEvictedListener<Integer, Integer>() {
@Override
public void entryEvicted(EntryEvent<Integer, Integer> event) {
evictedKey.set(event.getKey());
}
}, false);
// 1. Make available free-heap-percentage 10. availableFree = maxMemoryMB - (totalMemoryMB - freeMemoryMB)
// free-heap-percentage = availableFree/maxMemoryMB;
int totalMemoryMB = 90;
int freeMemoryMB = 0;
int maxMemoryMB = 100;
setMockRuntimeMemoryInfoAccessor(map, totalMemoryMB, freeMemoryMB, maxMemoryMB);
// 2. This `put` should trigger eviction because we used 90% heap already.
// And max used-heap-percentage was set 10% in map-config.
map.put(1, 1);
final Integer expected = 1;
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Eviction impl. should evict latest added key when heap based max-size-policy is used", expected, evictedKey.get());
}
});
}
use of com.hazelcast.config.Config 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);
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class ExpirationListenerTest method init.
@Before
public void init() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(instanceCount);
Config config = new Config();
instances = factory.newInstances(config);
HazelcastInstance node = getInstance();
map = node.getMap(randomMapName());
}
Aggregations