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));
}
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());
}
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);
}
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);
}
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));
}
Aggregations