use of com.hazelcast.collection.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.collection.IQueue in project hazelcast by hazelcast.
the class ClientQueueTest method testTake_whenInterruptedWhileBlocking.
@Test(expected = InterruptedException.class)
public void testTake_whenInterruptedWhileBlocking() throws InterruptedException {
IQueue queue = client.getQueue(randomString());
interruptCurrentThread(2000);
queue.take();
}
use of com.hazelcast.collection.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.collection.IQueue in project hazelcast by hazelcast.
the class Invocation_BlockingTest method sync_testWaitingWithTimeout.
@Test
public void sync_testWaitingWithTimeout() throws InterruptedException {
final Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "6000");
final HazelcastInstance hz = createHazelcastInstance(config);
final CountDownLatch latch = new CountDownLatch(1);
final IQueue queue = hz.getQueue(randomName());
spawn(() -> {
try {
queue.poll(10, SECONDS);
latch.countDown();
} catch (Exception ignored) {
ignored.printStackTrace();
}
});
assertTrue("latch failed to open", latch.await(20, SECONDS));
}
use of com.hazelcast.collection.IQueue in project hazelcast by hazelcast.
the class Invocation_BlockingTest method sync_testWaitingIndefinitely.
@Test
public void sync_testWaitingIndefinitely() throws InterruptedException {
final Config config = new Config().setProperty(OPERATION_CALL_TIMEOUT_MILLIS.getName(), "6000");
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance[] instances = factory.newInstances(config);
// need to warm-up partitions, since waiting for queue backup can take up to 5 seconds
// and that may cause OperationTimeoutException with "No response for 4000 ms" error
warmUpPartitions(instances);
final String name = randomName();
IQueue queue = instances[0].getQueue(name);
final CountDownLatch latch = new CountDownLatch(1);
new Thread(() -> {
try {
// because max timeout=6000 we get timeout exception which we should not
instances[1].getQueue(name).take();
latch.countDown();
} catch (Exception ignored) {
ignored.printStackTrace();
}
}).start();
// wait for enough time which is greater than max-timeout (6000)
sleepSeconds(10);
queue.offer("item");
assertTrue(latch.await(20, SECONDS));
}
Aggregations