use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testValues_shouldNotDeduplicateEntriesWhenGettingByPredicate.
@Test
public void testValues_shouldNotDeduplicateEntriesWhenGettingByPredicate() throws TransactionException {
final int nodeCount = 1;
final String mapName = randomMapName();
final Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance node = factory.newHazelcastInstance(config);
final IMap map = node.getMap(mapName);
final Employee emp = new Employee("name", 77, true, 10D);
map.put(1, emp);
node.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Integer, Employee> txMap = context.getMap(mapName);
txMap.put(2, emp);
Collection<Employee> coll = txMap.values(Predicates.sql("age = 77"));
assertEquals(2, coll.size());
return true;
}
});
node.shutdown();
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testContainsKey.
@Test
public void testContainsKey() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final IMap<String, String> map = h1.getMap("default");
map.put("1", "1");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.delete("1");
assertFalse(txMap.containsKey("1"));
assertTrue(map.containsKey("1"));
return true;
}
});
assertTrue(b);
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testPutTTL.
// =================== putTTL ===============================
@Test
public void testPutTTL() throws TransactionException {
final String mapName = "putWithTTL";
final 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(mapName);
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap(mapName);
txMap.put("1", "value", 5, TimeUnit.SECONDS);
assertEquals("value", txMap.get("1"));
assertEquals(1, txMap.size());
return true;
}
});
assertTrue(b);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNull(map2.get("1"));
}
});
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testRemove.
@Test
public void testRemove() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap map1 = h1.getMap("default");
final IMap map2 = h2.getMap("default");
map2.put("1", "1");
map2.put("2", "2");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.put("3", "3");
map2.put("4", "4");
assertEquals("1", txMap.remove("1"));
assertEquals("2", map1.remove("2"));
assertEquals("1", map1.get("1"));
assertNull(txMap.get("1"));
assertNull(txMap.remove("2"));
assertEquals(2, txMap.size());
return true;
}
});
assertTrue(b);
assertNull(map1.get("1"));
assertNull(map2.get("1"));
assertNull(map1.get("2"));
assertNull(map2.get("2"));
assertEquals("3", map1.get("3"));
assertEquals("3", map2.get("3"));
assertEquals("4", map1.get("4"));
assertEquals("4", map2.get("4"));
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testGetForUpdate_ThenUpdate.
@Test
public void testGetForUpdate_ThenUpdate() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap<String, String> map = h2.getMap("default");
map.put("var", "value0");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
try {
final TransactionalMap<String, String> txMap = context.getMap("default");
assertEquals("value0", txMap.getForUpdate("var"));
assertEquals("value0", txMap.put("var", "value1"));
assertEquals("value1", txMap.getForUpdate("var"));
assertEquals("value1", txMap.get("var"));
} catch (Exception e) {
}
return true;
}
});
}
Aggregations