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