use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseIntegrationTest method commit_whenPrepareSkippedButCommitRunsIntoConflict.
@Test
public void commit_whenPrepareSkippedButCommitRunsIntoConflict() {
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(1);
TransactionImpl tx = new TransactionImpl(localTxService, localNodeEngine, options, txOwner);
tx.begin();
MockTransactionLogRecord record = new MockTransactionLogRecord().failCommit();
tx.add(record);
try {
tx.commit();
fail();
} catch (TransactionException expected) {
}
assertCommitFailed(tx);
assertNoBackupLogOnRemote(tx);
record.assertPrepareNotCalled().assertCommitCalled().assertRollbackNotCalled();
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class TransactionImpl_TwoPhaseTest method commit_whenThrowsExceptionDuringCommit.
@Test
public void commit_whenThrowsExceptionDuringCommit() throws Exception {
TransactionOptions options = new TransactionOptions().setTransactionType(TWO_PHASE).setDurability(0);
TransactionImpl tx = new TransactionImpl(txManagerService, nodeEngine, options, "dummy-uuid");
tx.begin();
tx.add(new MockTransactionLogRecord().failCommit());
tx.prepare();
try {
tx.commit();
fail();
} catch (TransactionException expected) {
}
assertEquals(COMMIT_FAILED, tx.getState());
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testValues_withPagingPredicate.
@Test(expected = IllegalArgumentException.class)
public void testValues_withPagingPredicate() throws TransactionException {
final int nodeCount = 1;
final String mapName = randomMapName("testValuesWithPagingPredicate");
final Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance node = factory.newHazelcastInstance(config);
final IMap<Integer, Employee> 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);
PagingPredicate<Integer, Employee> predicate = new PagingPredicate<Integer, Employee>(5);
txMap.values(predicate);
return true;
}
});
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testReplace.
@Test
public void testReplace() 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");
assertNull(txMap.replace("1", "value"));
txMap.put("1", "value2");
assertEquals("value2", txMap.replace("1", "value3"));
assertEquals("value3", txMap.get("1"));
assertNull(map1.get("1"));
assertNull(map2.get("2"));
return true;
}
});
assertTrue(b);
assertEquals("value3", map1.get("1"));
assertEquals("value3", map2.get("1"));
}
use of com.hazelcast.transaction.TransactionException in project hazelcast by hazelcast.
the class MapTransactionTest method testGetForUpdate_LoadsKeyFromMapLoader_whenKeyDoesNotExistsInDb.
@Test
public void testGetForUpdate_LoadsKeyFromMapLoader_whenKeyDoesNotExistsInDb() {
final String mapName = randomMapName();
final MapStoreAdapter mock = mock(MapStoreAdapter.class);
when(mock.load(anyObject())).thenReturn(null);
Config config = new Config();
MapStoreConfig storeConfig = new MapStoreConfig();
storeConfig.setEnabled(true).setImplementation(mock);
config.getMapConfig(mapName).setMapStoreConfig(storeConfig);
HazelcastInstance instance = createHazelcastInstance(config);
instance.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> map = context.getMap(mapName);
Object value = map.getForUpdate(1);
assertNull("value should be null", value);
verify(mock, times(1)).load(anyObject());
return null;
}
});
}
Aggregations