Search in sources :

Example 41 with TransactionContext

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

the class QueueStoreTest method testIssue1401QueueStoreWithTxnPoll.

@Test
public void testIssue1401QueueStoreWithTxnPoll() {
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig();
    queueStoreConfig.setStoreImplementation(new MyQueueStore());
    queueStoreConfig.setEnabled(true);
    queueStoreConfig.setProperty("binary", "false");
    queueStoreConfig.setProperty("memory-limit", "0");
    queueStoreConfig.setProperty("bulk-load", "100");
    Config config = new Config();
    QueueConfig queueConfig = config.getQueueConfig("test");
    queueConfig.setMaxSize(10);
    queueConfig.setQueueStoreConfig(queueStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    for (int i = 0; i < 10; i++) {
        TransactionContext context = instance.newTransactionContext();
        context.beginTransaction();
        TransactionalQueue<String> queue = context.getQueue("test");
        String queueData = queue.poll();
        assertNotNull(queueData);
        context.commitTransaction();
    }
}
Also used : QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) QueueConfig(com.hazelcast.config.QueueConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueueConfig(com.hazelcast.config.QueueConfig) Config(com.hazelcast.config.Config) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) TransactionContext(com.hazelcast.transaction.TransactionContext) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 42 with TransactionContext

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

the class QueueTestsFrom2X method testQueueOfferCommitSize.

@Test
public void testQueueOfferCommitSize() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    TransactionContext context = instance1.newTransactionContext();
    context.beginTransaction();
    TransactionalQueue<String> txnQ1 = context.getQueue("testQueueOfferCommitSize");
    TransactionalQueue<String> txnQ2 = context.getQueue("testQueueOfferCommitSize");
    txnQ1.offer("item");
    assertEquals(1, txnQ1.size());
    assertEquals(1, txnQ2.size());
    context.commitTransaction();
    assertEquals(1, instance1.getQueue("testQueueOfferCommitSize").size());
    assertEquals(1, instance2.getQueue("testQueueOfferCommitSize").size());
    assertEquals("item", instance2.getQueue("testQueueOfferCommitSize").poll());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 43 with TransactionContext

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

the class QueueTestsFrom2X method testQueuePollRollbackSize.

@Test
public void testQueuePollRollbackSize() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = factory.newHazelcastInstance();
    factory.newHazelcastInstance();
    TransactionContext context = instance.newTransactionContext();
    IQueue<Object> queue = instance.getQueue("testQueuePollRollbackSize");
    queue.offer("item1");
    queue.offer("item2");
    assertEquals(2, queue.size());
    context.beginTransaction();
    TransactionalQueue txnQ1 = context.getQueue("testQueuePollRollbackSize");
    assertEquals("item1", txnQ1.poll());
    assertEquals(1, txnQ1.size());
    assertEquals(1, queue.size());
    context.rollbackTransaction();
    assertEquals(2, queue.size());
    assertEquals("item1", queue.poll());
    assertEquals("item2", queue.poll());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionalQueue(com.hazelcast.core.TransactionalQueue) TransactionContext(com.hazelcast.transaction.TransactionContext) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 44 with TransactionContext

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

the class QueueTestsFrom2X method testQueuePollCommitSize.

@Test
public void testQueuePollCommitSize() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    TransactionContext context = instance1.newTransactionContext();
    context.beginTransaction();
    TransactionalQueue<String> txnQ1 = context.getQueue("testQueuePollCommitSize");
    TransactionalQueue<String> txnQ2 = context.getQueue("testQueuePollCommitSize");
    txnQ1.offer("item1");
    txnQ1.offer("item2");
    assertEquals(2, txnQ1.size());
    assertEquals(2, txnQ2.size());
    assertEquals("item1", txnQ1.poll());
    assertEquals(1, txnQ1.size());
    assertEquals(1, txnQ2.size());
    context.commitTransaction();
    assertEquals(1, instance1.getQueue("testQueuePollCommitSize").size());
    assertEquals(1, instance2.getQueue("testQueuePollCommitSize").size());
    assertEquals("item2", instance1.getQueue("testQueuePollCommitSize").poll());
    assertEquals(0, instance1.getQueue("testQueuePollCommitSize").size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 45 with TransactionContext

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

the class TransactionQueueTest method testQueueWithMap.

@Test
public void testQueueWithMap() throws Exception {
    Config config = new Config();
    final int insCount = 4;
    final String queueName = "defQueue";
    final String mapName = "defMap";
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(insCount);
    final HazelcastInstance[] instances = factory.newInstances(config);
    instances[0].getMap(mapName).lock("lock1");
    final TransactionContext context = instances[1].newTransactionContext(new TransactionOptions().setTimeout(5, SECONDS));
    context.beginTransaction();
    try {
        boolean offered = context.getQueue(queueName).offer("item1");
        assertTrue(offered);
        context.getMap(mapName).put("lock1", "value1");
        fail();
    } catch (TransactionException ex) {
        // expected
        context.rollbackTransaction();
    }
    assertEquals(0, instances[0].getQueue(queueName).size());
    assertNull(instances[0].getMap(mapName).get("lock1"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionException(com.hazelcast.transaction.TransactionException) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) TransactionOptions(com.hazelcast.transaction.TransactionOptions) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TransactionContext (com.hazelcast.transaction.TransactionContext)280 Test (org.junit.Test)209 QuickTest (com.hazelcast.test.annotation.QuickTest)189 ParallelTest (com.hazelcast.test.annotation.ParallelTest)184 HazelcastInstance (com.hazelcast.core.HazelcastInstance)58 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)48 TransactionalMap (com.hazelcast.core.TransactionalMap)33 TransactionException (com.hazelcast.transaction.TransactionException)22 IMap (com.hazelcast.core.IMap)21 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)19 Config (com.hazelcast.config.Config)17 NightlyTest (com.hazelcast.test.annotation.NightlyTest)16 CountDownLatch (java.util.concurrent.CountDownLatch)14 XAException (javax.transaction.xa.XAException)14 TransactionalQueue (com.hazelcast.core.TransactionalQueue)13 TransactionalMultiMap (com.hazelcast.core.TransactionalMultiMap)9 HazelcastXAResource (com.hazelcast.transaction.HazelcastXAResource)9 ExecutionException (java.util.concurrent.ExecutionException)9 ISet (com.hazelcast.core.ISet)8 MultiMap (com.hazelcast.core.MultiMap)8