Search in sources :

Example 16 with VersionedObject

use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.

the class QueueStoreTest method testQueueStore_withBinaryModeOn.

@Test
public void testQueueStore_withBinaryModeOn() {
    String queueName = randomString();
    Config config = getConfig();
    QueueStoreConfig queueStoreConfig = getBinaryQueueStoreConfig();
    config.getQueueConfig(queueName).setQueueStoreConfig(queueStoreConfig);
    HazelcastInstance node = createHazelcastInstance(config);
    IQueue<VersionedObject<Integer>> queue = node.getQueue(queueName);
    queue.add(new VersionedObject<>(1));
    queue.add(new VersionedObject<>(2));
    queue.add(new VersionedObject<>(3));
    // this triggers bulk loading
    VersionedObject<Integer> value = queue.peek();
    assertEquals(new VersionedObject<>(1), value);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 17 with VersionedObject

use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.

the class QueueStatisticsTest method testOtherOperationCount.

@Test
public void testOtherOperationCount() {
    IQueue<VersionedObject<String>> queue = newQueue();
    for (int i = 0; i < 30; i++) {
        queue.offer(new VersionedObject<>("item" + i, i));
    }
    ArrayList<VersionedObject<String>> list = new ArrayList<>();
    queue.drainTo(list);
    queue.addAll(list);
    queue.removeAll(list);
    final LocalQueueStats stats = queue.getLocalQueueStats();
    assertTrueEventually(() -> assertEquals(3, stats.getOtherOperationsCount()));
}
Also used : LocalQueueStats(com.hazelcast.collection.LocalQueueStats) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) ArrayList(java.util.ArrayList) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 18 with VersionedObject

use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.

the class QueueStatisticsTest method testOfferOperationCount.

@Test
public void testOfferOperationCount() throws Exception {
    IQueue<VersionedObject<String>> queue = newQueue();
    for (int i = 0; i < 10; i++) {
        queue.offer(new VersionedObject<>("item" + i, i));
    }
    for (int i = 0; i < 10; i++) {
        queue.add(new VersionedObject<>("item" + i, i));
    }
    for (int i = 0; i < 10; i++) {
        queue.put(new VersionedObject<>("item" + i, i));
    }
    final LocalQueueStats stats = queue.getLocalQueueStats();
    assertTrueEventually(() -> assertEquals(30, stats.getOfferOperationCount()));
}
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 19 with VersionedObject

use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.

the class QueueStatisticsTest method testEventOperationCount.

@Test
public void testEventOperationCount() {
    IQueue<VersionedObject<String>> queue = newQueue();
    TestListener listener = new TestListener(30);
    queue.addItemListener(listener, true);
    for (int i = 0; i < 30; i++) {
        queue.offer(new VersionedObject<>("item" + i, i));
    }
    for (int i = 0; i < 30; i++) {
        queue.poll();
    }
    final LocalQueueStats stats = queue.getLocalQueueStats();
    assertOpenEventually(listener.addedLatch);
    assertOpenEventually(listener.removedLatch);
    assertTrueEventually(() -> assertEquals(60, stats.getEventOperationCount()));
}
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 20 with VersionedObject

use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.

the class QueueStatisticsTest method testItemCount.

@Test
public void testItemCount() {
    IQueue<VersionedObject<String>> queue = newQueue();
    int items = 20;
    for (int i = 0; i < items; i++) {
        queue.offer(new VersionedObject<>("item" + i, i));
    }
    LocalQueueStats stats = queue.getLocalQueueStats();
    assertEquals(20, stats.getOwnedItemCount());
    assertEquals(0, stats.getBackupItemCount());
}
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)

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