use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QueueTestsFrom2X method testQueuePollCommitSize.
@Test
public void testQueuePollCommitSize() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = factory.newHazelcastInstance();
HazelcastInstance instance2 = factory.newHazelcastInstance();
TransactionContext context = instance1.newTransactionContext();
context.beginTransaction();
TransactionalQueue<String> txnQ1 = context.getQueue("testQueuePollCommitSize");
TransactionalQueue<String> txnQ2 = context.getQueue("testQueuePollCommitSize");
txnQ1.offer("item1");
txnQ1.offer("item2");
assertEquals(2, txnQ1.size());
assertEquals(2, txnQ2.size());
assertEquals("item1", txnQ1.poll());
assertEquals(1, txnQ1.size());
assertEquals(1, txnQ2.size());
context.commitTransaction();
assertEquals(1, instance1.getQueue("testQueuePollCommitSize").size());
assertEquals(1, instance2.getQueue("testQueuePollCommitSize").size());
assertEquals("item2", instance1.getQueue("testQueuePollCommitSize").poll());
assertEquals(0, instance1.getQueue("testQueuePollCommitSize").size());
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class ClusterListTest method testShutdown.
@Test
public void testShutdown() {
final String name = randomString();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
final HazelcastInstance[] instances = factory.newInstances();
IList<String> list1 = instances[0].getList(name);
IList<String> list2 = instances[1].getList(name);
warmUpPartitions(instances);
for (int i = 0; i < 50; i++) {
list1.add("item" + i);
}
instances[0].shutdown();
assertSizeEventually(50, list2);
for (int i = 50; i < 100; i++) {
list2.add("item" + i);
}
for (int i = 0; i < 100; i++) {
assertEquals("item" + i, list2.remove(0));
}
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class ClusterListTest method testMaxSize.
@Test
public void testMaxSize() {
Config config = new Config();
final String name = "defList";
config.addListConfig(new ListConfig().setName(name).setBackupCount(1).setMaxSize(100));
final int insCount = 2;
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(insCount);
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
IList<String> list = instance1.getList(name);
for (int i = 0; i < 100; i++) {
assertTrue(list.add("item" + i));
}
assertFalse(list.add("item"));
assertNotNull(list.remove(0));
assertTrue(list.add("item"));
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CountDownLatchMigrationTest method testLatchMigration.
@Test
public void testLatchMigration() throws InterruptedException {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(5);
HazelcastInstance hz1 = factory.newHazelcastInstance();
HazelcastInstance hz2 = factory.newHazelcastInstance();
warmUpPartitions(hz2, hz1);
ICountDownLatch latch1 = hz1.getCountDownLatch("test");
latch1.trySetCount(10);
Thread.sleep(500);
ICountDownLatch latch2 = hz2.getCountDownLatch("test");
assertEquals(10, latch2.getCount());
latch2.countDown();
assertEquals(9, latch1.getCount());
hz1.shutdown();
assertEquals(9, latch2.getCount());
HazelcastInstance hz3 = factory.newHazelcastInstance();
warmUpPartitions(hz3);
ICountDownLatch latch3 = hz3.getCountDownLatch("test");
latch3.countDown();
assertEquals(8, latch3.getCount());
hz2.shutdown();
latch3.countDown();
assertEquals(7, latch3.getCount());
HazelcastInstance hz4 = factory.newHazelcastInstance();
HazelcastInstance hz5 = factory.newHazelcastInstance();
warmUpPartitions(hz5, hz4);
Thread.sleep(250);
hz3.shutdown();
ICountDownLatch latch4 = hz4.getCountDownLatch("test");
assertEquals(7, latch4.getCount());
ICountDownLatch latch5 = hz5.getCountDownLatch("test");
latch5.countDown();
assertEquals(6, latch5.getCount());
latch5.countDown();
assertEquals(5, latch4.getCount());
assertEquals(5, latch5.getCount());
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CountDownLatchSplitBrainTest method testCountDownLatchSplitBrain.
@Test
public void testCountDownLatchSplitBrain() throws InterruptedException {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
Config config = newConfig();
HazelcastInstance h1 = factory.newHazelcastInstance(config);
HazelcastInstance h2 = factory.newHazelcastInstance(config);
HazelcastInstance h3 = factory.newHazelcastInstance(config);
warmUpPartitions(h1, h2, h3);
String name = generateKeyOwnedBy(h3);
ICountDownLatch countDownLatch1 = h1.getCountDownLatch(name);
ICountDownLatch countDownLatch3 = h3.getCountDownLatch(name);
countDownLatch3.trySetCount(5);
waitAllForSafeState(h1, h2, h3);
// create split: [h1, h2] & [h3]
closeConnectionBetween(h1, h3);
closeConnectionBetween(h2, h3);
assertClusterSizeEventually(2, h1);
assertClusterSizeEventually(2, h2);
assertClusterSizeEventually(1, h3);
// modify both latches after split with different counts
// count of h1 & h2 = 4
countDownLatch1.countDown();
// count of h3 = 0
while (countDownLatch3.getCount() > 0) {
countDownLatch3.countDown();
}
// merge back
getNode(h3).getClusterService().merge(getAddress(h1));
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
// latch count should be equal to the count of larger cluster
assertEquals(4, countDownLatch3.getCount());
}
Aggregations