use of com.hazelcast.core.TransactionalMultiMap in project hazelcast by hazelcast.
the class ClientTxnMultiMapTest method testPutAndRoleBack.
@Test
public void testPutAndRoleBack() throws Exception {
final String mapName = randomString();
final String key = "key";
final String value = "value";
final MultiMap multiMap = client.getMultiMap(mapName);
TransactionContext tx = client.newTransactionContext();
tx.beginTransaction();
TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
mulitMapTxn.put(key, value);
mulitMapTxn.put(key, value);
tx.rollbackTransaction();
assertEquals(0, multiMap.get(key).size());
}
use of com.hazelcast.core.TransactionalMultiMap in project hazelcast by hazelcast.
the class ClientTxnMultiMapTest method testGet_whenBackedWithList.
@Test
public void testGet_whenBackedWithList() throws Exception {
final String mapName = multiMapBackedByList + randomString();
final String key = "key";
final String value = "value";
final MultiMap multiMap = server.getMultiMap(mapName);
multiMap.put(key, value);
TransactionContext tx = client.newTransactionContext();
tx.beginTransaction();
TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
Collection c = mulitMapTxn.get(key);
assertFalse(c.isEmpty());
tx.commitTransaction();
}
use of com.hazelcast.core.TransactionalMultiMap in project hazelcast by hazelcast.
the class ClientTxnMultiMapTest method testConcrruentTxnPut.
@Test
public void testConcrruentTxnPut() throws Exception {
final String mapName = randomString();
final MultiMap multiMap = client.getMultiMap(mapName);
final int threads = 10;
final ExecutorService ex = Executors.newFixedThreadPool(threads);
final CountDownLatch latch = new CountDownLatch(threads);
final AtomicReference<Throwable> error = new AtomicReference<Throwable>(null);
for (int i = 0; i < threads; i++) {
final int key = i;
ex.execute(new Runnable() {
public void run() {
multiMap.put(key, "value");
final TransactionContext context = client.newTransactionContext();
try {
context.beginTransaction();
final TransactionalMultiMap txnMultiMap = context.getMultiMap(mapName);
txnMultiMap.put(key, "value");
txnMultiMap.put(key, "value1");
txnMultiMap.put(key, "value2");
assertEquals(3, txnMultiMap.get(key).size());
context.commitTransaction();
assertEquals(3, multiMap.get(key).size());
} catch (Exception e) {
error.compareAndSet(null, e);
} finally {
latch.countDown();
}
}
});
}
try {
latch.await(1, TimeUnit.MINUTES);
assertNull(error.get());
} finally {
ex.shutdownNow();
}
}
use of com.hazelcast.core.TransactionalMultiMap in project hazelcast by hazelcast.
the class ClientTxnMultiMapTest method testRemove_whenBackedWithList.
@Test
public void testRemove_whenBackedWithList() throws Exception {
final String mapName = multiMapBackedByList + randomString();
final String key = "key";
final String value = "value";
final MultiMap multiMap = server.getMultiMap(mapName);
multiMap.put(key, value);
TransactionContext tx = client.newTransactionContext();
tx.beginTransaction();
TransactionalMultiMap mulitMapTxn = tx.getMultiMap(mapName);
Collection c = mulitMapTxn.remove(key);
assertFalse(c.isEmpty());
tx.commitTransaction();
}
use of com.hazelcast.core.TransactionalMultiMap in project hazelcast by hazelcast.
the class ClientTxnMultiMapTest method testRemoveAll.
@Test
public void testRemoveAll() throws Exception {
final String mapName = randomString();
final String key = "key";
MultiMap multiMap = client.getMultiMap(mapName);
for (int i = 0; i < 10; i++) {
multiMap.put(key, i);
}
TransactionContext tx = client.newTransactionContext();
tx.beginTransaction();
TransactionalMultiMap txnMultiMap = tx.getMultiMap(mapName);
txnMultiMap.remove(key);
tx.commitTransaction();
assertTrue(multiMap.get(key).isEmpty());
}
Aggregations