Search in sources :

Example 46 with VersionedObject

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

the class QueueAdvancedTest method testRemoveBackup.

@Test
public void testRemoveBackup() {
    HazelcastInstance[] instances = createHazelcastInstances();
    HazelcastInstance instance1 = instances[0];
    HazelcastInstance instance2 = instances[1];
    String name = generateKeyOwnedBy(instance1);
    IQueue<VersionedObject<String>> queue1 = instance1.getQueue(name);
    IQueue<VersionedObject<String>> queue2 = instance2.getQueue(name);
    for (int i = 0; i < 4; i++) {
        queue1.offer(new VersionedObject<>("item" + i, i));
    }
    assertSizeEventually(4, queue2);
    assertIterableEquals(queue2, new VersionedObject<>("item0", 0), new VersionedObject<>("item1", 1), new VersionedObject<>("item2", 2), new VersionedObject<>("item3", 3));
    queue1.remove(new VersionedObject<>("item0", 0));
    queue1.remove(new VersionedObject<>("item1", 1));
    instance1.shutdown();
    assertSizeEventually(2, queue2);
    assertIterableEquals(queue2, new VersionedObject<>("item2", 2), new VersionedObject<>("item3", 3));
}
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 47 with VersionedObject

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

the class QueueAdvancedTest method testQueueAfterShutdown_switchedInstanceOrder.

@Test
public void testQueueAfterShutdown_switchedInstanceOrder() throws Exception {
    HazelcastInstance[] instances = createHazelcastInstanceFactory(2).newInstances(getConfig());
    HazelcastInstance h1 = instances[0];
    HazelcastInstance h2 = instances[1];
    IQueue<VersionedObject<String>> q1 = h1.getQueue("default");
    IQueue<VersionedObject<String>> q2 = h2.getQueue("default");
    q1.offer(new VersionedObject<>("item"));
    assertEquals(1, q1.size());
    assertEquals(1, q2.size());
    assertEquals(new VersionedObject<>("item"), q2.take());
    assertEquals(0, q1.size());
    assertEquals(0, q2.size());
    h2.getLifecycleService().shutdown();
    assertEquals(0, q1.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)

Example 48 with VersionedObject

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

the class QueueAdvancedTest method testPutInterruption.

@Test
public void testPutInterruption() {
    Config config = getConfig().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "10000");
    config.getQueueConfig("default").setMaxSize(1);
    HazelcastInstance instance = createHazelcastInstance(config);
    IQueue<VersionedObject<String>> queue = instance.getQueue(randomName());
    assertTrue("Expected queue.offer() to succeed", queue.offer(new VersionedObject<>("item")));
    CountDownLatch putLatch = new CountDownLatch(1);
    TestThread thread = new TestThread() {

        @Override
        public void doRun() throws Throwable {
            putLatch.countDown();
            queue.put(new VersionedObject<>("item"));
        }
    };
    thread.start();
    assertOpenEventually(putLatch);
    thread.interrupt();
    thread.assertFailsEventually(InterruptedException.class);
}
Also used : VersionedObject(com.hazelcast.collection.impl.queue.model.VersionedObject) HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestThread(com.hazelcast.test.TestThread) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) CountDownLatch(java.util.concurrent.CountDownLatch) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 49 with VersionedObject

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

the class QueueAdvancedTest method queueEntriesShouldBeConsistentAfterShutdown_switchedInstanceOrder.

@Test
public void queueEntriesShouldBeConsistentAfterShutdown_switchedInstanceOrder() {
    HazelcastInstance[] instances = createHazelcastInstanceFactory(2).newInstances(getConfig());
    HazelcastInstance h1 = instances[0];
    HazelcastInstance h2 = instances[1];
    Queue<VersionedObject<String>> q1 = h1.getQueue("q");
    Queue<VersionedObject<String>> q2 = h2.getQueue("q");
    for (int i = 0; i < 5; i++) {
        q2.offer(new VersionedObject<>("item" + i, i));
    }
    assertEquals(5, q1.size());
    assertEquals(5, q2.size());
    assertEquals(new VersionedObject<>("item0", 0), q1.poll());
    assertEquals(new VersionedObject<>("item1", 1), q1.poll());
    assertEquals(new VersionedObject<>("item2", 2), q1.poll());
    assertSizeEventually(2, q1);
    assertSizeEventually(2, q2);
    h2.getLifecycleService().shutdown();
    assertSizeEventually(2, q1);
}
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 50 with VersionedObject

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

the class QueueAdvancedTest method testPollNull.

@Test
public void testPollNull() throws Exception {
    HazelcastInstance[] instances = createHazelcastInstanceFactory(2).newInstances(getConfig());
    HazelcastInstance h1 = instances[0];
    HazelcastInstance h2 = instances[1];
    IQueue<VersionedObject<String>> q1 = h1.getQueue("default");
    IQueue<VersionedObject<String>> q2 = h2.getQueue("default");
    for (int i = 0; i < 100; i++) {
        assertNull(q1.poll());
        assertNull(q2.poll());
    }
    assertNull(q1.poll(2, SECONDS));
    assertNull(q2.poll(2, SECONDS));
}
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