Search in sources :

Example 1 with MemberGroupFactory

use of com.hazelcast.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.partition.membergroup.SingleMemberGroupFactory) SingleMemberGroupFactory(com.hazelcast.partition.membergroup.SingleMemberGroupFactory) HostAwareMemberGroupFactory(com.hazelcast.partition.membergroup.HostAwareMemberGroupFactory) MemberGroupFactory(com.hazelcast.partition.membergroup.MemberGroupFactory) ConfigMemberGroupFactory(com.hazelcast.partition.membergroup.ConfigMemberGroupFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 2 with MemberGroupFactory

use of com.hazelcast.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);
    // we create this instance in order to fully create Node
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    Node node = TestUtil.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 : DefaultMemberGroup(com.hazelcast.partition.membergroup.DefaultMemberGroup) MemberGroup(com.hazelcast.partition.membergroup.MemberGroup) 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.Node) SPIAwareMemberGroupFactory(com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory) Member(com.hazelcast.core.Member) MemberGroupFactory(com.hazelcast.partition.membergroup.MemberGroupFactory) SPIAwareMemberGroupFactory(com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with MemberGroupFactory

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

the class DiscoverySpiTest method testSPIAwareMemberGroupFactoryInvalidConfig.

@Test(expected = RuntimeException.class)
public void testSPIAwareMemberGroupFactoryInvalidConfig() throws Exception {
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
    try {
        MemberGroupFactory groupFactory = new SPIAwareMemberGroupFactory(TestUtil.getNode(hazelcastInstance).getDiscoveryService());
        Collection<Member> members = createMembers();
        groupFactory.createMemberGroups(members);
    } finally {
        hazelcastInstance.shutdown();
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) SPIAwareMemberGroupFactory(com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory) Member(com.hazelcast.core.Member) MemberGroupFactory(com.hazelcast.partition.membergroup.MemberGroupFactory) SPIAwareMemberGroupFactory(com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with MemberGroupFactory

use of com.hazelcast.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 : DefaultMemberGroup(com.hazelcast.partition.membergroup.DefaultMemberGroup) MemberGroup(com.hazelcast.partition.membergroup.MemberGroup) Address(com.hazelcast.nio.Address) InetAddress(java.net.InetAddress) Collection(java.util.Collection) DefaultMemberGroup(com.hazelcast.partition.membergroup.DefaultMemberGroup) Member(com.hazelcast.core.Member) SingleMemberGroupFactory(com.hazelcast.partition.membergroup.SingleMemberGroupFactory) HostAwareMemberGroupFactory(com.hazelcast.partition.membergroup.HostAwareMemberGroupFactory) MemberGroupFactory(com.hazelcast.partition.membergroup.MemberGroupFactory) ConfigMemberGroupFactory(com.hazelcast.partition.membergroup.ConfigMemberGroupFactory) LinkedList(java.util.LinkedList) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

MemberGroupFactory (com.hazelcast.partition.membergroup.MemberGroupFactory)4 QuickTest (com.hazelcast.test.annotation.QuickTest)4 Test (org.junit.Test)4 Member (com.hazelcast.core.Member)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)2 ConfigMemberGroupFactory (com.hazelcast.partition.membergroup.ConfigMemberGroupFactory)2 DefaultMemberGroup (com.hazelcast.partition.membergroup.DefaultMemberGroup)2 HostAwareMemberGroupFactory (com.hazelcast.partition.membergroup.HostAwareMemberGroupFactory)2 MemberGroup (com.hazelcast.partition.membergroup.MemberGroup)2 SPIAwareMemberGroupFactory (com.hazelcast.partition.membergroup.SPIAwareMemberGroupFactory)2 SingleMemberGroupFactory (com.hazelcast.partition.membergroup.SingleMemberGroupFactory)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 AwsConfig (com.hazelcast.config.AwsConfig)1 Config (com.hazelcast.config.Config)1 DiscoveryConfig (com.hazelcast.config.DiscoveryConfig)1 DiscoveryStrategyConfig (com.hazelcast.config.DiscoveryStrategyConfig)1 InterfacesConfig (com.hazelcast.config.InterfacesConfig)1 JoinConfig (com.hazelcast.config.JoinConfig)1 MulticastConfig (com.hazelcast.config.MulticastConfig)1 TcpIpConfig (com.hazelcast.config.TcpIpConfig)1