use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method throws_reached_max_size_exception_when_one_phase.
@Test
public void throws_reached_max_size_exception_when_one_phase() {
expectedException.expect(ReachedMaxSizeException.class);
String mapName = "map";
Config config = getConfig(mapName, 100);
HazelcastInstance node = createHazelcastInstance(config);
TransactionContext context = newTransactionContext(node, ONE_PHASE);
context.beginTransaction();
TransactionalMap map = context.getMap("map");
for (int i = 0; i < 101; i++) {
map.put("item-" + i, "value");
}
context.commitTransaction();
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method prepare_step_throws_reached_max_size_exception_when_two_phase.
@Test
public void prepare_step_throws_reached_max_size_exception_when_two_phase() {
expectedException.expect(TransactionException.class);
expectedException.expectCause(isA(ReachedMaxSizeException.class));
String mapName = "map";
long maxWbqCapacity = 100;
Config config = getConfig(mapName, maxWbqCapacity);
HazelcastInstance node = createHazelcastInstance(config);
TransactionContext context = newTransactionContext(node, TWO_PHASE);
context.beginTransaction();
TransactionalMap map = context.getMap(mapName);
for (int i = 0; i < 101; i++) {
map.put("item-" + i, "value");
}
context.commitTransaction();
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testGetForUpdate_whenTimeout.
@Test
public void testGetForUpdate_whenTimeout() 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");
map.lock("var");
TransactionOptions opts = new TransactionOptions();
opts.setTimeout(1, TimeUnit.SECONDS);
try {
boolean b = h1.executeTransaction(opts, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<String, String> txMap = context.getMap("default");
txMap.getForUpdate("var");
fail();
return true;
}
});
} catch (TransactionException e) {
}
assertTrue(map.isLocked("var"));
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testReplace_whenNullOldValue.
@Test(expected = NullPointerException.class)
public void testReplace_whenNullOldValue() 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.replace("key", null, "newvalue");
return true;
}
});
}
use of com.hazelcast.transaction.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testTxnOwnerDies.
@Test
@Category(NightlyTest.class)
public void testTxnOwnerDies() throws TransactionException, InterruptedException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final HazelcastInstance h3 = factory.newHazelcastInstance(config);
final int size = 50;
final AtomicBoolean result = new AtomicBoolean(false);
Runnable runnable = new Runnable() {
public void run() {
try {
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap("default");
for (int i = 0; i < size; i++) {
txMap.put(i, i);
sleepSeconds(1);
}
return true;
}
});
result.set(b);
} catch (HazelcastInstanceNotActiveException ignored) {
} catch (TransactionException ignored) {
}
}
};
Thread thread = new Thread(runnable);
thread.start();
sleepSeconds(1);
h1.shutdown();
// wait till thread finishes.
thread.join(30 * 1000);
assertFalse(result.get());
final IMap map2 = h2.getMap("default");
for (int i = 0; i < size; i++) {
assertNull(map2.get(i));
}
}
Aggregations