Search in sources :

Example 11 with VersionedObject

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

the class QueueStoreTest method testIssue1401QueueStoreWithTxnPoll.

@Test
public void testIssue1401QueueStoreWithTxnPoll() {
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setStoreImplementation(new MyQueueStore()).setEnabled(true).setProperty("binary", "false").setProperty("memory-limit", "0").setProperty("bulk-load", "100");
    Config config = getConfig();
    config.getQueueConfig("test").setMaxSize(10).setQueueStoreConfig(queueStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    for (int i = 0; i < 10; i++) {
        TransactionContext context = instance.newTransactionContext();
        context.beginTransaction();
        TransactionalQueue<VersionedObject<String>> queue = context.getQueue("test");
        VersionedObject<String> queueData = queue.poll();
        assertNotNull(queueData);
        context.commitTransaction();
    }
}
Also used : 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) TransactionContext(com.hazelcast.transaction.TransactionContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 12 with VersionedObject

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

the class QueueStoreTest method testQueueStoreFactoryIsNotInitialized_whenDisabledInQueueStoreConfig.

@Test
public void testQueueStoreFactoryIsNotInitialized_whenDisabledInQueueStoreConfig() {
    String queueName = randomString();
    Config config = getConfig();
    QueueStoreFactory<VersionedObject<Integer>> queueStoreFactory = new SimpleQueueStoreFactory();
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setEnabled(false).setFactoryImplementation(queueStoreFactory);
    config.getQueueConfig(queueName).setQueueStoreConfig(queueStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.getQueue(queueName).add(new VersionedObject<>(1));
    TestQueueStore testQueueStore = (TestQueueStore) queueStoreFactory.newQueueStore(queueName, null);
    int size = testQueueStore.store.size();
    assertEquals("Expected no queue store operation since we disabled it in QueueStoreConfig, but found initialized ", 0, 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 13 with VersionedObject

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

the class QueueStoreTest method testQueueStore.

@Test
public void testQueueStore() throws Exception {
    Config config = getConfig();
    int maxSize = 2000;
    TestQueueStore queueStore = new TestQueueStore(1000, 0, 2000, 0, 0, 0, 1);
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setStoreImplementation(queueStore);
    config.getQueueConfig("testQueueStore").setMaxSize(maxSize).setQueueStoreConfig(queueStoreConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    for (int i = 0; i < maxSize / 2; i++) {
        queueStore.store.put((long) i, new VersionedObject<>(i, i));
    }
    IQueue<VersionedObject<Integer>> queue = instance.getQueue("testQueueStore");
    for (int i = 0; i < maxSize / 2; i++) {
        int id = i + maxSize / 2;
        queue.offer(new VersionedObject<>(id, id));
    }
    instance.shutdown();
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    IQueue<VersionedObject<Integer>> queue2 = instance2.getQueue("testQueueStore");
    assertEquals(maxSize, queue2.size());
    assertEquals(maxSize, queueStore.store.size());
    for (int i = 0; i < maxSize; i++) {
        assertEquals(new VersionedObject<>(i, i), queue2.poll());
    }
    queueStore.assertAwait(3);
}
Also used : 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) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 14 with VersionedObject

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

the class QueueStoreTest method testQueueStoreDrainTo_whenBulkLoadEnabled.

@Test
public void testQueueStoreDrainTo_whenBulkLoadEnabled() {
    int maxSize = 10000;
    int queueStoreSize = 2 * maxSize;
    int bulkLoadSize = 10;
    // in the case of priority queue, all items are preloaded
    // so we can sort them
    TestQueueStore queueStore = comparatorClassName != null ? new TestQueueStore(0, 0, 0, 0, 0, 1) : new TestQueueStore(0, 0, 0, 0, 0, queueStoreSize / bulkLoadSize);
    Config config = getConfigForDrainToTest(maxSize, bulkLoadSize, queueStore);
    HazelcastInstance instance = createHazelcastInstance(config);
    // setup queue store with 2 * maxSize
    for (int i = 0; i < queueStoreSize; i++) {
        queueStore.store.put((long) i, new VersionedObject<>(i, i));
    }
    IQueue<VersionedObject<Integer>> queue = instance.getQueue("testQueueStore");
    List<VersionedObject<Integer>> items = new ArrayList<>();
    int count = queue.drainTo(items);
    assertEquals(queueStoreSize, count);
    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) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 15 with VersionedObject

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

the class QueueStoreTest method testStoreId_whenNodeDown.

@Test
public void testStoreId_whenNodeDown() {
    Config config = getConfig();
    IdCheckerQueueStore idCheckerQueueStore = new IdCheckerQueueStore();
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setEnabled(true).setStoreImplementation(idCheckerQueueStore);
    config.getQueueConfig("default").setQueueStoreConfig(queueStoreConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    String name = generateKeyOwnedBy(instance1);
    IQueue<VersionedObject<String>> queue = instance2.getQueue(name);
    queue.offer(new VersionedObject<>(randomString()));
    queue.offer(new VersionedObject<>(randomString()));
    queue.offer(new VersionedObject<>(randomString()));
    instance1.shutdown();
    queue.offer(new VersionedObject<>(randomString()));
}
Also used : 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) 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