Search in sources :

Example 61 with VersionedObject

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()));
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 62 with VersionedObject

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);
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 63 with VersionedObject

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()));
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 64 with VersionedObject

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());
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 65 with VersionedObject

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());
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

VersionedObject (com.hazelcast.collection.impl.queue.model.VersionedObject)78 Test (org.junit.Test)77 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)76 QuickTest (com.hazelcast.test.annotation.QuickTest)76 HazelcastInstance (com.hazelcast.core.HazelcastInstance)68 TransactionContext (com.hazelcast.transaction.TransactionContext)25 Config (com.hazelcast.config.Config)23 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)19 CountDownLatch (java.util.concurrent.CountDownLatch)16 QueueStoreConfig (com.hazelcast.config.QueueStoreConfig)10 LocalQueueStats (com.hazelcast.collection.LocalQueueStats)8 ArrayList (java.util.ArrayList)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 TestThread (com.hazelcast.test.TestThread)5 TransactionException (com.hazelcast.transaction.TransactionException)4 ItemListenerConfig (com.hazelcast.config.ItemListenerConfig)3 ListenerConfig (com.hazelcast.config.ListenerConfig)3 QueueConfig (com.hazelcast.config.QueueConfig)3 HazelcastInstanceNotActiveException (com.hazelcast.core.HazelcastInstanceNotActiveException)3 ExecutorService (java.util.concurrent.ExecutorService)3