Search in sources :

Example 1 with TransactionContext

use of com.hazelcast.transaction.TransactionContext in project hazelcast by hazelcast.

the class MultiMapTestsFrom2X method testMultiMapPutRemoveWithTxn.

@Test
public void testMultiMapPutRemoveWithTxn() {
    final HazelcastInstance instance = createHazelcastInstance();
    MultiMap<String, String> multiMap = instance.getMultiMap("testMultiMapPutRemoveWithTxn");
    multiMap.put("1", "C");
    multiMap.put("2", "x");
    multiMap.put("2", "y");
    final TransactionContext context = instance.newTransactionContext();
    context.beginTransaction();
    TransactionalMultiMap<String, String> txnMap = context.getMultiMap("testMultiMapPutRemoveWithTxn");
    txnMap.put("1", "A");
    txnMap.put("1", "B");
    Collection g1 = txnMap.get("1");
    assertContains(g1, "A");
    assertContains(g1, "B");
    assertContains(g1, "C");
    assertTrue(txnMap.remove("1", "C"));
    assertEquals(4, txnMap.size());
    Collection g2 = txnMap.get("1");
    assertContains(g2, "A");
    assertContains(g2, "B");
    assertFalse(g2.contains("C"));
    Collection r1 = txnMap.remove("2");
    assertContains(r1, "x");
    assertContains(r1, "y");
    assertEquals(0, txnMap.get("2").size());
    Collection r2 = txnMap.remove("1");
    assertEquals(2, r2.size());
    assertContains(r2, "A");
    assertContains(r2, "B");
    assertEquals(0, txnMap.get("1").size());
    assertEquals(0, txnMap.size());
    assertEquals(3, multiMap.size());
    context.commitTransaction();
    assertEquals(0, multiMap.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) Collection(java.util.Collection) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with TransactionContext

use of com.hazelcast.transaction.TransactionContext in project hazelcast by hazelcast.

the class TransactionalMapWriteQuorumTest method testTxDeleteThrowsExceptionWhenQuorumSizeNotMet.

@Test(expected = TransactionException.class)
public void testTxDeleteThrowsExceptionWhenQuorumSizeNotMet() {
    TransactionContext transactionContext = cluster.h4.newTransactionContext(options);
    transactionContext.beginTransaction();
    TransactionalMap<Object, Object> map = transactionContext.getMap(randomMapName(MAP_NAME_PREFIX));
    map.delete("foo");
    transactionContext.commitTransaction();
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with TransactionContext

use of com.hazelcast.transaction.TransactionContext in project hazelcast by hazelcast.

the class TransactionalMapWriteQuorumTest method testTxGetForUpdateThrowsExceptionWhenQuorumSizeNotMet.

@Test(expected = TransactionException.class)
public void testTxGetForUpdateThrowsExceptionWhenQuorumSizeNotMet() {
    TransactionContext transactionContext = cluster.h4.newTransactionContext(options);
    transactionContext.beginTransaction();
    TransactionalMap<Object, Object> map = transactionContext.getMap(randomMapName(MAP_NAME_PREFIX));
    map.getForUpdate("foo");
    transactionContext.commitTransaction();
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with TransactionContext

use of com.hazelcast.transaction.TransactionContext in project hazelcast by hazelcast.

the class TransactionalQueueQuorumTest method testTxTakeThrowsExceptionWhenQuorumSizeNotMet.

@Test(expected = TransactionException.class)
public void testTxTakeThrowsExceptionWhenQuorumSizeNotMet() throws Exception {
    TransactionContext transactionContext = cluster.h4.newTransactionContext(options);
    transactionContext.beginTransaction();
    TransactionalQueue<Object> q = transactionContext.getQueue(QUEUE_NAME);
    q.take();
    transactionContext.commitTransaction();
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with TransactionContext

use of com.hazelcast.transaction.TransactionContext in project hazelcast by hazelcast.

the class TransactionalMapReadWriteQuorumTest method testTxValuesThrowsExceptionWhenQuorumSizeNotMet.

@Test(expected = TransactionException.class)
public void testTxValuesThrowsExceptionWhenQuorumSizeNotMet() {
    TransactionContext transactionContext = cluster.h4.newTransactionContext(options);
    transactionContext.beginTransaction();
    TransactionalMap<Object, Object> map = transactionContext.getMap(randomMapName(MAP_NAME_PREFIX));
    map.values();
    transactionContext.commitTransaction();
}
Also used : TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TransactionContext (com.hazelcast.transaction.TransactionContext)391 Test (org.junit.Test)308 QuickTest (com.hazelcast.test.annotation.QuickTest)287 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)200 ParallelTest (com.hazelcast.test.annotation.ParallelTest)79 HazelcastInstance (com.hazelcast.core.HazelcastInstance)76 AbstractSplitBrainProtectionTest (com.hazelcast.splitbrainprotection.AbstractSplitBrainProtectionTest)76 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)48 TransactionalMap (com.hazelcast.transaction.TransactionalMap)38 TransactionException (com.hazelcast.transaction.TransactionException)27 VersionedObject (com.hazelcast.collection.impl.queue.model.VersionedObject)24 Config (com.hazelcast.config.Config)24 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)24 IMap (com.hazelcast.map.IMap)22 NightlyTest (com.hazelcast.test.annotation.NightlyTest)17 XAException (javax.transaction.xa.XAException)17 CountDownLatch (java.util.concurrent.CountDownLatch)15 TransactionalQueue (com.hazelcast.transaction.TransactionalQueue)12 TransactionOptions (com.hazelcast.transaction.TransactionOptions)10 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)9