Search in sources :

Example 36 with TransactionException

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

the class MapTransactionTest method testCommitOrder.

@Test
public void testCommitOrder() throws TransactionException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final HazelcastInstance h3 = factory.newHazelcastInstance(config);
    final HazelcastInstance h4 = factory.newHazelcastInstance(config);
    boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap("default");
            txMap.put("1", "value1");
            assertEquals("value1", txMap.put("1", "value2"));
            assertEquals("value2", txMap.put("1", "value3"));
            assertEquals("value3", txMap.put("1", "value4"));
            assertEquals("value4", txMap.put("1", "value5"));
            assertEquals("value5", txMap.put("1", "value6"));
            assertEquals(1, txMap.size());
            return true;
        }
    });
    assertEquals("value6", h4.getMap("default").get("1"));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 37 with TransactionException

use of com.hazelcast.transaction.TransactionException 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;
        }
    });
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 38 with TransactionException

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

the class MapTransactionTest method testGetForUpdate_whenMultipleTimes.

@Test
public void testGetForUpdate_whenMultipleTimes() 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.getForUpdate("var"));
                assertEquals("value0", txMap.getForUpdate("var"));
            } catch (Exception e) {
            }
            return true;
        }
    });
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) TransactionException(com.hazelcast.transaction.TransactionException) ExecutionException(java.util.concurrent.ExecutionException) ExpectedRuntimeException(com.hazelcast.test.ExpectedRuntimeException) TransactionNotActiveException(com.hazelcast.transaction.TransactionNotActiveException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 39 with TransactionException

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

the class MapTransactionTest method testRemove_whenSame.

@Test
public void testRemove_whenSame() throws TransactionException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap map1 = h1.getMap("default");
    final IMap map2 = h2.getMap("default");
    map2.put("1", "1");
    map2.put("2", "2");
    boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap("default");
            txMap.put("3", "3");
            map2.put("4", "4");
            assertTrue(txMap.remove("1", "1"));
            assertFalse(txMap.remove("2", "1"));
            assertEquals("1", map1.get("1"));
            assertNull(txMap.get("1"));
            assertTrue(txMap.remove("2", "2"));
            assertFalse(txMap.remove("5", "2"));
            assertEquals(2, txMap.size());
            return true;
        }
    });
    assertTrue(b);
    assertNull(map1.get("1"));
    assertNull(map2.get("1"));
    assertNull(map1.get("2"));
    assertNull(map2.get("2"));
    assertEquals("3", map1.get("3"));
    assertEquals("3", map2.get("3"));
    assertEquals("4", map1.get("4"));
    assertEquals("4", map2.get("4"));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 40 with TransactionException

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

the class MapTransactionTest method testDelete.

@Test
public void testDelete() throws TransactionException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final IMap map1 = h1.getMap("default");
    final IMap map2 = h2.getMap("default");
    map2.put("1", "1");
    map2.put("2", "2");
    boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {

        public Boolean execute(TransactionalTaskContext context) throws TransactionException {
            final TransactionalMap<Object, Object> txMap = context.getMap("default");
            txMap.put("3", "3");
            map2.put("4", "4");
            txMap.delete("1");
            map2.delete("2");
            assertEquals("1", map1.get("1"));
            assertNull(txMap.get("1"));
            txMap.delete("2");
            assertEquals(2, txMap.size());
            return true;
        }
    });
    assertTrue(b);
    assertNull(map1.get("1"));
    assertNull(map2.get("1"));
    assertNull(map1.get("2"));
    assertNull(map2.get("2"));
    assertEquals("3", map1.get("3"));
    assertEquals("3", map2.get("3"));
    assertEquals("4", map1.get("4"));
    assertEquals("4", map2.get("4"));
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

TransactionException (com.hazelcast.transaction.TransactionException)106 Test (org.junit.Test)82 QuickTest (com.hazelcast.test.annotation.QuickTest)76 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)72 HazelcastInstance (com.hazelcast.core.HazelcastInstance)70 TransactionalMap (com.hazelcast.transaction.TransactionalMap)60 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)57 NightlyTest (com.hazelcast.test.annotation.NightlyTest)48 Config (com.hazelcast.config.Config)38 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)38 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)34 MapStoreConfig (com.hazelcast.config.MapStoreConfig)32 TransactionContext (com.hazelcast.transaction.TransactionContext)22 IMap (com.hazelcast.map.IMap)16 TransactionOptions (com.hazelcast.transaction.TransactionOptions)8 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)7 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)7 Mockito.anyObject (org.mockito.Mockito.anyObject)7 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)6 Data (com.hazelcast.internal.serialization.Data)5