use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class NearCacheTest method testMapClear_clearsLocalNearCache.
@Test
public void testMapClear_clearsLocalNearCache() {
int size = 1000;
final String mapName = randomMapName();
Config config = createNearCachedMapConfig(mapName);
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
final HazelcastInstance instance1 = factory.newHazelcastInstance(config);
final HazelcastInstance instance2 = factory.newHazelcastInstance(config);
final HazelcastInstance instance3 = factory.newHazelcastInstance(config);
IMap<Integer, Integer> map = instance1.getMap(mapName);
populateMap(map, size);
populateNearCache(map, size);
map.clear();
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, getNearCacheSize(instance1.getMap(mapName)));
assertEquals(0, getNearCacheSize(instance2.getMap(mapName)));
assertEquals(0, getNearCacheSize(instance3.getMap(mapName)));
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class NearCacheLiteMemberTest method assertNullNearCacheEntryEventually.
private static void assertNullNearCacheEntryEventually(final HazelcastInstance instance, String mapName, Object key) {
final NearCache<Object, Object> nearCache = getNearCache(instance, mapName);
final Data keyData = toData(instance, key);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertNull(toObject(instance, nearCache.get(keyData)));
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class QueryAdvancedTest method testQueryAfterInitialLoad.
// issue 1404 "to be fixed by issue 1404"
@Test
public void testQueryAfterInitialLoad() {
final int size = 100;
String name = "default";
Config config = getConfig();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(new MapStoreAdapter<Integer, Employee>() {
@Override
public Map<Integer, Employee> loadAll(Collection<Integer> keys) {
Map<Integer, Employee> map = new HashMap<Integer, Employee>();
for (Integer key : keys) {
Employee emp = new Employee();
emp.setActive(true);
map.put(key, emp);
}
return map;
}
@Override
public Set<Integer> loadAllKeys() {
Set<Integer> set = new HashSet<Integer>();
for (int i = 0; i < size; i++) {
set.add(i);
}
return set;
}
});
config.getMapConfig(name).setMapStoreConfig(mapStoreConfig);
HazelcastInstance instance = createHazelcastInstance(config);
final IMap map = instance.getMap(name);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Collection values = map.values(new SqlPredicate("active = true"));
assertEquals(size, values.size());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MultiMapListenerTest method testListeners.
@Test
public void testListeners() throws Exception {
int count = 4;
String name = randomMapName();
Config config = new Config();
config.getMultiMapConfig(name).setValueCollectionType(MultiMapConfig.ValueCollectionType.LIST);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(count);
HazelcastInstance[] instances = factory.newInstances(config);
final Set<String> keys = Collections.newSetFromMap(new ConcurrentHashMap<String, Boolean>());
EntryListener<String, String> listener = new EntryAdapter<String, String>() {
public void entryAdded(EntryEvent<String, String> event) {
keys.add(event.getKey());
}
public void entryRemoved(EntryEvent<String, String> event) {
keys.remove(event.getKey());
}
@Override
public void mapCleared(MapEvent event) {
keys.clear();
}
};
final MultiMap<String, String> multiMap = instances[0].getMultiMap(name);
final String id = multiMap.addLocalEntryListener(listener);
multiMap.put("key1", "val1");
multiMap.put("key2", "val2");
multiMap.put("key3", "val3");
multiMap.put("key4", "val4");
multiMap.put("key5", "val5");
multiMap.put("key6", "val6");
multiMap.put("key7", "val7");
multiMap.put("key8", "val8");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertContainsAll(multiMap.localKeySet(), keys);
}
});
if (keys.size() != 0) {
multiMap.remove(keys.iterator().next());
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertContainsAll(multiMap.localKeySet(), keys);
}
});
multiMap.removeEntryListener(id);
getMultiMap(instances, name).clear();
keys.clear();
final String id2 = multiMap.addEntryListener(listener, true);
getMultiMap(instances, name).put("key3", "val3");
getMultiMap(instances, name).put("key3", "val33");
getMultiMap(instances, name).put("key4", "val4");
getMultiMap(instances, name).remove("key3", "val33");
assertSizeEventually(1, keys);
getMultiMap(instances, name).clear();
assertSizeEventually(0, keys);
multiMap.removeEntryListener(id2);
multiMap.addEntryListener(listener, "key7", true);
getMultiMap(instances, name).put("key2", "val2");
getMultiMap(instances, name).put("key3", "val3");
getMultiMap(instances, name).put("key7", "val7");
assertSizeEventually(1, keys);
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class TxnMultiMapTest method testListener.
@Test
public void testListener() throws InterruptedException {
String mapName = "mm";
long key = 1L;
String value = "value";
String value2 = "value2";
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance();
HazelcastInstance instance2 = factory.newHazelcastInstance();
final CountingEntryListener<Object, Object> listener = new CountingEntryListener<Object, Object>();
MultiMap<Object, Object> map = instance1.getMultiMap(mapName);
map.addEntryListener(listener, true);
TransactionContext ctx1 = instance2.newTransactionContext();
ctx1.beginTransaction();
ctx1.getMultiMap(mapName).put(key, value);
ctx1.commitTransaction();
TransactionContext ctx2 = instance2.newTransactionContext();
ctx2.beginTransaction();
ctx2.getMultiMap(mapName).remove(key, value);
ctx2.commitTransaction();
TransactionContext ctx3 = instance2.newTransactionContext();
ctx3.beginTransaction();
ctx3.getMultiMap(mapName).put(key, value2);
ctx3.commitTransaction();
TransactionContext ctx4 = instance1.newTransactionContext();
ctx4.beginTransaction();
ctx4.getMultiMap(mapName).remove(key, value2);
ctx4.commitTransaction();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(2, listener.getAddedCount());
assertEquals(2, listener.getRemovedCount());
}
});
}
Aggregations