Search in sources :

Example 21 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method test.

private void test(MemberGroupFactory memberGroupFactory) throws Exception {
    PartitionStateGenerator generator = new PartitionStateGeneratorImpl();
    int maxSameHostCount = 3;
    int[] partitionCounts = new int[] { 271, 787, 1549, 3217 };
    int[] members = new int[] { 3, 6, 9, 10, 11, 17, 57, 100, 130, 77, 179, 93, 37, 26, 15, 5 };
    for (int partitionCount : partitionCounts) {
        int memberCount = members[0];
        List<Member> memberList = createMembers(memberCount, maxSameHostCount);
        Collection<MemberGroup> groups = memberGroupFactory.createMemberGroups(memberList);
        Address[][] state = generator.arrange(groups, emptyPartitionArray(partitionCount));
        checkTestResult(state, groups, partitionCount);
        int previousMemberCount = memberCount;
        for (int j = 1; j < members.length; j++) {
            memberCount = members[j];
            if (partitionCount / memberCount < 10) {
                break;
            }
            if ((float) partitionCount / memberCount > 2) {
                if (previousMemberCount == 0) {
                    memberList = createMembers(memberCount, maxSameHostCount);
                } else if (memberCount > previousMemberCount) {
                    MemberImpl last = (MemberImpl) memberList.get(previousMemberCount - 1);
                    List<Member> extra = createMembers(last, (memberCount - previousMemberCount), maxSameHostCount);
                    memberList.addAll(extra);
                } else {
                    List<Member> removedMembers = memberList.subList(memberCount, memberList.size());
                    memberList = memberList.subList(0, memberCount);
                    remove(state, removedMembers);
                }
                groups = memberGroupFactory.createMemberGroups(memberList);
                state = generator.arrange(groups, toPartitionArray(state));
                checkTestResult(state, groups, partitionCount);
                previousMemberCount = memberCount;
            }
        }
    }
}
Also used : DefaultMemberGroup(com.hazelcast.partition.membergroup.DefaultMemberGroup) MemberGroup(com.hazelcast.partition.membergroup.MemberGroup) MemberImpl(com.hazelcast.instance.MemberImpl) PartitionStateGenerator(com.hazelcast.internal.partition.PartitionStateGenerator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Member(com.hazelcast.core.Member)

Example 22 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method createMembers.

private static List<Member> createMembers(MemberImpl startAfter, int memberCount, int maxSameHostCount) throws Exception {
    Random rand = new Random();
    final byte[] ip = new byte[] { 10, 10, 0, 0 };
    if (startAfter != null) {
        Address address = startAfter.getAddress();
        byte[] startIp = address.getInetAddress().getAddress();
        if ((0xff & startIp[3]) < 255) {
            ip[2] = startIp[2];
            ip[3] = (byte) (startIp[3] + 1);
        } else {
            ip[2] = (byte) (startIp[2] + 1);
            ip[3] = 0;
        }
    }
    int count = 0;
    int port = 5700;
    List<Member> members = new ArrayList<Member>();
    int sameHostCount = rand.nextInt(maxSameHostCount) + 1;
    for (int i = 0; i < memberCount; i++) {
        if (count == sameHostCount) {
            ip[3] = ++ip[3];
            count = 0;
            port = 5700;
            sameHostCount = rand.nextInt(maxSameHostCount) + 1;
        }
        count++;
        port++;
        MemberImpl m = new MemberImpl(new Address(InetAddress.getByAddress(new byte[] { ip[0], ip[1], ip[2], ip[3] }), port), VERSION, false);
        members.add(m);
        if ((0xff & ip[3]) == 255) {
            ip[2] = ++ip[2];
        }
    }
    return members;
}
Also used : Random(java.util.Random) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) MemberImpl(com.hazelcast.instance.MemberImpl) ArrayList(java.util.ArrayList) Member(com.hazelcast.core.Member)

Example 23 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class MemberProviderFilterParserTest method givenMemberAttributeFilterIsUsed_whenMemberAttributeIsNotPresent_thenFilterDoesNotMatch.

@Test
public void givenMemberAttributeFilterIsUsed_whenMemberAttributeIsNotPresent_thenFilterDoesNotMatch() {
    Filter<Member> memberFilter = MemberProviderFilterParser.parseMemberFilter("HAS_ATTRIBUTE:foo");
    Map<String, Object> attributes = ImmutableMap.of("bar", (Object) "other");
    Member mockMember = createMockMemberWithAttributes(attributes);
    assertFalse(memberFilter.accept(mockMember));
}
Also used : Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class MemberProviderFilterParserTest method givenMemberAttributeFilterIsUsed_whenMemberAttributeIsPresent_thenFilterMatches.

@Test
public void givenMemberAttributeFilterIsUsed_whenMemberAttributeIsPresent_thenFilterMatches() {
    Filter<Member> memberFilter = MemberProviderFilterParser.parseMemberFilter("HAS_ATTRIBUTE:foo");
    Map<String, Object> attributes = ImmutableMap.of("foo", (Object) "bar");
    Member mockMember = createMockMemberWithAttributes(attributes);
    assertTrue(memberFilter.accept(mockMember));
}
Also used : Member(com.hazelcast.core.Member) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with Member

use of com.hazelcast.core.Member in project hazelcast by hazelcast.

the class WriteBehindOnBackupsTest method getOwnerNode.

private HazelcastInstance getOwnerNode(String key, HazelcastInstance[] nodes) {
    PartitionService partitionService = nodes[0].getPartitionService();
    Partition partition = partitionService.getPartition(key);
    Member owner = partition.getOwner();
    for (HazelcastInstance node : nodes) {
        Member localMember = node.getCluster().getLocalMember();
        if (localMember.equals(owner)) {
            return node;
        }
    }
    throw new IllegalStateException("This should not be happen...");
}
Also used : Partition(com.hazelcast.core.Partition) HazelcastInstance(com.hazelcast.core.HazelcastInstance) PartitionService(com.hazelcast.core.PartitionService) Member(com.hazelcast.core.Member)

Aggregations

Member (com.hazelcast.core.Member)330 Test (org.junit.Test)134 QuickTest (com.hazelcast.test.annotation.QuickTest)124 ParallelTest (com.hazelcast.test.annotation.ParallelTest)113 HazelcastInstance (com.hazelcast.core.HazelcastInstance)99 Address (com.hazelcast.nio.Address)60 IExecutorService (com.hazelcast.core.IExecutorService)57 Future (java.util.concurrent.Future)47 ArrayList (java.util.ArrayList)45 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)41 CountDownLatch (java.util.concurrent.CountDownLatch)37 Config (com.hazelcast.config.Config)35 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)26 HashMap (java.util.HashMap)26 IMap (com.hazelcast.core.IMap)24 HashSet (java.util.HashSet)21 LinkedList (java.util.LinkedList)20 OperationService (com.hazelcast.spi.OperationService)19 AssertTask (com.hazelcast.test.AssertTask)19 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)18