use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class TransactionQueueTest method testTxnQueueOuterTransaction.
@Test(expected = TransactionNotActiveException.class)
public void testTxnQueueOuterTransaction() {
HazelcastInstance h1 = createHazelcastInstance();
TransactionContext transactionContext = h1.newTransactionContext();
transactionContext.beginTransaction();
TransactionalQueue<VersionedObject<Object>> queue = transactionContext.getQueue("testTxnQueueOuterTransaction");
queue.offer(new VersionedObject<>("item"));
transactionContext.commitTransaction();
queue.poll();
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class TransactionQueueTest method testOfferTake.
@Test
public void testOfferTake() throws InterruptedException {
Config config = getConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance owner = factory.newHazelcastInstance(config);
HazelcastInstance backup = factory.newHazelcastInstance(config);
String name = generateKeyOwnedBy(owner);
for (int i = 0; i < 1000; i++) {
TransactionContext ctx = owner.newTransactionContext();
ctx.beginTransaction();
TransactionalQueue<VersionedObject<Integer>> queue = ctx.getQueue(name);
queue.offer(new VersionedObject<>(1, 1));
queue.take();
ctx.commitTransaction();
}
assertEquals(0, owner.getQueue(name).size());
assertTransactionMapSize(owner, name, 0);
assertTransactionMapSize(backup, name, 0);
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class TransactionQueueTest method transactionShouldBeRolledBack_whenInitiatorTerminatesBeforeCommit.
@Test
public void transactionShouldBeRolledBack_whenInitiatorTerminatesBeforeCommit() {
Config config = getConfig();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
HazelcastInstance master = factory.newHazelcastInstance(config);
HazelcastInstance instance = factory.newHazelcastInstance(config);
warmUpPartitions(instance);
String name = generateKeyOwnedBy(master);
IQueue<VersionedObject<Integer>> queue = master.getQueue(name);
queue.offer(new VersionedObject<>(1));
waitAllForSafeState(master, instance);
TransactionOptions options = new TransactionOptions().setTransactionType(TransactionOptions.TransactionType.TWO_PHASE);
TransactionContext context = master.newTransactionContext(options);
context.beginTransaction();
TransactionalQueue<VersionedObject<Integer>> txQueue = context.getQueue(name);
txQueue.poll();
master.getLifecycleService().terminate();
IQueue<Integer> queue2 = instance.getQueue(name);
assertTrueEventually(() -> assertEquals(1, queue2.size()));
assertTrueAllTheTime(() -> assertEquals(1, queue2.size()), 3);
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class TransactionQueueTest method testListener_withOffer.
@Test
public void testListener_withOffer() {
HazelcastInstance hz = createHazelcastInstance();
String name = randomName();
IQueue<VersionedObject<String>> queue = hz.getQueue(name);
EventCountingItemListener listener = new EventCountingItemListener();
queue.addItemListener(listener, true);
hz.executeTransaction((TransactionalTask<Object>) ctx -> {
TransactionalQueue<VersionedObject<Object>> queue1 = ctx.getQueue(name);
return queue1.offer(new VersionedObject<>("item"));
});
assertTrueEventually(() -> assertEquals(1, listener.adds.get()));
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStatisticsTest method testPollOperationCount.
@Test
public void testPollOperationCount() throws Exception {
IQueue<VersionedObject<String>> queue = newQueue();
for (int i = 0; i < 30; i++) {
queue.offer(new VersionedObject<>("item" + i, i));
}
for (int i = 0; i < 10; i++) {
queue.remove();
}
for (int i = 0; i < 10; i++) {
queue.take();
}
for (int i = 0; i < 10; i++) {
queue.poll();
}
final LocalQueueStats stats = queue.getLocalQueueStats();
assertTrueEventually(() -> assertEquals(30, stats.getPollOperationCount()));
}
Aggregations