use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class ClientTxnMapTest method testDeadLockFromClientInstance.
@Test
public void testDeadLockFromClientInstance() throws InterruptedException {
final String mapName = randomString();
final String key = "key";
final AtomicBoolean running = new AtomicBoolean(true);
Thread t = new Thread() {
public void run() {
while (running.get()) {
client.getMap(mapName).get(key);
}
}
};
t.start();
CBAuthorisation cb = new CBAuthorisation();
cb.setAmount(15000);
try {
TransactionContext context = client.newTransactionContext();
context.beginTransaction();
TransactionalMap mapTransaction = context.getMap(mapName);
// init data
mapTransaction.put(key, cb);
// start test deadlock, 3 set and concurrent, get deadlock
cb.setAmount(12000);
mapTransaction.set(key, cb);
cb.setAmount(10000);
mapTransaction.set(key, cb);
cb.setAmount(900);
mapTransaction.set(key, cb);
cb.setAmount(800);
mapTransaction.set(key, cb);
cb.setAmount(700);
mapTransaction.set(key, cb);
context.commitTransaction();
} catch (TransactionException e) {
e.printStackTrace();
fail();
}
running.set(false);
t.join();
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class ClientTxnMapTest method testTnxMapRemoveKeyValue.
@Test
public void testTnxMapRemoveKeyValue() throws Exception {
final String mapName = randomString();
final String key1 = "key1";
final String oldValue1 = "old1";
final String key2 = "key2";
final String oldValue2 = "old2";
IMap map = client.getMap(mapName);
map.put(key1, oldValue1);
map.put(key2, oldValue2);
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
final TransactionalMap txMap = context.getMap(mapName);
txMap.remove(key1, oldValue1);
txMap.remove(key2, "NO_REMOVE_AS_NOT_VALUE");
context.commitTransaction();
assertNull(map.get(key1));
assertEquals(oldValue2, map.get(key2));
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class ClientTxnMapTest method testTnxMapReplace.
@Test
public void testTnxMapReplace() throws Exception {
final String mapName = randomString();
IMap map = client.getMap(mapName);
final String key1 = "key1";
final String key2 = "key2";
final String replaceValue = "replaceValue";
map.put(key1, "OLD_VALUE");
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
final TransactionalMap txMap = context.getMap(mapName);
txMap.replace(key1, replaceValue);
txMap.replace(key2, "NOT_POSSIBLE");
context.commitTransaction();
assertEquals(replaceValue, map.get(key1));
assertNull(map.get(key2));
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method commit_step_does_not_throw_reached_max_size_exception_when_two_phase.
@Test
public void commit_step_does_not_throw_reached_max_size_exception_when_two_phase() {
String mapName = "map";
long maxWbqCapacity = 10;
int keySpace = 10;
Config config = getConfig(mapName, maxWbqCapacity);
HazelcastInstance node = createHazelcastInstance(config);
TransactionContext context = newTransactionContext(node, TWO_PHASE);
context.beginTransaction();
TransactionalMap txMap = context.getMap(mapName);
for (int i = 0; i < keySpace; i++) {
txMap.remove("item-" + i);
}
try {
context.commitTransaction();
} catch (TransactionException e) {
fail("no txn exception is expected here...");
}
assertEquals(0, node.getMap(mapName).size());
assertWriteBehindQueuesEmpty(mapName, Collections.singletonList(node));
assertEquals(0, getTotalNumOfTxnReservedCapacity(mapName, node));
assertEquals(0, getNodeWideUsedCapacity(node));
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method rollback_does_not_preserve_latest_state_after_reached_max_size_exception_when_one_phase.
@Ignore
@Test
public void rollback_does_not_preserve_latest_state_after_reached_max_size_exception_when_one_phase() {
String mapName = "map";
long maxWbqCapacity = 100;
Config config = getConfig(mapName, maxWbqCapacity);
HazelcastInstance node = createHazelcastInstance(config);
TransactionContext context = newTransactionContext(node, ONE_PHASE);
context.beginTransaction();
TransactionalMap map = context.getMap(mapName);
for (int i = 0; i < 101; i++) {
map.put("item-" + i, "value");
}
try {
context.commitTransaction();
} catch (TransactionException e) {
context.rollbackTransaction();
}
assertEquals(100, node.getMap(mapName).size());
}
Aggregations