Search in sources :

Example 1 with MemberGroupFactory

use of com.hazelcast.internal.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.

the class DiscoverySpiTest method testSPIAwareMemberGroupFactoryCreateMemberGroups.

@Test
public void testSPIAwareMemberGroupFactoryCreateMemberGroups() throws Exception {
    String xmlFileName = "test-hazelcast-discovery-spi-metadata.xml";
    Config config = getDiscoverySPIConfig(xmlFileName, false);
    // we create this instance in order to fully create Node
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    Node node = getNode(hazelcastInstance);
    assertNotNull(node);
    MemberGroupFactory groupFactory = new SPIAwareMemberGroupFactory(node.getDiscoveryService());
    Collection<Member> members = createMembers();
    Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
    assertEquals("Member Groups: " + String.valueOf(memberGroups), 2, memberGroups.size());
    for (MemberGroup memberGroup : memberGroups) {
        assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
    }
    hazelcastInstance.shutdown();
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) SPIAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SPIAwareMemberGroupFactory) Member(com.hazelcast.cluster.Member) SPIAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SPIAwareMemberGroupFactory) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with MemberGroupFactory

use of com.hazelcast.internal.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method testRandomPartitionGenerator.

@Test
public void testRandomPartitionGenerator() throws Exception {
    final MemberGroupFactory memberGroupFactory = new SingleMemberGroupFactory();
    test(memberGroupFactory);
}
Also used : SingleMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory) ConfigMemberGroupFactory(com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory) HostAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.HostAwareMemberGroupFactory) SingleMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MemberGroupFactory

use of com.hazelcast.internal.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method testOnlyUnassignedArrangement.

@Test
public void testOnlyUnassignedArrangement() throws Exception {
    List<Member> memberList = createMembers(10, 1);
    MemberGroupFactory memberGroupFactory = new SingleMemberGroupFactory();
    Collection<MemberGroup> groups = memberGroupFactory.createMemberGroups(memberList);
    PartitionStateGenerator generator = new PartitionStateGeneratorImpl();
    PartitionReplica[][] state = generator.arrange(groups, emptyPartitionArray(100));
    // unassign some partitions entirely
    Collection<Integer> unassignedPartitions = new ArrayList<Integer>();
    for (int i = 0; i < state.length; i++) {
        if (i % 3 == 0) {
            state[i] = new PartitionReplica[InternalPartition.MAX_REPLICA_COUNT];
            unassignedPartitions.add(i);
        }
    }
    // unassign only backup replicas of some partitions
    for (int i = 0; i < state.length; i++) {
        if (i % 10 == 0) {
            Arrays.fill(state[i], 1, InternalPartition.MAX_REPLICA_COUNT, null);
        }
    }
    InternalPartition[] partitions = toPartitionArray(state);
    state = generator.arrange(groups, partitions, unassignedPartitions);
    for (int pid = 0; pid < state.length; pid++) {
        PartitionReplica[] addresses = state[pid];
        if (unassignedPartitions.contains(pid)) {
            for (PartitionReplica address : addresses) {
                assertNotNull(address);
            }
        } else {
            InternalPartition partition = partitions[pid];
            for (int replicaIx = 0; replicaIx < InternalPartition.MAX_REPLICA_COUNT; replicaIx++) {
                assertEquals(partition.getReplica(replicaIx), addresses[replicaIx]);
            }
        }
    }
}
Also used : PartitionStateGenerator(com.hazelcast.internal.partition.PartitionStateGenerator) ArrayList(java.util.ArrayList) InternalPartition(com.hazelcast.internal.partition.InternalPartition) ReadonlyInternalPartition(com.hazelcast.internal.partition.ReadonlyInternalPartition) MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) PartitionReplica(com.hazelcast.internal.partition.PartitionReplica) SingleMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory) Member(com.hazelcast.cluster.Member) ConfigMemberGroupFactory(com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory) HostAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.HostAwareMemberGroupFactory) SingleMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MemberGroupFactory

use of com.hazelcast.internal.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.

the class PartitionStateGeneratorTest method testCustomPartitionStateGenerator.

