use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class NearCacheBatchInvalidationTest method testBatchInvalidationRemovesEntries.
@Test
public void testBatchInvalidationRemovesEntries() throws Exception {
String mapName = randomMapName();
Config config = newConfig(mapName);
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
configureBatching(config, true, 12, 1);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance node1 = factory.newHazelcastInstance(config);
HazelcastInstance node2 = factory.newHazelcastInstance(config);
final IMap<Integer, Integer> map1 = node1.getMap(mapName);
final IMap<Integer, Integer> map2 = node2.getMap(mapName);
int size = 1000;
// fill map-1
for (int i = 0; i < size; i++) {
map1.put(i, i);
}
// fill Near Cache on node-1
for (int i = 0; i < size; i++) {
map1.get(i);
}
// fill Near Cache on node-2
for (int i = 0; i < size; i++) {
map2.get(i);
}
// generate invalidation data
for (int i = 0; i < size; i++) {
map1.put(i, i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
NearCache nearCache1 = ((NearCachedMapProxyImpl) map1).getNearCache();
NearCache nearCache2 = ((NearCachedMapProxyImpl) map2).getNearCache();
assertEquals(0, nearCache1.size() + nearCache2.size());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class NearCacheLiteMemberTest method testPutAll.
public static void testPutAll(HazelcastInstance instance, HazelcastInstance lite, String mapName) {
IMap<Object, Object> map = instance.getMap(mapName);
IMap<Object, Object> liteMap = lite.getMap(mapName);
NearCachedMapProxyImpl proxy = (NearCachedMapProxyImpl) liteMap;
NearCache liteNearCache = proxy.getNearCache();
SerializationService serializationService = ((SerializationServiceSupport) instance).getSerializationService();
int count = 100;
// fill the near cache with the same data as below so we can detect when it is emptied
for (int i = 0; i < count; i++) {
liteNearCache.put(serializationService.toData(i), i);
}
final NearCacheStats stats = liteNearCache.getNearCacheStats();
assertEquals(100, stats.getOwnedEntryCount());
Map<Object, Object> localMap = new HashMap<Object, Object>();
for (int i = 0; i < count; i++) {
localMap.put(i, i);
}
map.putAll(localMap);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(0, stats.getOwnedEntryCount());
}
});
for (int i = 0; i < count; i++) {
liteMap.get(i);
}
assertLiteMemberNearCacheNonEmpty(lite, mapName);
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class PostJoinMapOperationTest method testPostJoinMapOperation_mapWithIndex.
// This test is meant to verify that a query will be executed *with an index* on the joining node
// See also QueryIndexMigrationTest, which tests that results are as expected.
@Test
public void testPostJoinMapOperation_mapWithIndex() throws InterruptedException {
TestHazelcastInstanceFactory hzFactory = createHazelcastInstanceFactory(2);
// given: a map with index on a single-node HazelcastInstance
HazelcastInstance hz1 = hzFactory.newHazelcastInstance();
IMap<String, Person> map = hz1.getMap("map");
map.put("foo", new Person("foo", 32));
map.put("bar", new Person("bar", 70));
map.addIndex("age", true);
// when: new node joins and original node is terminated
HazelcastInstance hz2 = hzFactory.newHazelcastInstance();
waitAllForSafeState(hz1, hz2);
hzFactory.terminate(hz1);
waitAllForSafeState(hz2);
// then: once all migrations are committed, the query is executed *with* the index and
// returns the expected results.
final IMap<String, Person> mapOnNode2 = hz2.getMap("map");
final AtomicInteger invocationCounter = new AtomicInteger(0);
// eventually index should be created after join
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Collection<Person> personsWithAgePredicate = mapOnNode2.values(new AgePredicate(invocationCounter));
assertEquals("isIndexed should have located an index", 1, invocationCounter.get());
assertEquals("index should return 1 match", 1, personsWithAgePredicate.size());
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class NearCacheTest method testNearCacheInvalidation_whenMaxSizeExceeded.
private void testNearCacheInvalidation_whenMaxSizeExceeded(EvictionPolicy evictionPolicy) {
int mapSize = 2000;
final int maxSize = 1000;
final IMap<Integer, Integer> map = getMapConfiguredWithMaxSizeAndPolicy(evictionPolicy, maxSize);
populateMap(map, mapSize);
populateNearCache(map, mapSize);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
long ownedEntryCount = getNearCacheStats(map).getOwnedEntryCount();
assertEquals(maxSize, ownedEntryCount);
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class NearCacheTest method testNearCacheInvalidationByUsingMapPutAll.
@Test
public void testNearCacheInvalidationByUsingMapPutAll() {
int clusterSize = 3;
int mapSize = 5000;
String mapName = randomMapName();
Config config = getConfig();
config.getMapConfig(mapName).setNearCacheConfig(newNearCacheConfig().setInvalidateOnChange(true));
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
HazelcastInstance[] instances = factory.newInstances(config);
final IMap<Integer, Integer> map = instances[0].getMap(mapName);
populateMap(map, mapSize);
populateNearCache(map, mapSize);
// more-or-less (count / no_of_nodes) should be in the Near Cache now
assertTrue(getNearCacheSize(map) > (mapSize / clusterSize - mapSize * 0.1));
Map<Integer, Integer> invalidationMap = new HashMap<Integer, Integer>(mapSize);
populateMap(invalidationMap, mapSize);
// this should invalidate the Near Cache
map.putAll(invalidationMap);
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals("Invalidation is not working on putAll()", 0, getNearCacheSize(map));
}
});
}
Aggregations