Search in sources :

Example 36 with PartitionedRegionLoadModel

use of org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel in project geode by apache.

the class PartitionedRegionLoadModelJUnitTest method testMoveBucketsWithRedundancy.

/**
   * Test to move buckets with redundancy. Makes sure that buckets and primaries are balanced
   */
@Test
public void testMoveBucketsWithRedundancy() throws Exception {
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 2, 4, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
    InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
    InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
    InternalDistributedMember member3 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 3);
    InternalDistributedMember member4 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 4);
    // Create some imbalanced nodes
    PartitionMemberInfoImpl details1 = buildDetails(member1, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 1, 1, 0, 0 });
    PartitionMemberInfoImpl details2 = buildDetails(member2, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 0, 0, 1, 0 });
    PartitionMemberInfoImpl details3 = buildDetails(member3, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 0, 0, 0, 1 });
    PartitionMemberInfoImpl details4 = buildDetails(member4, 500, 500, new long[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
    model.addRegion("a", Arrays.asList(details1, details2, details3, details4), new FakeOfflineDetails(), true);
    doMoves(new CompositeDirector(false, false, true, true), model);
    assertEquals(Collections.emptyList(), bucketOperator.creates);
    // One bucket should move from each member to member4
    Set<Move> expectedMoves = new HashSet<Move>();
    expectedMoves.add(new Move(member1, member4));
    expectedMoves.add(new Move(member2, member4));
    expectedMoves.add(new Move(member3, member4));
    assertEquals(expectedMoves, new HashSet<Move>(bucketOperator.bucketMoves));
    // We don't know how many primaries will move, because
    // the move buckets algorithm could move the primary or
    // it could move a redundant copy. But after we're done, we should
    // only have one primary per member.
    Set<PartitionMemberInfo> detailSet = model.getPartitionedMemberDetails("a");
    for (PartitionMemberInfo member : detailSet) {
        assertEquals(1, member.getPrimaryCount());
        assertEquals(3, member.getBucketCount());
    }
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) HashSet(java.util.HashSet) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)36 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)34 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)33 UnitTest (org.apache.geode.test.junit.categories.UnitTest)32 Test (org.junit.Test)32 ArrayList (java.util.ArrayList)19 HashSet (java.util.HashSet)9 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)8 Map (java.util.Map)3 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 CancelException (org.apache.geode.CancelException)2 PartitionRebalanceInfo (org.apache.geode.cache.partition.PartitionRebalanceInfo)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 InternalResourceManager (org.apache.geode.internal.cache.control.InternalResourceManager)2 PartitionRebalanceDetailsImpl (org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl)2 Completion (org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion)2 BucketOperatorWrapper (org.apache.geode.internal.cache.partitioned.rebalance.BucketOperatorWrapper)2 PersistentMemberID (org.apache.geode.internal.cache.persistence.PersistentMemberID)2 Ignore (org.junit.Ignore)2 IOException (java.io.IOException)1