use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testValuesWithPredicate_removingExistentEntry.
@Test
public void testValuesWithPredicate_removingExistentEntry() throws TransactionException {
final int nodeCount = 1;
final String mapName = randomMapName("_testValuesWithPredicate_removingExistentEntry_");
final Config config = getConfig();
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
final HazelcastInstance node = factory.newHazelcastInstance(config);
final IMap 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<Object, Object> txMap = context.getMap(mapName);
txMap.remove(1);
Collection<Object> coll = txMap.values(new SqlPredicate("age > 70 "));
assertEquals(0, coll.size());
return true;
}
});
node.shutdown();
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testGet_LoadsKeyFromMapLoader_whenKeyDoesNotExistsInDb.
@Test
public void testGet_LoadsKeyFromMapLoader_whenKeyDoesNotExistsInDb() {
final String mapName = randomMapName();
final MapStoreAdapter mock = mock(MapStoreAdapter.class);
when(mock.load(anyObject())).thenReturn(null);
Config config = getConfig();
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.get(1);
assertNull("value should be null", value);
verify(mock, times(1)).load(anyObject());
return null;
}
});
}
use of com.hazelcast.core.TransactionalMap in project hazelcast by hazelcast.
the class MapTransactionTest method testGetForUpdate_ThenUpdate.
@Test
public void testGetForUpdate_ThenUpdate() 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.getForUpdate("var"));
assertEquals("value0", txMap.put("var", "value1"));
assertEquals("value1", txMap.getForUpdate("var"));
assertEquals("value1", txMap.get("var"));
} catch (Exception e) {
}
return true;
}
});
}
use of com.hazelcast.core.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.core.TransactionalMap 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"));
}
});
}
Aggregations