use of com.hazelcast.core.TransactionalMap 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;
}
});
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testGetForUpdate_releasesBackupLock.
@Test
public void testGetForUpdate_releasesBackupLock() {
Config config = getConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
final String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
instance1.executeTransaction(new TransactionalTask<Object>() {
@Override
public Object execute(TransactionalTaskContext context) throws TransactionException {
TransactionalMap<Object, Object> map = context.getMap(randomString());
map.getForUpdate(keyOwnedByInstance2);
return null;
}
});
Node node = TestUtil.getNode(instance1);
Data keyData = node.nodeEngine.toData(keyOwnedByInstance2);
LockService lockService = node.nodeEngine.getService(LockService.SERVICE_NAME);
for (LockResource lockResource : lockService.getAllLocks()) {
if (keyData.equals(lockResource.getKey())) {
assertEquals(0, lockResource.getLockCount());
}
}
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testTxnCommit.
@Test
public void testTxnCommit() throws TransactionException {
Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance h1 = factory.newHazelcastInstance(config);
final HazelcastInstance h2 = factory.newHazelcastInstance(config);
final String map1 = "map1";
final String map2 = "map2";
final String key = "1";
boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {
public Boolean execute(TransactionalTaskContext context) throws TransactionException {
final TransactionalMap<Object, Object> txMap1 = context.getMap(map1);
final TransactionalMap<Object, Object> txMap2 = context.getMap(map2);
txMap1.put(key, "value");
assertEquals("value", txMap1.put(key, "value1"));
assertEquals("value1", txMap1.get(key));
txMap2.put(key, "value");
assertEquals("value", txMap2.put(key, "value2"));
assertEquals("value2", txMap2.get(key));
assertEquals(true, txMap1.containsKey(key));
assertEquals(true, txMap2.containsKey(key));
assertNull(h1.getMap(map1).get(key));
assertNull(h1.getMap(map2).get(key));
return true;
}
});
assertTrue(b);
assertEquals("value1", h1.getMap(map1).get(key));
assertEquals("value1", h2.getMap(map1).get(key));
assertEquals("value2", h1.getMap(map2).get(key));
assertEquals("value2", h2.getMap(map2).get(key));
assertFalse(h1.getMap(map1).isLocked(key));
assertFalse(h1.getMap(map2).isLocked(key));
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testContainsKey_whenNullKey.
// ========================= containsKey =====================
@Test(expected = NullPointerException.class)
public void testContainsKey_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.containsKey(null);
return true;
}
});
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method tesPutIfAbsent_whenNullKey.
// ========================= putIfAbsent =====================
@Test(expected = NullPointerException.class)
public void tesPutIfAbsent_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.putIfAbsent(null, "value");
return true;
}
});
}
Aggregations