use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testCommitOrder.
@Test
public void testCommitOrder() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final HazelcastInstance h3 = factory.newHazelcastInstance(config);
final HazelcastInstance h4 = factory.newHazelcastInstance(config);
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("1", "value1");
assertEquals("value1", txMap.put("1", "value2"));
assertEquals("value2", txMap.put("1", "value3"));
assertEquals("value3", txMap.put("1", "value4"));
assertEquals("value4", txMap.put("1", "value5"));
assertEquals("value5", txMap.put("1", "value6"));
assertEquals(1, txMap.size());
return true;
}
});
assertEquals("value6", h4.getMap("default").get("1"));
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testContainsKey_whenNullKey.
// ========================= containsKey =====================
@Test(expected = NullPointerException.class)
public void testContainsKey_whenNullKey() throws TransactionException {
final HazelcastInstance hz = createHazelcastInstance();
hz.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.containsKey(null);
return true;
}
});
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testGetForUpdate_whenMultipleTimes.
@Test
public void testGetForUpdate_whenMultipleTimes() 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.getForUpdate("var"));
assertEquals("value0", txMap.getForUpdate("var"));
} catch (Exception e) {
}
return true;
}
});
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testRemove_whenSame.
@Test
public void testRemove_whenSame() 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");
assertTrue(txMap.remove("1", "1"));
assertFalse(txMap.remove("2", "1"));
assertEquals("1", map1.get("1"));
assertNull(txMap.get("1"));
assertTrue(txMap.remove("2", "2"));
assertFalse(txMap.remove("5", "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.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testDelete.
@Test
public void testDelete() 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");
txMap.delete("1");
map2.delete("2");
assertEquals("1", map1.get("1"));
assertNull(txMap.get("1"));
txMap.delete("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"));
}
Aggregations