use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class ListenerTest method updates_with_putTransient_triggers_entryUpdatedListener.
@Test
public void updates_with_putTransient_triggers_entryUpdatedListener() throws Exception {
HazelcastInstance hz = createHazelcastInstance(getConfig());
IMap<String, String> map = hz.getMap("updates_with_putTransient_triggers_entryUpdatedListener");
final CountDownLatch updateEventCounterLatch = new CountDownLatch(1);
map.addEntryListener(new EntryUpdatedListener<String, String>() {
@Override
public void entryUpdated(EntryEvent<String, String> event) {
updateEventCounterLatch.countDown();
}
}, true);
map.putTransient("hello", "world", 0, TimeUnit.SECONDS);
map.putTransient("hello", "another world", 0, TimeUnit.SECONDS);
assertOpenEventually(updateEventCounterLatch);
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class ListenerTest method testEntryListenerEvent_withMapReplaceFail.
@Test
public void testEntryListenerEvent_withMapReplaceFail() throws Exception {
HazelcastInstance instance = createHazelcastInstance(getConfig());
final IMap<Integer, Object> map = instance.getMap(randomString());
final CounterEntryListener listener = new CounterEntryListener();
map.addEntryListener(listener, true);
final int putTotal = 1000;
final int oldVal = 1;
for (int i = 0; i < putTotal; i++) {
map.put(i, oldVal);
}
final int replaceTotal = 1000;
final int newVal = 2;
for (int i = 0; i < replaceTotal; i++) {
map.replace(i, "WrongValue", newVal);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
for (int i = 0; i < replaceTotal; i++) {
assertEquals(oldVal, map.get(i));
}
assertEquals(putTotal, listener.addCount.get());
assertEquals(0, listener.updateCount.get());
}
});
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class ListenerTest method hazelcastAwareEntryListener_injectHazelcastInstance.
private void hazelcastAwareEntryListener_injectHazelcastInstance(EntryListenerConfig listenerConfig) {
String pingMapName = randomMapName();
Config config = getConfig();
config.getMapConfig(pingMapName).getEntryListenerConfigs().add(listenerConfig);
HazelcastInstance instance = createHazelcastInstance(config);
IMap<Integer, String> pingMap = instance.getMap(pingMapName);
String pongMapName = randomMapName();
pingMap.put(0, pongMapName);
IMap<Integer, String> outputMap = instance.getMap(pongMapName);
assertSizeEventually(1, outputMap);
}
use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.
the class EvictionTest method testEvictionPerPartition.
@Test
public void testEvictionPerPartition() throws InterruptedException {
final int k = 2;
final int size = 10;
final String mapName = "testEvictionPerPartition";
Config cfg = getConfig();
cfg.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
final MapConfig mc = cfg.getMapConfig(mapName);
mc.setEvictionPolicy(EvictionPolicy.LRU);
mc.setEvictionPercentage(50);
mc.setMinEvictionCheckMillis(0);
final MaxSizeConfig msc = new MaxSizeConfig();
msc.setMaxSizePolicy(PER_PARTITION);
msc.setSize(size);
mc.setMaxSizeConfig(msc);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(k);
final HazelcastInstance[] instances = factory.newInstances(cfg);
final int pNum = instances[0].getPartitionService().getPartitions().size();
int insertCount = size * pNum * 2;
final Map<Integer, Integer> map = instances[0].getMap(mapName);
for (int i = 0; i < insertCount; i++) {
map.put(i, i);
}
int mapSize = map.size();
String message = format("mapSize : %d should be <= max-size : %d ", mapSize, size);
assertTrue(message, mapSize <= size);
}
use of com.hazelcast.core.HazelcastInstance 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);
}
Aggregations