use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStoreTest method testIssue1401QueueStoreWithTxnPoll.
@Test
public void testIssue1401QueueStoreWithTxnPoll() {
QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setStoreImplementation(new MyQueueStore()).setEnabled(true).setProperty("binary", "false").setProperty("memory-limit", "0").setProperty("bulk-load", "100");
Config config = getConfig();
config.getQueueConfig("test").setMaxSize(10).setQueueStoreConfig(queueStoreConfig);
HazelcastInstance instance = createHazelcastInstance(config);
for (int i = 0; i < 10; i++) {
TransactionContext context = instance.newTransactionContext();
context.beginTransaction();
TransactionalQueue<VersionedObject<String>> queue = context.getQueue("test");
VersionedObject<String> queueData = queue.poll();
assertNotNull(queueData);
context.commitTransaction();
}
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStoreTest method testQueueStoreFactoryIsNotInitialized_whenDisabledInQueueStoreConfig.
@Test
public void testQueueStoreFactoryIsNotInitialized_whenDisabledInQueueStoreConfig() {
String queueName = randomString();
Config config = getConfig();
QueueStoreFactory<VersionedObject<Integer>> queueStoreFactory = new SimpleQueueStoreFactory();
QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setEnabled(false).setFactoryImplementation(queueStoreFactory);
config.getQueueConfig(queueName).setQueueStoreConfig(queueStoreConfig);
HazelcastInstance instance = createHazelcastInstance(config);
instance.getQueue(queueName).add(new VersionedObject<>(1));
TestQueueStore testQueueStore = (TestQueueStore) queueStoreFactory.newQueueStore(queueName, null);
int size = testQueueStore.store.size();
assertEquals("Expected no queue store operation since we disabled it in QueueStoreConfig, but found initialized ", 0, size);
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStoreTest method testQueueStore.
@Test
public void testQueueStore() throws Exception {
Config config = getConfig();
int maxSize = 2000;
TestQueueStore queueStore = new TestQueueStore(1000, 0, 2000, 0, 0, 0, 1);
QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setStoreImplementation(queueStore);
config.getQueueConfig("testQueueStore").setMaxSize(maxSize).setQueueStoreConfig(queueStoreConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = factory.newHazelcastInstance(config);
for (int i = 0; i < maxSize / 2; i++) {
queueStore.store.put((long) i, new VersionedObject<>(i, i));
}
IQueue<VersionedObject<Integer>> queue = instance.getQueue("testQueueStore");
for (int i = 0; i < maxSize / 2; i++) {
int id = i + maxSize / 2;
queue.offer(new VersionedObject<>(id, id));
}
instance.shutdown();
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
IQueue<VersionedObject<Integer>> queue2 = instance2.getQueue("testQueueStore");
assertEquals(maxSize, queue2.size());
assertEquals(maxSize, queueStore.store.size());
for (int i = 0; i < maxSize; i++) {
assertEquals(new VersionedObject<>(i, i), queue2.poll());
}
queueStore.assertAwait(3);
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStoreTest method testQueueStoreDrainTo_whenBulkLoadEnabled.
@Test
public void testQueueStoreDrainTo_whenBulkLoadEnabled() {
int maxSize = 10000;
int queueStoreSize = 2 * maxSize;
int bulkLoadSize = 10;
// in the case of priority queue, all items are preloaded
// so we can sort them
TestQueueStore queueStore = comparatorClassName != null ? new TestQueueStore(0, 0, 0, 0, 0, 1) : new TestQueueStore(0, 0, 0, 0, 0, queueStoreSize / bulkLoadSize);
Config config = getConfigForDrainToTest(maxSize, bulkLoadSize, queueStore);
HazelcastInstance instance = createHazelcastInstance(config);
// setup queue store with 2 * maxSize
for (int i = 0; i < queueStoreSize; i++) {
queueStore.store.put((long) i, new VersionedObject<>(i, i));
}
IQueue<VersionedObject<Integer>> queue = instance.getQueue("testQueueStore");
List<VersionedObject<Integer>> items = new ArrayList<>();
int count = queue.drainTo(items);
assertEquals(queueStoreSize, count);
assertOpenEventually(queueStore.latchLoadAll);
}
use of com.hazelcast.collection.impl.queue.model.VersionedObject in project hazelcast by hazelcast.
the class QueueStoreTest method testStoreId_whenNodeDown.
@Test
public void testStoreId_whenNodeDown() {
Config config = getConfig();
IdCheckerQueueStore idCheckerQueueStore = new IdCheckerQueueStore();
QueueStoreConfig queueStoreConfig = new QueueStoreConfig().setEnabled(true).setStoreImplementation(idCheckerQueueStore);
config.getQueueConfig("default").setQueueStoreConfig(queueStoreConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
String name = generateKeyOwnedBy(instance1);
IQueue<VersionedObject<String>> queue = instance2.getQueue(name);
queue.offer(new VersionedObject<>(randomString()));
queue.offer(new VersionedObject<>(randomString()));
queue.offer(new VersionedObject<>(randomString()));
instance1.shutdown();
queue.offer(new VersionedObject<>(randomString()));
}
Aggregations