use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QueueAdvancedTest method testShutdown.
@Test
public void testShutdown() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance[] instances = factory.newInstances();
HazelcastInstance h1 = instances[0];
HazelcastInstance h2 = instances[1];
warmUpPartitions(h2, h1);
IQueue<String> q1 = h1.getQueue("default");
IQueue<String> q2 = h2.getQueue("default");
for (int i = 0; i < 40; i++) {
assertTrue("Expected q1.offer() to succeed", q1.offer("item" + i, 100, SECONDS));
}
h1.getLifecycleService().shutdown();
for (int i = 40; i < 100; i++) {
assertTrue("Expected q2.offer() to succeed", q2.offer("item" + i, 100, SECONDS));
}
for (int i = 0; i < 100; i++) {
assertEquals("item" + i, q2.poll());
}
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QueueAdvancedTest method testTake.
@Test
public void testTake() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance[] instances = factory.newInstances();
HazelcastInstance h1 = instances[0];
HazelcastInstance h2 = instances[1];
final IQueue<String> q1 = h1.getQueue("default");
final IQueue<String> q2 = h2.getQueue("default");
final CountDownLatch offerLatch = new CountDownLatch(2 * 100);
new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
for (int i = 0; i < 100; i++) {
if (q1.offer("item")) {
offerLatch.countDown();
}
if (q2.offer("item")) {
offerLatch.countDown();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}).start();
assertOpenEventually(offerLatch);
ExecutorService es = Executors.newFixedThreadPool(50);
final CountDownLatch latch = new CountDownLatch(200);
for (int i = 0; i < 100; i++) {
es.execute(new Runnable() {
@Override
public void run() {
try {
if ("item".equals(q1.take())) {
latch.countDown();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
es.execute(new Runnable() {
@Override
public void run() {
try {
if ("item".equals(q2.take())) {
latch.countDown();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}
assertOpenEventually(latch);
es.shutdown();
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QueueTestsFrom2X method testQueueOfferCommitSize.
@Test
public void testQueueOfferCommitSize() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance();
HazelcastInstance instance2 = factory.newHazelcastInstance();
TransactionContext context = instance1.newTransactionContext();
context.beginTransaction();
TransactionalQueue<String> txnQ1 = context.getQueue("testQueueOfferCommitSize");
TransactionalQueue<String> txnQ2 = context.getQueue("testQueueOfferCommitSize");
txnQ1.offer("item");
assertEquals(1, txnQ1.size());
assertEquals(1, txnQ2.size());
context.commitTransaction();
assertEquals(1, instance1.getQueue("testQueueOfferCommitSize").size());
assertEquals(1, instance2.getQueue("testQueueOfferCommitSize").size());
assertEquals("item", instance2.getQueue("testQueueOfferCommitSize").poll());
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QueueTestsFrom2X method testInterruption.
@Test
@Ignore
public void testInterruption() throws Exception {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
HazelcastInstance instance = factory.newHazelcastInstance(new Config());
final IQueue<String> queue = instance.getQueue("testInterruption");
final CountDownLatch latch = new CountDownLatch(1);
Thread thread = new Thread(new Runnable() {
public void run() {
try {
queue.poll(5, TimeUnit.SECONDS);
fail();
} catch (InterruptedException e) {
latch.countDown();
}
}
});
thread.start();
sleep(2000);
thread.interrupt();
assertTrue(latch.await(100, TimeUnit.SECONDS));
queue.offer("message");
assertEquals(1, queue.size());
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QueueTestsFrom2X method testQueuePollRollbackSize.
@Test
public void testQueuePollRollbackSize() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = factory.newHazelcastInstance();
factory.newHazelcastInstance();
TransactionContext context = instance.newTransactionContext();
IQueue<Object> queue = instance.getQueue("testQueuePollRollbackSize");
queue.offer("item1");
queue.offer("item2");
assertEquals(2, queue.size());
context.beginTransaction();
TransactionalQueue txnQ1 = context.getQueue("testQueuePollRollbackSize");
assertEquals("item1", txnQ1.poll());
assertEquals(1, txnQ1.size());
assertEquals(1, queue.size());
context.rollbackTransaction();
assertEquals(2, queue.size());
assertEquals("item1", queue.poll());
assertEquals("item2", queue.poll());
}
Aggregations