Search in sources :

Example 76 with VersionedObject

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

the class QueueStoreTest method testQueueStoreFactory.

@Test
public void testQueueStoreFactory() {
    String queueName = randomString();
    Config config = getConfig();
    QueueStoreFactory<VersionedObject<Integer>> queueStoreFactory = new SimpleQueueStoreFactory();
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setEnabled(true).setFactoryImplementation(queueStoreFactory);
    config.getQueueConfig(queueName).setQueueStoreConfig(queueStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IQueue<VersionedObject<Integer>> queue = instance.getQueue(queueName);
    queue.add(new VersionedObject<>(1));
    TestQueueStore testQueueStore = (TestQueueStore) queueStoreFactory.newQueueStore(queueName, null);
    int size = testQueueStore.store.size();
    assertEquals("Queue store size should be 1 but found " + size, 1, size);
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) 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 77 with VersionedObject

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

the class QueueAbstractTest method testToArray.

// ================ toArray ==============================
@Test
public void testToArray() {
    for (int i = 0; i < 10; i++) {
        queue.offer(new VersionedObject<>("item" + i, i));
    }
    Object[] array = queue.toArray();
    for (int i = 0; i < array.length; i++) {
        Object o = array[i];
        int id = i++;
        assertEquals(o, new VersionedObject<>("item" + id, id));
    }
    @SuppressWarnings("unchecked") VersionedObject<String>[] arr = queue.toArray(new VersionedObject[0]);
    assertEquals(arr.length, 10);
    for (int i = 0; i < arr.length; i++) {
        Object o = arr[i];
        int id = i++;
        assertEquals(o, new VersionedObject<>("item" + id, id));
    }
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) Test(org.junit.Test)

Example 78 with VersionedObject

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

the class QueueStoreTest method testQueueStoreDrainTo.

@Test
public void testQueueStoreDrainTo() {
    int maxSize = 10000;
    // in the case of priority queue, all items are preloaded
    TestQueueStore queueStore = comparatorClassName != null ? new TestQueueStore(0, 0, 0, 0, 0, 1) : new TestQueueStore(0, 0, 0, 0, 2 * maxSize, 0);
    Config config = getConfigForDrainToTest(maxSize, 1, queueStore);
    HazelcastInstance instance = createHazelcastInstance(config);
    // initialize queue store with 2 * maxSize
    for (int i = 0; i < maxSize * 2; i++) {
        queueStore.store.put((long) i, new VersionedObject<>(i));
    }
    IQueue<VersionedObject<Object>> queue = instance.getQueue("testQueueStore");
    List<Object> items = new ArrayList<>();
    int count = queue.drainTo(items);
    assertEquals(2 * maxSize, count);
    assertOpenEventually(queueStore.latchLoad);
    assertOpenEventually(queueStore.latchLoadAll);
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) ArrayList(java.util.ArrayList) 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