Search in sources :

Example 31 with TestHazelcastInstanceFactory

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TransactionContext(com.hazelcast.transaction.TransactionContext) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 32 with TestHazelcastInstanceFactory

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));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 33 with TestHazelcastInstanceFactory

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"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ListConfig(com.hazelcast.config.ListConfig) ListConfig(com.hazelcast.config.ListConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 34 with TestHazelcastInstanceFactory

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICountDownLatch(com.hazelcast.core.ICountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 35 with TestHazelcastInstanceFactory

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());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) ICountDownLatch(com.hazelcast.core.ICountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)743 HazelcastInstance (com.hazelcast.core.HazelcastInstance)665 Test (org.junit.Test)632 QuickTest (com.hazelcast.test.annotation.QuickTest)618 ParallelTest (com.hazelcast.test.annotation.ParallelTest)598 Config (com.hazelcast.config.Config)361 MapConfig (com.hazelcast.config.MapConfig)146 MapStoreConfig (com.hazelcast.config.MapStoreConfig)101 CountDownLatch (java.util.concurrent.CountDownLatch)99 AssertTask (com.hazelcast.test.AssertTask)94 NightlyTest (com.hazelcast.test.annotation.NightlyTest)70 IMap (com.hazelcast.core.IMap)65 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)62 MapIndexConfig (com.hazelcast.config.MapIndexConfig)51 TransactionException (com.hazelcast.transaction.TransactionException)46 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)43 Member (com.hazelcast.core.Member)41 NearCacheConfig (com.hazelcast.config.NearCacheConfig)40 Map (java.util.Map)38 Before (org.junit.Before)35