use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testSet.
// =================== set ===============================
@Test
public void testSet() 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");
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
txMap.set("1", "value");
txMap.set("1", "value2");
assertEquals("value2", txMap.get("1"));
assertNull(map1.get("1"));
assertNull(map1.get("2"));
assertEquals(1, txMap.size());
return true;
}
});
assertTrue(b);
assertEquals("value2", map1.get("1"));
assertEquals("value2", map2.get("1"));
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method tesPutIfAbsent_whenNullValue.
@Test(expected = NullPointerException.class)
public void tesPutIfAbsent_whenNullValue() 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.putIfAbsent("key", null);
return true;
}
});
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testValues_WithPredicates_notContains_oldValues.
@Test
public void testValues_WithPredicates_notContains_oldValues() throws TransactionException {
Config config = getConfig();
final String mapName = "testValuesWithPredicate_notContains_oldValues";
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap<Integer, Employee> map = h1.getMap(mapName);
final Employee employeeAtAge22 = new Employee("emin", 22, true, 10D);
final Employee employeeAtAge23 = new Employee("emin", 23, true, 10D);
map.put(1, employeeAtAge22);
h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> txMap = context.getMap(mapName);
assertEquals(1, txMap.values(Predicates.sql("age > 21")).size());
txMap.put(1, employeeAtAge23);
Collection coll = txMap.values(Predicates.sql("age > 21"));
assertEquals(1, coll.size());
return true;
}
});
h1.shutdown();
h2.shutdown();
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testFailingMapStore.
@Test
public // TODO: @mm - Review following case...
void testFailingMapStore() throws TransactionException {
final String map = "map";
final String anotherMap = "anotherMap";
Config config = getConfig();
config.getMapConfig(map).setMapStoreConfig(new MapStoreConfig().setEnabled(true).setImplementation(new MapStoreAdapter() {
public void store(Object key, Object value) {
throw new ExpectedRuntimeException("Map store intentionally failed :) ");
}
}));
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
try {
h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
assertNull(context.getMap(map).put("1", "value1"));
assertNull(context.getMap(anotherMap).put("1", "value1"));
return true;
}
});
fail();
} catch (ExpectedRuntimeException expected) {
}
assertNull(h2.getMap(map).get("1"));
assertEquals("value1", h2.getMap(anotherMap).get("1"));
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testGetForUpdate_whenNullKey.
// =================== getForUpdate ===============================
@Test(expected = NullPointerException.class)
public void testGetForUpdate_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.getForUpdate(null);
return true;
}
});
}
Aggregations