Search in sources :

Example 66 with TransactionalMap

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

the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method throws_reached_max_size_exception_when_one_phase.

@Test
public void throws_reached_max_size_exception_when_one_phase() {
    expectedException.expect(ReachedMaxSizeException.class);
    String mapName = "map";
    Config config = getConfig(mapName, 100);
    HazelcastInstance node = createHazelcastInstance(config);
    TransactionContext context = newTransactionContext(node, ONE_PHASE);
    context.beginTransaction();
    TransactionalMap map = context.getMap("map");
    for (int i = 0; i < 101; i++) {
        map.put("item-" + i, "value");
    }
    context.commitTransaction();
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 67 with TransactionalMap

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

the class TransactionsWithWriteBehind_whenNoCoalescingQueueIsFullTest method prepare_step_throws_reached_max_size_exception_when_two_phase.

@Test
public void prepare_step_throws_reached_max_size_exception_when_two_phase() {
    expectedException.expect(TransactionException.class);
    expectedException.expectCause(isA(ReachedMaxSizeException.class));
    String mapName = "map";
    long maxWbqCapacity = 100;
    Config config = getConfig(mapName, maxWbqCapacity);
    HazelcastInstance node = createHazelcastInstance(config);
    TransactionContext context = newTransactionContext(node, TWO_PHASE);
    context.beginTransaction();
    TransactionalMap map = context.getMap(mapName);
    for (int i = 0; i < 101; i++) {
        map.put("item-" + i, "value");
    }
    context.commitTransaction();
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) ReachedMaxSizeException(com.hazelcast.map.ReachedMaxSizeException) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 68 with TransactionalMap

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

the class MapTransactionTest method testGetForUpdate_whenTimeout.

@Test
public void testGetForUpdate_whenTimeout() 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");
    map.lock("var");
    TransactionOptions opts = new TransactionOptions();
    opts.setTimeout(1, TimeUnit.SECONDS);
    try {
        boolean b = h1.executeTransaction(opts, new TransactionalTask<Boolean>() {

            public Boolean execute(TransactionalTaskContext context) throws TransactionException {
                final TransactionalMap<String, String> txMap = context.getMap("default");
                txMap.getForUpdate("var");
                fail();
                return true;
            }
        });
    } catch (TransactionException e) {
    }
    assertTrue(map.isLocked("var"));
}
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) TransactionOptions(com.hazelcast.transaction.TransactionOptions) 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 69 with TransactionalMap

use of com.hazelcast.transaction.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;
        }
    });
}
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 70 with TransactionalMap

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

the class MapTransactionTest method testTxnOwnerDies.

@Test
@Category(NightlyTest.class)
public void testTxnOwnerDies() throws TransactionException, InterruptedException {
    Config config = getConfig();
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    final HazelcastInstance h1 = factory.newHazelcastInstance(config);
    final HazelcastInstance h2 = factory.newHazelcastInstance(config);
    final HazelcastInstance h3 = factory.newHazelcastInstance(config);
    final int size = 50;
    final AtomicBoolean result = new AtomicBoolean(false);
    Runnable runnable = new Runnable() {

        public void run() {
            try {
                boolean b = h1.executeTransaction(options, new TransactionalTask<Boolean>() {

                    public Boolean execute(TransactionalTaskContext context) throws TransactionException {
                        final TransactionalMap<Object, Object> txMap = context.getMap("default");
                        for (int i = 0; i < size; i++) {
                            txMap.put(i, i);
                            sleepSeconds(1);
                        }
                        return true;
                    }
                });
                result.set(b);
            } catch (HazelcastInstanceNotActiveException ignored) {
            } catch (TransactionException ignored) {
            }
        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
    sleepSeconds(1);
    h1.shutdown();
    // wait till thread finishes.
    thread.join(30 * 1000);
    assertFalse(result.get());
    final IMap map2 = h2.getMap("default");
    for (int i = 0; i < size; i++) {
        assertNull(map2.get(i));
    }
}
Also used : TransactionalMap(com.hazelcast.transaction.TransactionalMap) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionalTaskContext(com.hazelcast.transaction.TransactionalTaskContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastInstanceNotActiveException(com.hazelcast.core.HazelcastInstanceNotActiveException) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Category(org.junit.experimental.categories.Category) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Aggregations

TransactionalMap (com.hazelcast.transaction.TransactionalMap)95 Test (org.junit.Test)77 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)76 QuickTest (com.hazelcast.test.annotation.QuickTest)76 HazelcastInstance (com.hazelcast.core.HazelcastInstance)63 TransactionException (com.hazelcast.transaction.TransactionException)60 TransactionalTaskContext (com.hazelcast.transaction.TransactionalTaskContext)55 NightlyTest (com.hazelcast.test.annotation.NightlyTest)42 Config (com.hazelcast.config.Config)39 TransactionContext (com.hazelcast.transaction.TransactionContext)38 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)37 MapStoreConfig (com.hazelcast.config.MapStoreConfig)32 IMap (com.hazelcast.map.IMap)28 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)27 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)14 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)7 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)6 TransactionNotActiveException (com.hazelcast.transaction.TransactionNotActiveException)6 Collection (java.util.Collection)6 ExecutionException (java.util.concurrent.ExecutionException)6