Search in sources :

Example 11 with TestHazelcastInstanceFactory

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

the class ClusterShutdownTest method testClusterShutdownWithMultipleMembers.

private void testClusterShutdownWithMultipleMembers(int clusterSize, int nodeCountToTriggerShutdown) {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
    HazelcastInstance[] instances = factory.newInstances();
    instances[0].getCluster().changeClusterState(ClusterState.PASSIVE);
    Node[] nodes = getNodes(instances);
    final CountDownLatch latch = new CountDownLatch(1);
    for (int i = 0; i < nodeCountToTriggerShutdown; i++) {
        final HazelcastInstance instance = instances[i];
        final Runnable shutdownRunnable = new Runnable() {

            @Override
            public void run() {
                assertOpenEventually(latch);
                instance.getCluster().shutdown();
            }
        };
        new Thread(shutdownRunnable).start();
    }
    latch.countDown();
    assertNodesShutDownEventually(nodes);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 12 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 13 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 14 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 15 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)

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