Search in sources :

Example 46 with TestHazelcastInstanceFactory

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

the class JoinStressTest method testJoincompletesCorrectlyWhenMultipleNodesStartedParallel.

@Test
public void testJoincompletesCorrectlyWhenMultipleNodesStartedParallel() throws Exception {
    int count = 10;
    final TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(count);
    final HazelcastInstance[] instances = new HazelcastInstance[count];
    final CountDownLatch latch = new CountDownLatch(count);
    for (int i = 0; i < count; i++) {
        final int index = i;
        new Thread(new Runnable() {

            @Override
            public void run() {
                instances[index] = factory.newHazelcastInstance();
                latch.countDown();
            }
        }).start();
    }
    assertOpenEventually(latch);
    for (int i = 0; i < count; i++) {
        assertClusterSize(count, instances[i]);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 47 with TestHazelcastInstanceFactory

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

the class ClusterMembershipTest method testMembershipListener.

@Test
public void testMembershipListener() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    MembershipListenerImpl listener = new MembershipListenerImpl();
    hz1.getCluster().addMembershipListener(listener);
    //start a second instance
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    assertEventuallySizeAtLeast(listener.events, 1);
    assertMembershipAddedEvent(listener.events.get(0), hz2.getCluster().getLocalMember(), hz1.getCluster().getLocalMember(), hz2.getCluster().getLocalMember());
    //terminate the second instance
    Member member2 = hz2.getCluster().getLocalMember();
    hz2.shutdown();
    assertEventuallySizeAtLeast(listener.events, 2);
    assertMembershipRemovedEvent(listener.events.get(1), member2, hz1.getCluster().getLocalMember());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 48 with TestHazelcastInstanceFactory

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

the class ClusterMembershipTest method testNodesAbleToJoinFromMultipleThreads_whenPostJoinOperationPresent.

@Test
public void testNodesAbleToJoinFromMultipleThreads_whenPostJoinOperationPresent() throws InterruptedException {
    final int instanceCount = 6;
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(instanceCount);
    final Config config = new Config();
    config.setProperty(GroupProperty.WAIT_SECONDS_BEFORE_JOIN.getName(), "0");
    final String mapName = randomMapName();
    // index config is added since it was blocking post join operations.
    config.getMapConfig(mapName).addMapIndexConfig(new MapIndexConfig("name", false));
    final CountDownLatch latch = new CountDownLatch(instanceCount);
    for (int i = 0; i < instanceCount; i++) {
        executorService.execute(new Runnable() {

            public void run() {
                HazelcastInstance hz = factory.newHazelcastInstance(config);
                hz.getMap(mapName);
                latch.countDown();
            }
        });
    }
    assertOpenEventually(latch);
    Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
    for (HazelcastInstance instance : instances) {
        assertClusterSize(instanceCount, instance);
    }
}
Also used : MapIndexConfig(com.hazelcast.config.MapIndexConfig) HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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 49 with TestHazelcastInstanceFactory

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

the class ClusterMembershipTest method testRemoveMembershipListener.

@Test
public void testRemoveMembershipListener() {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    Cluster cluster = hz1.getCluster();
    MembershipListener membershipListener = mock(MembershipListener.class);
    String id = cluster.addMembershipListener(membershipListener);
    boolean removed = cluster.removeMembershipListener(id);
    assertTrue(removed);
    // now we add a member
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    // and verify that the listener isn't called.
    verify(membershipListener, never()).memberAdded(any(MembershipEvent.class));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) Cluster(com.hazelcast.core.Cluster) InitialMembershipListener(com.hazelcast.core.InitialMembershipListener) MembershipListener(com.hazelcast.core.MembershipListener) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 50 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)

Aggregations

TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)948 HazelcastInstance (com.hazelcast.core.HazelcastInstance)827 Test (org.junit.Test)774 QuickTest (com.hazelcast.test.annotation.QuickTest)726 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)575 Config (com.hazelcast.config.Config)488 MapConfig (com.hazelcast.config.MapConfig)185 ParallelTest (com.hazelcast.test.annotation.ParallelTest)145 MapStoreConfig (com.hazelcast.config.MapStoreConfig)121 CountDownLatch (java.util.concurrent.CountDownLatch)108 AssertTask (com.hazelcast.test.AssertTask)97 NightlyTest (com.hazelcast.test.annotation.NightlyTest)86 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)81 Before (org.junit.Before)75 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)58 NearCacheConfig (com.hazelcast.config.NearCacheConfig)53 SlowTest (com.hazelcast.test.annotation.SlowTest)53 IndexConfig (com.hazelcast.config.IndexConfig)50 ArrayList (java.util.ArrayList)45 Map (java.util.Map)43