Search in sources :

Example 1 with DefaultMemberGroup

use of com.hazelcast.internal.partition.membergroup.DefaultMemberGroup 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)

Aggregations

Address (com.hazelcast.cluster.Address)1 Member (com.hazelcast.cluster.Member)1 ConfigMemberGroupFactory (com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory)1 DefaultMemberGroup (com.hazelcast.internal.partition.membergroup.DefaultMemberGroup)1 HostAwareMemberGroupFactory (com.hazelcast.internal.partition.membergroup.HostAwareMemberGroupFactory)1 MemberGroupFactory (com.hazelcast.internal.partition.membergroup.MemberGroupFactory)1 SingleMemberGroupFactory (com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory)1 MemberGroup (com.hazelcast.spi.partitiongroup.MemberGroup)1 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1 QuickTest (com.hazelcast.test.annotation.QuickTest)1 InetAddress (java.net.InetAddress)1 Collection (java.util.Collection)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1