use of com.hazelcast.core.IQueue in project orientdb by orientechnologies.
the class HazelcastQueueThroughputTest method main.
public static void main(String[] args) throws InterruptedException {
final HazelcastInstance hz = Hazelcast.newHazelcastInstance();
final IQueue[] ring = new IQueue[QUEUE_RING_SIZE];
for (int q = 0; q < QUEUE_RING_SIZE; ++q) ring[q] = hz.getQueue("test" + q);
final long start = System.currentTimeMillis();
long lastLap = start;
Thread t = new Thread() {
long lastLap = start;
@Override
public void run() {
int senderQueueIndex = 0;
System.out.println((System.currentTimeMillis() - lastLap) + " Start receiving msgs");
for (int i = 1; i < TOTAL + 1; ++i) {
try {
if (senderQueueIndex >= QUEUE_RING_SIZE)
senderQueueIndex = 0;
Object msg = ring[senderQueueIndex++].take();
if (i % LAP == 0) {
final long lapTime = System.currentTimeMillis() - lastLap;
System.out.printf("<- messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime));
lastLap = System.currentTimeMillis();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
};
t.start();
int receiverQueueIndex = 0;
System.out.println((System.currentTimeMillis() - lastLap) + " Start sending msgs");
for (int i = 1; i < TOTAL + 1; ++i) {
if (receiverQueueIndex >= QUEUE_RING_SIZE)
receiverQueueIndex = 0;
ring[receiverQueueIndex++].offer(i);
if (i % LAP == 0) {
final long lapTime = System.currentTimeMillis() - lastLap;
System.out.printf("-> messages %d/%d = %dms (%f msg/sec)\n", i, TOTAL, lapTime, ((float) LAP * 1000 / lapTime));
lastLap = System.currentTimeMillis();
}
}
System.out.println((System.currentTimeMillis() - start) + " Finished sending msgs");
t.join();
System.out.println((System.currentTimeMillis() - start) + " Test finished");
}
use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class ClientQueueTest method testPoll_whenInterruptedWhileBlocking.
@Test(expected = InterruptedException.class)
public void testPoll_whenInterruptedWhileBlocking() throws InterruptedException {
IQueue queue = client.getQueue(randomString());
interruptCurrentThread(2000);
queue.poll(1, TimeUnit.MINUTES);
}
use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class ClientTxnQueueTest method testTransactionalOfferRoleBack.
@Test
public void testTransactionalOfferRoleBack() {
final String name = randomString();
final IQueue queue = client.getQueue(name);
final TransactionContext context = client.newTransactionContext();
context.beginTransaction();
TransactionalQueue<String> qTxn = context.getQueue(name);
qTxn.offer("ITEM");
context.rollbackTransaction();
assertEquals(0, queue.size());
}
use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class PartitionControlledIdTest method testQueue.
@Test
public void testQueue() throws Exception {
String partitionKey = "hazelcast";
HazelcastInstance hz = getHazelcastInstance(partitionKey);
IQueue queue = hz.getQueue("queue@" + partitionKey);
queue.add("");
assertEquals("queue@" + partitionKey, queue.getName());
assertEquals(partitionKey, queue.getPartitionKey());
QueueService service = getNodeEngine(hz).getService(QueueService.SERVICE_NAME);
assertTrue(service.containsQueue(queue.getName()));
}
use of com.hazelcast.core.IQueue in project hazelcast by hazelcast.
the class HazelcastOSGiInstanceTest method getQueueCalledSuccessfullyOverOSGiInstance.
@Test
public void getQueueCalledSuccessfullyOverOSGiInstance() {
IQueue mockQueue = mock(IQueue.class);
HazelcastInstance mockHazelcastInstance = mock(HazelcastInstance.class);
HazelcastOSGiInstance hazelcastOSGiInstance = HazelcastOSGiTestUtil.createHazelcastOSGiInstance(mockHazelcastInstance);
when(mockHazelcastInstance.getQueue("my-queue")).thenReturn(mockQueue);
assertEquals(mockQueue, hazelcastOSGiInstance.getQueue("my-queue"));
verify(mockHazelcastInstance).getQueue("my-queue");
}
Aggregations