Search in sources :

Example 16 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class ClusterMembershipTest method testMembershipListenerSequentialInvocation.

@Test
public void testMembershipListenerSequentialInvocation() throws Exception {
    final int nodeCount = 10;
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(nodeCount);
    final CountDownLatch eventLatch = new CountDownLatch(nodeCount - 1);
    final CountDownLatch nodeLatch = new CountDownLatch(nodeCount - 1);
    Config config = new Config().addListenerConfig(new ListenerConfig().setImplementation(newAddMemberListener(eventLatch)));
    // first node has listener
    factory.newHazelcastInstance(config);
    for (int i = 1; i < nodeCount; i++) {
        executorService.execute(new Runnable() {

            public void run() {
                factory.newHazelcastInstance(new Config());
                nodeLatch.countDown();
            }
        });
    }
    assertOpenEventually(nodeLatch);
    assertOpenEventually(eventLatch);
}
Also used : ListenerConfig(com.hazelcast.config.ListenerConfig) ListenerConfig(com.hazelcast.config.ListenerConfig) Config(com.hazelcast.config.Config) MapIndexConfig(com.hazelcast.config.MapIndexConfig) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 17 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class TransactionListTest method testMigrationSerializationNotFails_whenTransactionsAreUsed.

@Test
public void testMigrationSerializationNotFails_whenTransactionsAreUsed() throws Exception {
    Config config = new Config();
    config.setProperty("hazelcast.partition.count", "2");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    String listName = randomString();
    TransactionContext tr = instance1.newTransactionContext();
    tr.beginTransaction();
    TransactionalList<Object> list = tr.getList(listName);
    for (int i = 0; i < 10; i++) {
        list.add(i);
    }
    tr.commitTransaction();
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    Member owner = instance1.getPartitionService().getPartition(listName).getOwner();
    HazelcastInstance aliveInstance;
    if (instance1.getCluster().getLocalMember().equals(owner)) {
        instance1.shutdown();
        aliveInstance = instance2;
    } else {
        instance2.shutdown();
        aliveInstance = instance1;
    }
    IList<Object> l = aliveInstance.getList(listName);
    for (int i = 0; i < 10; i++) {
        assertEquals(i, l.get(i));
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 18 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class TransactionQueueTest method testIssue859And863_WhenInQueueOnSecondInstance_OutQueueOnFirstInstance.

@Test
public void testIssue859And863_WhenInQueueOnSecondInstance_OutQueueOnFirstInstance() throws Exception {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance();
    HazelcastInstance instance2 = factory.newHazelcastInstance();
    String inQueueName = generateKeyOwnedBy(instance2);
    String outQueueName = generateKeyOwnedBy(instance1);
    testIssue859And863(instance1, instance2, inQueueName, outQueueName);
}
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 19 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class QueueStoreTest method testQueueStore.

@Test
public void testQueueStore() throws Exception {
    Config config = new Config();
    int maxSize = 2000;
    QueueConfig queueConfig = config.getQueueConfig("testQueueStore");
    queueConfig.setMaxSize(maxSize);
    TestQueueStore queueStore = new TestQueueStore(1000, 0, 2000, 0, 0, 0, 1);
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig();
    queueStoreConfig.setStoreImplementation(queueStore);
    queueConfig.setQueueStoreConfig(queueStoreConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    for (int i = 0; i < maxSize / 2; i++) {
        queueStore.store.put((long) i, i);
    }
    IQueue<Object> queue = instance.getQueue("testQueueStore");
    for (int i = 0; i < maxSize / 2; i++) {
        queue.offer(i + maxSize / 2);
    }
    instance.shutdown();
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    IQueue<Object> queue2 = instance2.getQueue("testQueueStore");
    assertEquals(maxSize, queue2.size());
    assertEquals(maxSize, queueStore.store.size());
    for (int i = 0; i < maxSize; i++) {
        assertEquals(i, queue2.poll());
    }
    queueStore.assertAwait(3);
}
Also used : QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) QueueConfig(com.hazelcast.config.QueueConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueueConfig(com.hazelcast.config.QueueConfig) Config(com.hazelcast.config.Config) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 20 with TestHazelcastInstanceFactory

use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.

the class QueueStoreTest method testStoreId_whenNodeDown.

@Test
public void testStoreId_whenNodeDown() {
    Config config = new Config();
    QueueConfig queueConfig = config.getQueueConfig("default");
    IdCheckerQueueStore idCheckerQueueStore = new IdCheckerQueueStore();
    QueueStoreConfig queueStoreConfig = new QueueStoreConfig();
    queueStoreConfig.setEnabled(true).setStoreImplementation(idCheckerQueueStore);
    queueConfig.setQueueStoreConfig(queueStoreConfig);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    String name = generateKeyOwnedBy(instance1);
    IQueue<Object> queue = instance2.getQueue(name);
    queue.offer(randomString());
    queue.offer(randomString());
    queue.offer(randomString());
    instance1.shutdown();
    queue.offer(randomString());
}
Also used : QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) QueueConfig(com.hazelcast.config.QueueConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) QueueConfig(com.hazelcast.config.QueueConfig) Config(com.hazelcast.config.Config) QueueStoreConfig(com.hazelcast.config.QueueStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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