Search in sources :

Example 71 with VersionedObject

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

the class QueueTestsFrom2X method testQueueContainsAll.

@Test
public void testQueueContainsAll() {
    HazelcastInstance instance = createHazelcastInstance();
    IQueue<VersionedObject<String>> queue = instance.getQueue("testQueueContainsAll");
    List<VersionedObject<String>> items = Arrays.asList(new VersionedObject<>("one"), new VersionedObject<>("two"), new VersionedObject<>("three"), new VersionedObject<>("four"));
    queue.addAll(items);
    assertContainsAll(queue, items);
}
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)

Example 72 with VersionedObject

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

the class QueueTestsFrom2X method issue99TestQueueTakeAndDuringRollback.

/**
 * Github issue #99
 */
@Test
public void issue99TestQueueTakeAndDuringRollback() throws Exception {
    String name = "issue99TestQueueTakeAndDuringRollback";
    HazelcastInstance hz = createHazelcastInstance();
    IQueue<VersionedObject<String>> q = hz.getQueue(name);
    q.offer(new VersionedObject<>("item"));
    Thread t1 = new Thread(() -> {
        TransactionContext context = hz.newTransactionContext();
        try {
            context.beginTransaction();
            context.getQueue(name).poll(1, TimeUnit.DAYS);
            sleep(1000);
            throw new RuntimeException();
        } catch (InterruptedException e) {
            fail(e.getMessage());
        } catch (Exception e) {
            context.rollbackTransaction();
        }
    });
    AtomicBoolean fail = new AtomicBoolean(false);
    Thread t2 = new Thread(() -> {
        TransactionContext context = hz.newTransactionContext();
        try {
            context.beginTransaction();
            context.getQueue(name).poll(1, TimeUnit.DAYS);
            context.commitTransaction();
            fail.set(false);
        } catch (Exception e) {
            context.rollbackTransaction();
            e.printStackTrace();
            fail.set(true);
        }
    });
    t1.start();
    sleep(500);
    t2.start();
    t2.join();
    assertFalse("Queue take failed after rollback!", fail.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 73 with VersionedObject

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

the class QueueTestsFrom2X method issue370.

@Test
public void issue370() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance h1 = factory.newHazelcastInstance(getConfig());
    HazelcastInstance h2 = factory.newHazelcastInstance(getConfig());
    waitAllForSafeState(h1, h2);
    Queue<VersionedObject<String>> q1 = h1.getQueue("q");
    Queue<VersionedObject<String>> q2 = h2.getQueue("q");
    for (int i = 0; i < 5; i++) {
        q1.offer(new VersionedObject<>("item" + i, i));
    }
    assertEquals(5, q1.size());
    assertEquals(5, q2.size());
    assertEquals(new VersionedObject<>("item0", 0), q2.poll());
    assertEquals(new VersionedObject<>("item1", 1), q2.poll());
    assertEquals(new VersionedObject<>("item2", 2), q2.poll());
    assertEquals(2, q1.size());
    assertEquals(2, q2.size());
    h1.shutdown();
    assertEquals(2, q2.size());
    HazelcastInstance h3 = factory.newHazelcastInstance(getConfig());
    waitAllForSafeState(h2, h3);
    Queue<VersionedObject<String>> q3 = h3.getQueue("q");
    assertEquals(2, q2.size());
    assertEquals(2, q3.size());
    h2.shutdown();
    assertEquals(2, q3.size());
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with VersionedObject

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

the class QueueTestsFrom2X method testQueueOrderAfterPollRollback.

@Test
public void testQueueOrderAfterPollRollback() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(getConfig());
    HazelcastInstance instance2 = factory.newHazelcastInstance(getConfig());
    waitAllForSafeState(instance1, instance2);
    TransactionContext context = instance1.newTransactionContext();
    IQueue<VersionedObject<Integer>> queue = instance1.getQueue("testQueueOrderAfterPollRollback");
    context.beginTransaction();
    TransactionalQueue<VersionedObject<Integer>> txn1 = context.getQueue("testQueueOrderAfterPollRollback");
    txn1.offer(new VersionedObject<>(1, 1));
    txn1.offer(new VersionedObject<>(2, 2));
    txn1.offer(new VersionedObject<>(3, 3));
    context.commitTransaction();
    assertEquals(3, queue.size());
    TransactionContext context2 = instance2.newTransactionContext();
    context2.beginTransaction();
    TransactionalQueue<VersionedObject<Integer>> txn2 = context2.getQueue("testQueueOrderAfterPollRollback");
    assertEquals(new VersionedObject<>(1, 1), txn2.poll());
    context2.rollbackTransaction();
    assertEquals(new VersionedObject<>(1, 1), queue.poll());
    assertEquals(new VersionedObject<>(2, 2), queue.poll());
    assertEquals(new VersionedObject<>(3, 3), 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 75 with VersionedObject

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

the class QueueStoreTest method testQueueStoreLoadMoreThanMaxSize.

@Test
public void testQueueStoreLoadMoreThanMaxSize() {
    Config config = getConfig();
    int maxSize = 2000;
    TestQueueStore queueStore = new TestQueueStore();
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setStoreImplementation(queueStore);
    config.getQueueConfig("testQueueStore").setMaxSize(maxSize).setQueueStoreConfig(queueStoreConfig);
    HazelcastInstance instance = createHazelcastInstance(config);
    for (int i = 0; i < maxSize * 2; i++) {
        queueStore.store.put((long) i, new VersionedObject<>(i, i));
    }
    IQueue<Object> queue = instance.getQueue("testQueueStore");
    assertEquals("Queue Size should be equal to max size", maxSize, queue.size());
}
Also used : QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) 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