use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class QueueAdvancedTest method testPollNull.
@Test
public void testPollNull() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance[] instances = factory.newInstances();
HazelcastInstance h1 = instances[0];
HazelcastInstance h2 = instances[1];
IQueue q1 = h1.getQueue("default");
IQueue 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));
}
use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class TransactionQueueTest method testSingleQueueAtomicity.
@Test
public void testSingleQueueAtomicity() throws ExecutionException, InterruptedException {
final String name = randomString();
final int itemCount = 200;
final HazelcastInstance instance = createHazelcastInstance();
Future<Integer> f = spawn(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
IQueue<Object> queue = instance.getQueue(name);
queue.take();
return queue.size();
}
});
TransactionContext context = instance.newTransactionContext();
context.beginTransaction();
TransactionalQueue<Object> queue = context.getQueue(name);
for (int i = 0; i < itemCount; i++) {
queue.offer("item-" + i);
}
context.commitTransaction();
int size = f.get();
assertEquals(itemCount - 1, size);
}
use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class MBeanDestroyTest method testQueue.
@Test
public void testQueue() throws Exception {
IQueue queue = holder.getHz().getQueue("queue");
queue.size();
holder.assertMBeanExistEventually("IQueue", queue.getName());
destroyObjectAndAssert(queue, "IQueue");
}
use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class AllTest method loadQOperations.
private List<Runnable> loadQOperations() {
List<Runnable> operations = new ArrayList<Runnable>();
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
q.offer(new byte[100]);
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
try {
q.offer(new byte[100], 10, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
q.contains(new byte[100]);
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
q.isEmpty();
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
q.size();
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
q.remove(new byte[100]);
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
q.remainingCapacity();
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
q.poll();
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
q.add(new byte[100]);
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
try {
q.take();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}, 10);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
List list = new ArrayList();
for (int i = 0; i < 10; i++) {
list.add(new byte[100]);
}
q.addAll(list);
}
}, 1);
addOperation(operations, new Runnable() {
public void run() {
IQueue q = hazelcast.getQueue("myQ");
List list = new ArrayList();
q.drainTo(list);
}
}, 1);
return operations;
}
use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class ClientTxnQueueTest method testTransactionalOfferPoll.
@Test
public void testTransactionalOfferPoll() {
final String item = "offered";
final String queueName = randomString();
final IQueue queue = client.getQueue(queueName);
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
TransactionalQueue txnQueue = context.getQueue(queueName);
txnQueue.offer(item);
assertEquals(item, txnQueue.poll());
context.commitTransaction();
}
Aggregations