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();
}
}
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());
}
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());
}
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());
}
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"));
}
Aggregations