use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class MapTransactionTest method testTxnReplace2.
@Test
public void testTxnReplace2() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap map2 = h2.getMap("default");
map2.put("1", "value2");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
assertEquals("value2", txMap.replace("1", "value3"));
assertEquals("value3", txMap.get("1"));
assertNull(map2.get("2"));
return true;
}
});
assertTrue(b);
IMap map1 = h1.getMap("default");
assertEquals("value3", map1.get("1"));
assertEquals("value3", map2.get("1"));
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class QueryCacheNoEventLossTest method newQueryCacheOnNewNode.
private IMap newQueryCacheOnNewNode(final AtomicInteger eventLostCounter) {
HazelcastInstance node = factory.newHazelcastInstance(newConfig());
waitClusterForSafeState(node);
IMap map = node.getMap(MAP_NAME);
addEventLostListenerToQueryCache(map, eventLostCounter);
return map;
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class QueryCacheGuaranteesTest method continuesToReceiveEvents_afterNodeShutdown.
@Test
public void continuesToReceiveEvents_afterNodeShutdown() {
String mapName = randomString();
String queryCacheName = randomString();
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
Config config = new Config();
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setBatchSize(100);
queryCacheConfig.setDelaySeconds(6);
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.addQueryCacheConfig(queryCacheConfig);
HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map = (IMap<Integer, Integer>) node.<Integer, Integer>getMap(mapName);
final QueryCache<Integer, Integer> queryCache = map.getQueryCache(queryCacheName, Predicates.sql("this > 20"), true);
for (int i = 0; i < 30; i++) {
map.put(i, i);
}
HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map2 = node2.getMap(mapName);
for (int i = 200; i < 220; i++) {
map2.put(i, i);
}
HazelcastInstance node3 = instanceFactory.newHazelcastInstance(config);
IMap<Integer, Integer> map3 = node3.getMap(mapName);
for (int i = 350; i < 357; i++) {
map3.put(i, i);
}
node3.shutdown();
for (int i = 220; i < 227; i++) {
map2.put(i, i);
}
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(43, queryCache.size());
}
});
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class QueryCacheMethodsWithPredicateTest method testKeySetIsNotBackedByQueryCache_nonIndexedAttribute.
@Test
public void testKeySetIsNotBackedByQueryCache_nonIndexedAttribute() {
Assume.assumeTrue(inMemoryFormat != OBJECT);
int count = 111;
IMap<Employee, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
for (int i = 0; i < count; i++) {
map.put(new Employee(i), new Employee(i));
}
Predicate<Employee, Employee> predicate = Predicates.lessThan("salary", Employee.MAX_SALARY);
QueryCache<Employee, Employee> cache = map.getQueryCache(cacheName);
cache.addIndex(IndexType.SORTED, "id");
for (Map.Entry<Employee, Employee> entry : cache.entrySet(predicate)) {
entry.getValue().setAge(Employee.MAX_AGE + 1);
}
for (Map.Entry<Employee, Employee> entry : cache.entrySet(predicate)) {
assertNotEquals(Employee.MAX_AGE + 1, entry.getValue().getAge());
}
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class QueryCacheTest method testQueryCacheCleared_afterCalling_IMap_clear.
@Test
public void testQueryCacheCleared_afterCalling_IMap_clear() {
final IMap<Integer, Employee> map = getIMapWithDefaultConfig(TRUE_PREDICATE);
final QueryCache<Integer, Employee> queryCache = map.getQueryCache(cacheName);
populateMap(map, 1000);
IFunction clear = (ignored) -> {
map.clear();
return null;
};
assertQueryCacheSizeEventually(0, clear, queryCache);
}
Aggregations