Search in sources :

Example 31 with VersionedObject

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

the class QueueStoreTest method testRemoveAll.

@Test
public void testRemoveAll() {
    int maxSize = 2000;
    Config config = getConfig();
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setStoreImplementation(new TestQueueStore()).setProperty("bulk-load", String.valueOf(200));
    config.getQueueConfig("testQueueStore").setMaxSize(maxSize).setQueueStoreConfig(queueStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    IQueue<VersionedObject<Integer>> queue = instance.getQueue("testQueueStore");
    for (int i = 0; i < maxSize; i++) {
        queue.add(new VersionedObject<>(i));
    }
    assertEquals(maxSize, queue.size());
    for (VersionedObject<Integer> o : queue) {
        queue.remove(o);
    }
    assertEquals(0, queue.size());
}
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 32 with VersionedObject

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

the class QueueTestsFrom2X method testQueuePollRollbackSize.

@Test
public void testQueuePollRollbackSize() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(getConfig());
    HazelcastInstance instance2 = factory.newHazelcastInstance(getConfig());
    waitAllForSafeState(instance1, instance2);
    TransactionContext context = instance1.newTransactionContext();
    IQueue<VersionedObject<String>> queue = instance1.getQueue("testQueuePollRollbackSize");
    queue.offer(new VersionedObject<>("item1", 1));
    queue.offer(new VersionedObject<>("item2", 2));
    assertEquals(2, queue.size());
    context.beginTransaction();
    TransactionalQueue<VersionedObject<String>> txnQ1 = context.getQueue("testQueuePollRollbackSize");
    assertEquals(new VersionedObject<>("item1", 1), txnQ1.poll());
    assertEquals(1, txnQ1.size());
    assertEquals(1, queue.size());
    context.rollbackTransaction();
    assertEquals(2, queue.size());
    assertEquals(new VersionedObject<>("item1", 1), queue.poll());
    assertEquals(new VersionedObject<>("item2", 2), queue.poll());
}
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)

Example 33 with VersionedObject

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

the class QueueTestsFrom2X method testQueuePollCommitSize.

@Test
public void testQueuePollCommitSize() {
    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("testQueuePollCommitSize");
    TransactionalQueue<VersionedObject<String>> txnQ2 = context.getQueue("testQueuePollCommitSize");
    txnQ1.offer(new VersionedObject<>("item1"));
    txnQ1.offer(new VersionedObject<>("item2"));
    assertEquals(2, txnQ1.size());
    assertEquals(2, txnQ2.size());
    assertEquals(new VersionedObject<>("item1"), txnQ1.poll());
    assertEquals(1, txnQ1.size());
    assertEquals(1, txnQ2.size());
    context.commitTransaction();
    assertEquals(1, instance1.getQueue("testQueuePollCommitSize").size());
    assertEquals(1, instance2.getQueue("testQueuePollCommitSize").size());
    assertEquals(new VersionedObject<>("item2"), instance1.getQueue("testQueuePollCommitSize").poll());
    assertEquals(0, instance1.getQueue("testQueuePollCommitSize").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)

Example 34 with VersionedObject

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

the class QueueTestsFrom2X method testQueueOfferCommitSize.

@Test
public void testQueueOfferCommitSize() {
    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("testQueueOfferCommitSize");
    TransactionalQueue<VersionedObject<String>> txnQ2 = context.getQueue("testQueueOfferCommitSize");
    txnQ1.offer(new VersionedObject<>("item"));
    assertEquals(1, txnQ1.size());
    assertEquals(1, txnQ2.size());
    context.commitTransaction();
    assertEquals(1, instance1.getQueue("testQueueOfferCommitSize").size());
    assertEquals(1, instance2.getQueue("testQueueOfferCommitSize").size());
    assertEquals(new VersionedObject<>("item"), instance2.getQueue("testQueueOfferCommitSize").poll());
}
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)

Example 35 with VersionedObject

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

the class QueueTestsFrom2X method testQueueAddAll.

@Test
public void testQueueAddAll() {
    HazelcastInstance instance = createHazelcastInstance();
    IQueue<VersionedObject<String>> queue = instance.getQueue("testQueueAddAll");
    @SuppressWarnings("unchecked") VersionedObject<String>[] items = new VersionedObject[] { new VersionedObject<>("one"), new VersionedObject<>("two"), new VersionedObject<>("three"), new VersionedObject<>("four") };
    queue.addAll(asList(items));
    assertEquals(4, queue.size());
    queue.addAll(asList(items));
    assertEquals(8, queue.size());
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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