Search in sources :

Example 1 with SingleMemberGroupFactory

use of com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory 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 2 with SingleMemberGroupFactory

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

Aggregations

ConfigMemberGroupFactory (com.hazelcast.internal.partition.membergroup.ConfigMemberGroupFactory)2 HostAwareMemberGroupFactory (com.hazelcast.internal.partition.membergroup.HostAwareMemberGroupFactory)2 MemberGroupFactory (com.hazelcast.internal.partition.membergroup.MemberGroupFactory)2 SingleMemberGroupFactory (com.hazelcast.internal.partition.membergroup.SingleMemberGroupFactory)2 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Test (org.junit.Test)2 Member (com.hazelcast.cluster.Member)1 InternalPartition (com.hazelcast.internal.partition.InternalPartition)1 PartitionReplica (com.hazelcast.internal.partition.PartitionReplica)1 PartitionStateGenerator (com.hazelcast.internal.partition.PartitionStateGenerator)1 ReadonlyInternalPartition (com.hazelcast.internal.partition.ReadonlyInternalPartition)1 DefaultMemberGroup (com.hazelcast.internal.partition.membergroup.DefaultMemberGroup)1 MemberGroup (com.hazelcast.spi.partitiongroup.MemberGroup)1 ArrayList (java.util.ArrayList)1