Search in sources :

Example 26 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class MemberListTest method testOutOfSyncMemberListTwoMasters.

/*
     * Sets up a situation where the member list is out of order on node2. Both
     * node2 and node1 think they are masters and both think each other are in
     * their clusters.
     */
@Test
public void testOutOfSyncMemberListTwoMasters() throws Exception {
    List<HazelcastInstance> instanceList = buildInstances(3, 35701);
    final HazelcastInstance h1 = instanceList.get(0);
    final HazelcastInstance h2 = instanceList.get(1);
    final HazelcastInstance h3 = instanceList.get(2);
    final MemberImpl m1 = (MemberImpl) h1.getCluster().getLocalMember();
    final MemberImpl m2 = (MemberImpl) h2.getCluster().getLocalMember();
    final MemberImpl m3 = (MemberImpl) h3.getCluster().getLocalMember();
    // All three nodes join into one cluster
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    final Node n2 = TestUtil.getNode(h2);
    // Simulates node2 getting an out of order member list. That causes node2 to think it's the master.
    List<MemberInfo> members = new ArrayList<MemberInfo>();
    members.add(new MemberInfo(m2.getAddress(), m2.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
    members.add(new MemberInfo(m3.getAddress(), m3.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
    members.add(new MemberInfo(m1.getAddress(), m1.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
    n2.clusterService.updateMembers(members, n2.getMasterAddress());
    n2.setMasterAddress(m2.getAddress());
    // Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
    sleepSeconds(30);
    assertMasterEquals(m1, h1);
    assertMasterEquals(m1, h2);
    assertMasterEquals(m1, h3);
    assertClusterSize(3, h1);
    assertClusterSize(3, h2);
    assertClusterSize(3, h3);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) MemberImpl(com.hazelcast.instance.MemberImpl) Node(com.hazelcast.instance.Node) ArrayList(java.util.ArrayList) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 27 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class MemberListTest method testSameMasterDifferentMemberList.

/*
     * Sets up situation where all nodes have the same master, but node 2's list
     * doesn't contain node 3.
     */
@Test
public void testSameMasterDifferentMemberList() throws Exception {
    List<HazelcastInstance> instanceList = buildInstances(3, 45701);
    final HazelcastInstance h1 = instanceList.get(0);
    final HazelcastInstance h2 = instanceList.get(1);
    final HazelcastInstance h3 = instanceList.get(2);
    final MemberImpl m1 = (MemberImpl) h1.getCluster().getLocalMember();
    final MemberImpl m2 = (MemberImpl) h2.getCluster().getLocalMember();
    // All three nodes join into one cluster
    assertClusterSizeEventually(3, h1);
    assertClusterSizeEventually(3, h2);
    assertClusterSizeEventually(3, h3);
    final Node n2 = TestUtil.getNode(h2);
    // Simulates node2 getting an out of order member list. That causes node2 to think it's the master.
    List<MemberInfo> members = new ArrayList<MemberInfo>();
    members.add(new MemberInfo(m1.getAddress(), m1.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
    members.add(new MemberInfo(m2.getAddress(), m2.getUuid(), Collections.<String, Object>emptyMap(), n2.getVersion()));
    n2.clusterService.updateMembers(members, n2.getMasterAddress());
    // Give the cluster some time to figure things out. The merge and heartbeat code should have kicked in by this point
    sleepSeconds(30);
    assertMasterEquals(m1, h1);
    assertMasterEquals(m1, h2);
    assertMasterEquals(m1, h3);
    assertClusterSize(3, h1);
    assertClusterSize(3, h2);
    assertClusterSize(3, h3);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MemberInfo(com.hazelcast.internal.cluster.MemberInfo) MemberImpl(com.hazelcast.instance.MemberImpl) Node(com.hazelcast.instance.Node) ArrayList(java.util.ArrayList) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 28 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class AdvancedClusterStateTest method changeClusterState_shouldFail_whenMemberRemoved_duringTx.

@Test(expected = IllegalStateException.class)
public void changeClusterState_shouldFail_whenMemberRemoved_duringTx() throws Exception {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
    HazelcastInstance[] instances = new HazelcastInstance[3];
    for (int i = 0; i < 3; i++) {
        instances[i] = factory.newHazelcastInstance();
    }
    HazelcastInstance hz = instances[instances.length - 1];
    ClusterServiceImpl clusterService = (ClusterServiceImpl) getClusterService(hz);
    Collection<Member> initialMembers = new ArrayList<Member>(clusterService.getMembers());
    MemberImpl fakeMember = new MemberImpl((MemberImpl) clusterService.getLocalMember());
    initialMembers.add(fakeMember);
    changeClusterState(hz, ClusterState.PASSIVE, initialMembers);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MemberImpl(com.hazelcast.instance.MemberImpl) ArrayList(java.util.ArrayList) 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 29 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class MemberMapTest method cloneAdding_failsWithDuplicateAddress.

@Test(expected = IllegalArgumentException.class)
public void cloneAdding_failsWithDuplicateAddress() {
    MemberImpl[] members = new MemberImpl[3];
    for (int i = 0; i < members.length; i++) {
        members[i] = newMember(5000 + i);
    }
    MemberImpl member = newMember(5000);
    MemberMap.cloneAdding(MemberMap.createNew(members), member);
}
Also used : MemberImpl(com.hazelcast.instance.MemberImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with MemberImpl

use of com.hazelcast.instance.MemberImpl in project hazelcast by hazelcast.

the class MemberMapTest method testConstructor_whenMapsHaveDifferentMembers_thenThrowAssertionError.

@Test(expected = AssertionError.class)
@RequireAssertEnabled
public void testConstructor_whenMapsHaveDifferentMembers_thenThrowAssertionError() {
    Map<Address, MemberImpl> addressMap = new HashMap<Address, MemberImpl>();
    Map<String, MemberImpl> uuidMap = new HashMap<String, MemberImpl>();
    MemberImpl addressMember = newMember(5701);
    MemberImpl uuidMember = newMember(5702);
    addressMap.put(addressMember.getAddress(), addressMember);
    uuidMap.put(uuidMember.getUuid(), uuidMember);
    new MemberMap(addressMap, uuidMap);
}
Also used : Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) HashMap(java.util.HashMap) MemberImpl(com.hazelcast.instance.MemberImpl) UuidUtil.newUnsecureUuidString(com.hazelcast.util.UuidUtil.newUnsecureUuidString) RequireAssertEnabled(com.hazelcast.test.RequireAssertEnabled) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MemberImpl (com.hazelcast.instance.MemberImpl)86 Address (com.hazelcast.nio.Address)37 Test (org.junit.Test)18 Member (com.hazelcast.core.Member)17 QuickTest (com.hazelcast.test.annotation.QuickTest)16 ParallelTest (com.hazelcast.test.annotation.ParallelTest)14 ArrayList (java.util.ArrayList)12 InetAddress (java.net.InetAddress)9 Future (java.util.concurrent.Future)9 HashSet (java.util.HashSet)8 HazelcastInstance (com.hazelcast.core.HazelcastInstance)7 MemberInfo (com.hazelcast.internal.cluster.MemberInfo)7 ClusterService (com.hazelcast.internal.cluster.ClusterService)5 MemberInfoUpdateOperation (com.hazelcast.internal.cluster.impl.operations.MemberInfoUpdateOperation)5 PartitionRuntimeState (com.hazelcast.internal.partition.PartitionRuntimeState)5 ILogger (com.hazelcast.logging.ILogger)5 OperationService (com.hazelcast.spi.OperationService)5 InternalOperationService (com.hazelcast.spi.impl.operationservice.InternalOperationService)5 Before (org.junit.Before)5 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)4