use of com.hazelcast.test.AssertTask 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.test.AssertTask in project hazelcast by hazelcast.
the class LocalMapStatsTest method testPutAsync.
@Test
public void testPutAsync() throws Exception {
IMap<Integer, Integer> map = getMap();
for (int i = 0; i < 100; i++) {
map.putAsync(i, i);
}
final LocalMapStats localMapStats = map.getLocalMapStats();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(100, localMapStats.getPutOperationCount());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class LocalMapStatsTest method testRemoveAsync.
@Test
public void testRemoveAsync() throws Exception {
IMap<Integer, Integer> map = getMap();
for (int i = 0; i < 100; i++) {
map.put(i, i);
map.removeAsync(i);
}
final LocalMapStats localMapStats = map.getLocalMapStats();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(100, localMapStats.getRemoveOperationCount());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class LocalMapStatsTest method testHitsGenerated_updatedConcurrently.
@Test
public void testHitsGenerated_updatedConcurrently() throws Exception {
final IMap<Integer, Integer> map = getMap();
final int actionCount = 100;
for (int i = 0; i < actionCount; i++) {
map.put(i, i);
map.get(i);
}
final LocalMapStats localMapStats = map.getLocalMapStats();
final long initialHits = localMapStats.getHits();
new Thread(new Runnable() {
@Override
public void run() {
for (int i = 0; i < actionCount; i++) {
map.get(i);
}
// causes the local stats object to update
map.getLocalMapStats();
}
}).start();
assertEquals(actionCount, initialHits);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(actionCount * 2, localMapStats.getHits());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class QueryAdvancedTest method testMapWithIndexAfterShutDown.
@Test
public void testMapWithIndexAfterShutDown() {
Config config = getConfig();
String mapName = "default";
config.getMapConfig(mapName).addMapIndexConfig(new MapIndexConfig("typeName", false));
HazelcastInstance[] instances = createHazelcastInstanceFactory(3).newInstances(config);
final IMap<Integer, ValueType> map = instances[0].getMap(mapName);
final int sampleSize1 = 100;
final int sampleSize2 = 30;
int totalSize = sampleSize1 + sampleSize2;
for (int i = 0; i < sampleSize1; i++) {
map.put(i, new ValueType("type" + i));
}
for (int i = sampleSize1; i < totalSize; i++) {
map.put(i, new ValueType("typex"));
}
Collection typexValues = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, typexValues.size());
instances[1].shutdown();
assertEquals(totalSize, map.size());
assertTrueEventually(new AssertTask() {
public void run() {
final Collection values = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, values.size());
}
});
instances[2].shutdown();
assertEquals(totalSize, map.size());
assertTrueEventually(new AssertTask() {
public void run() {
final Collection values = map.values(new SqlPredicate("typeName = typex"));
assertEquals(sampleSize2, values.size());
}
});
}
Aggregations