@Test
public void testCustomPartitionStateGenerator() throws Exception {
    final MemberGroupFactory memberGroupFactory = new MemberGroupFactory() {

        public Collection<MemberGroup> createMemberGroups(Collection<? extends Member> members) {
            MemberGroup[] g = new MemberGroup[4];
            for (int i = 0; i < g.length; i++) {
                g[i] = new DefaultMemberGroup();
            }
            for (Member member : members) {
                Address address = member.getAddress();
                if (even(address.getHost().hashCode()) && even(address.getPort())) {
                    g[0].addMember(member);
                } else if (even(address.getHost().hashCode()) && !even(address.getPort())) {
                    g[1].addMember(member);
                } else if (!even(address.getHost().hashCode()) && even(address.getPort())) {
                    g[2].addMember(member);
                } else if (!even(address.getHost().hashCode()) && !even(address.getPort())) {
                    g[3].addMember(member);
                }
            }
            List<MemberGroup> list = new LinkedList<MemberGroup>();
            for (MemberGroup memberGroup : g) {
                if (memberGroup.size() > 0) {
                    list.add(memberGroup);
                }
            }
            return list;
        }

        boolean even(int k) {
            return k % 2 == 0;
        }
    };
    test(memberGroupFactory);
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) Address(com.hazelcast.cluster.Address) InetAddress(java.net.InetAddress) Collection(java.util.Collection) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) Member(com.hazelcast.cluster.Member) ConfigMemberGroupFactory(com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory) HostAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.HostAwareMemberGroupFactory) SingleMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) LinkedList(java.util.LinkedList) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 5 with MemberGroupFactory

use of com.hazelcast.internal.partition.membergroup.MemberGroupFactory in project hazelcast by hazelcast.

the class DiscoverySpiTest method testSPIAwareMemberGroupFactoryCreateMemberGroups_withDeprecated.

@Test
public void testSPIAwareMemberGroupFactoryCreateMemberGroups_withDeprecated() throws Exception {
    String xmlFileName = "test-hazelcast-discovery-spi-metadata.xml";
    Config config = getDiscoverySPIConfig(xmlFileName, true);
    // we create this instance in order to fully create Node
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    Node node = getNode(hazelcastInstance);
    assertNotNull(node);
    MemberGroupFactory groupFactory = new SPIAwareMemberGroupFactory(node.getDiscoveryService());
    Collection<Member> members = createMembers();
    Collection<MemberGroup> memberGroups = groupFactory.createMemberGroups(members);
    assertEquals("Member Groups: " + String.valueOf(memberGroups), 2, memberGroups.size());
    for (MemberGroup memberGroup : memberGroups) {
        assertEquals("Member Group: " + String.valueOf(memberGroup), 2, memberGroup.size());
    }
    hazelcastInstance.shutdown();
}
Also used : MemberGroup(com.hazelcast.spi.partitiongroup.MemberGroup) DefaultMemberGroup(com.hazelcast.internal.partition.membergroup.DefaultMemberGroup) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AwsConfig(com.hazelcast.config.AwsConfig) DiscoveryStrategyConfig(com.hazelcast.config.DiscoveryStrategyConfig) MulticastConfig(com.hazelcast.config.MulticastConfig) JoinConfig(com.hazelcast.config.JoinConfig) Config(com.hazelcast.config.Config) DiscoveryConfig(com.hazelcast.config.DiscoveryConfig) TcpIpConfig(com.hazelcast.config.TcpIpConfig) InterfacesConfig(com.hazelcast.config.InterfacesConfig) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) SPIAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SPIAwareMemberGroupFactory) Member(com.hazelcast.cluster.Member) SPIAwareMemberGroupFactory(com.hazelcast.internal.partition.membergroup.SPIAwareMemberGroupFactory) MemberGroupFactory(com.hazelcast.internal.partition.membergroup.MemberGroupFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

MemberGroupFactory (com.hazelcast.internal.partition.membergroup.MemberGroupFactory)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 Member (com.hazelcast.cluster.Member)5 DefaultMemberGroup (com.hazelcast.internal.partition.membergroup.DefaultMemberGroup)4 MemberGroup (com.hazelcast.spi.partitiongroup.MemberGroup)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ConfigMemberGroupFactory (com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory)3 HostAwareMemberGroupFactory (com.hazelcast.internal.partition.membergroup.HostAwareMemberGroupFactory)3 SPIAwareMemberGroupFactory (com.hazelcast.internal.partition.membergroup.SPIAwareMemberGroupFactory)3 SingleMemberGroupFactory (com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory)3 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)3 AwsConfig (com.hazelcast.config.AwsConfig)2 Config (com.hazelcast.config.Config)2 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)2 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)2 InterfacesConfig (com.hazelcast.config.InterfacesConfig)2 JoinConfig (com.hazelcast.config.JoinConfig)2 MulticastConfig (com.hazelcast.config.MulticastConfig)2 TcpIpConfig (com.hazelcast.config.TcpIpConfig)2