use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStatisticsTest method testRejectedOfferOperationCount.
@Test
public void testRejectedOfferOperationCount() {
IQueue<VersionedObject<String>> queue = newQueue(30);
for (int i = 0; i < 30; i++) {
queue.offer(new VersionedObject<>("item" + i, i));
}
for (int i = 0; i < 10; i++) {
queue.offer(new VersionedObject<>("item" + i, i));
}
final LocalQueueStats stats = queue.getLocalQueueStats();
assertTrueEventually(() -> assertEquals(10, stats.getRejectedOfferOperationCount()));
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStatisticsTest method testAge.
@Test
public void testAge() throws InterruptedException {
IQueue<VersionedObject<String>> queue = newQueue();
queue.offer(new VersionedObject<>("maxAgeItem", 0));
queue.offer(new VersionedObject<>("minAgeItem", 1));
sleepAtLeastMillis(100);
queue.poll();
queue.poll();
QueueService queueService = getNode(instance).nodeEngine.getService(QueueService.SERVICE_NAME);
LocalQueueStats stats = queueService.getStats().get(queue.getName());
long maxAge = stats.getMaxAge();
long minAge = stats.getMinAge();
long expectedAverageAge = (maxAge + minAge) / 2;
long avgAge = stats.getAverageAge();
assertEquals(expectedAverageAge, avgAge);
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStatisticsTest method testEmptyPollOperationCount.
@Test
public void testEmptyPollOperationCount() {
IQueue<VersionedObject<String>> queue = newQueue();
for (int i = 0; i < 10; i++) {
queue.poll();
}
final LocalQueueStats stats = queue.getLocalQueueStats();
assertTrueEventually(() -> assertEquals(10, stats.getEmptyPollOperationCount()));
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueTestsFrom2X method testQueueItemListener.
@Test
public void testQueueItemListener() throws Exception {
HazelcastInstance instance = createHazelcastInstance();
IQueue<VersionedObject<String>> queue = instance.getQueue("testQueueItemListener");
VersionedObject<String> value = new VersionedObject<>("hello");
CountDownLatch latch = new CountDownLatch(8);
queue.addItemListener(new ItemListener<VersionedObject<String>>() {
public void itemAdded(ItemEvent<VersionedObject<String>> itemEvent) {
assertEquals(value, itemEvent.getItem());
latch.countDown();
}
public void itemRemoved(ItemEvent<VersionedObject<String>> itemEvent) {
assertEquals(value, itemEvent.getItem());
latch.countDown();
}
}, true);
queue.offer(value);
assertEquals(value, queue.poll());
queue.offer(value);
assertTrue(queue.remove(value));
queue.add(value);
assertEquals(value, queue.remove());
queue.put(value);
assertEquals(value, queue.take());
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertTrue(queue.isEmpty());
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueTestsFrom2X method testQueueOfferRollbackSize.
@Test
public void testQueueOfferRollbackSize() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance(getConfig());
HazelcastInstance instance2 = factory.newHazelcastInstance(getConfig());
waitAllForSafeState(instance1, instance2);
TransactionContext context = instance1.newTransactionContext();
context.beginTransaction();
TransactionalQueue<VersionedObject<String>> txnQ1 = context.getQueue("testQueueOfferRollbackSize");
TransactionalQueue<VersionedObject<String>> txnQ2 = context.getQueue("testQueueOfferRollbackSize");
txnQ1.offer(new VersionedObject<>("item"));
assertEquals(1, txnQ1.size());
assertEquals(1, txnQ2.size());
context.rollbackTransaction();
assertEquals(0, instance1.getQueue("testQueueOfferRollbackSize").size());
assertEquals(0, instance2.getQueue("testQueueOfferRollbackSize").size());
}
Aggregations