use of com.hazelcast.transaction.TransactionalTaskContext 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.TransactionalTaskContext in project hazelcast by hazelcast.
the class MapTransactionTest method testPutTTL.
// =================== putTTL ===============================
@Test
public void testPutTTL() throws TransactionException {
final String mapName = "putWithTTL";
final Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final IMap map2 = h2.getMap(mapName);
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap = context.getMap(mapName);
txMap.put("1", "value", 5, TimeUnit.SECONDS);
assertEquals("value", txMap.get("1"));
assertEquals(1, txMap.size());
return true;
}
});
assertTrue(b);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertNull(map2.get("1"));
}
});
}
use of com.hazelcast.transaction.TransactionalTaskContext 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));
}
}
use of com.hazelcast.transaction.TransactionalTaskContext in project hazelcast by hazelcast.
the class MapTransactionTest method testSet_whenNullKey.
@Test(expected = NullPointerException.class)
public void testSet_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.set(null, "value");
return true;
}
});
}
use of com.hazelcast.transaction.TransactionalTaskContext in project hazelcast by hazelcast.
the class MapTransactionTest method testUpdate_thenGetForUpdate.
@Test
public void testUpdate_thenGetForUpdate() 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.put("var", "value1"));
assertEquals("value1", txMap.getForUpdate("var"));
} catch (Exception e) {
}
return true;
}
});
}
Aggregations