use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStoreTest method testQueueStoreFactory.
@Test
public void testQueueStoreFactory() {
String queueName = randomString();
Config config = getConfig();
QueueStoreFactory<VersionedObject<Integer>> queueStoreFactory = new SimpleQueueStoreFactory();
QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setEnabled(true).setFactoryImplementation(queueStoreFactory);
config.getQueueConfig(queueName).setQueueStoreConfig(queueStoreConfig);
HazelcastInstance instance = createHazelcastInstance(config);
IQueue<VersionedObject<Integer>> queue = instance.getQueue(queueName);
queue.add(new VersionedObject<>(1));
TestQueueStore testQueueStore = (TestQueueStore) queueStoreFactory.newQueueStore(queueName, null);
int size = testQueueStore.store.size();
assertEquals("Queue store size should be 1 but found " + size, 1, size);
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueAbstractTest method testToArray.
// ================ toArray ==============================
@Test
public void testToArray() {
for (int i = 0; i < 10; i++) {
queue.offer(new VersionedObject<>("item" + i, i));
}
Object[] array = queue.toArray();
for (int i = 0; i < array.length; i++) {
Object o = array[i];
int id = i++;
assertEquals(o, new VersionedObject<>("item" + id, id));
}
@SuppressWarnings("unchecked") VersionedObject<String>[] arr = queue.toArray(new VersionedObject[0]);
assertEquals(arr.length, 10);
for (int i = 0; i < arr.length; i++) {
Object o = arr[i];
int id = i++;
assertEquals(o, new VersionedObject<>("item" + id, id));
}
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStoreTest method testQueueStoreDrainTo.
@Test
public void testQueueStoreDrainTo() {
int maxSize = 10000;
// in the case of priority queue, all items are preloaded
TestQueueStore queueStore = comparatorClassName != null ? new TestQueueStore(0, 0, 0, 0, 0, 1) : new TestQueueStore(0, 0, 0, 0, 2 * maxSize, 0);
Config config = getConfigForDrainToTest(maxSize, 1, queueStore);
HazelcastInstance instance = createHazelcastInstance(config);
// initialize queue store with 2 * maxSize
for (int i = 0; i < maxSize * 2; i++) {
queueStore.store.put((long) i, new VersionedObject<>(i));
}
IQueue<VersionedObject<Object>> queue = instance.getQueue("testQueueStore");
List<Object> items = new ArrayList<>();
int count = queue.drainTo(items);
assertEquals(2 * maxSize, count);
assertOpenEventually(queueStore.latchLoad);
assertOpenEventually(queueStore.latchLoadAll);
}
Aggregations