Search in sources :

Example 6 with Completion

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

the class BucketOperatorWrapperTest method bucketWrapperShouldInvokeOnFailureWhenCreateBucketFails.

@Test
public void bucketWrapperShouldInvokeOnFailureWhenCreateBucketFails() {
    doAnswer(new Answer<Object>() {

        public Object answer(InvocationOnMock invocation) {
            // 3rd argument is Completion object sent to BucketOperatorImpl.createRedundantBucket
            ((Completion) invocation.getArguments()[3]).onFailure();
            return null;
        }
    }).when(delegate).createRedundantBucket(eq(targetMember), eq(bucketId), eq(colocatedRegionBytes), any(Completion.class));
    Completion completionSentToWrapper = mock(Completion.class);
    wrapper.createRedundantBucket(targetMember, bucketId, colocatedRegionBytes, completionSentToWrapper);
    // verify onFailure is invoked
    verify(completionSentToWrapper, times(1)).onFailure();
}
Also used : Completion(org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion) InvocationOnMock(org.mockito.invocation.InvocationOnMock) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 7 with Completion

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

the class PartitionedRegionLoadModelJUnitTest method testRedundancySatisfactionWithAsyncFailures.

/**
   * Test that redundancy satisfation can handle asynchronous failures and complete the job
   * correctly.
   */
@Test
public void testRedundancySatisfactionWithAsyncFailures() throws Exception {
    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);
    BucketOperatorWithFailures operator = new BucketOperatorWithFailures();
    operator.addBadMember(member2);
    bucketOperator = operator;
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(bucketOperator, 1, 6, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
    PartitionMemberInfoImpl details1 = buildDetails(member1, 500, 500, new long[] { 1, 1, 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1, 1, 1 });
    PartitionMemberInfoImpl details2 = buildDetails(member2, 500, 500, new long[] { 0, 0, 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0, 0, 0 });
    PartitionMemberInfoImpl details3 = buildDetails(member3, 500, 500, new long[] { 0, 0, 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0, 0, 0 });
    model.addRegion("a", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
    Set<PartitionMemberInfo> details = model.getPartitionedMemberDetails("a");
    assertEquals(3, details.size());
    // TODO - make some assertions about what's in the details
    // we expect 6 moves (3 of these will fail)
    assertEquals(6, doMoves(new CompositeDirector(true, true, false, false), model));
    assertEquals(3, bucketOperator.creates.size());
    for (Completion completion : operator.pendingSuccesses) {
        completion.onSuccess();
    }
    for (Completion completion : operator.pendingFailures) {
        completion.onFailure();
    }
    // Now the last two moves will get reattempted to a new location (because the last location
    // failed)
    assertEquals(3, doMoves(new CompositeDirector(true, true, false, false), model));
    List<Create> expectedCreates = new ArrayList<Create>();
    expectedCreates.add(new Create(member3, 1));
    expectedCreates.add(new Create(member3, 3));
    expectedCreates.add(new Create(member3, 5));
    expectedCreates.add(new Create(member3, 0));
    expectedCreates.add(new Create(member3, 2));
    expectedCreates.add(new Create(member3, 4));
    assertEquals(expectedCreates, bucketOperator.creates);
}
Also used : PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) Completion(org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) ArrayList(java.util.ArrayList) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 8 with Completion

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

the class PartitionedRegionLoadModelJUnitTest method testRedundancySatisfactionWithFailures.

/**
   * Tests to make sure that redundancy satisfaction balances between nodes to ensure an even load.
   */
@Test
public void testRedundancySatisfactionWithFailures() throws Exception {
    InternalDistributedMember member1 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 1);
    final InternalDistributedMember member2 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 2);
    InternalDistributedMember member3 = new InternalDistributedMember(InetAddress.getByName("127.0.0.1"), 3);
    MyBucketOperator op = new MyBucketOperator() {

        @Override
        public void createRedundantBucket(InternalDistributedMember targetMember, int i, Map<String, Long> colocatedRegionBytes, Completion completion) {
            if (targetMember.equals(member2)) {
                completion.onFailure();
            } else {
                super.createRedundantBucket(targetMember, i, colocatedRegionBytes, completion);
            }
        }
    };
    PartitionedRegionLoadModel model = new PartitionedRegionLoadModel(op, 1, 4, getAddressComparor(false), Collections.<InternalDistributedMember>emptySet(), null);
    // Create some buckets with low redundancy on member 1
    PartitionMemberInfoImpl details1 = buildDetails(member1, 500, 500, new long[] { 1, 1, 1, 1 }, new long[] { 1, 1, 1, 1 });
    PartitionMemberInfoImpl details2 = buildDetails(member2, 500, 500, new long[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
    PartitionMemberInfoImpl details3 = buildDetails(member3, 500, 500, new long[] { 0, 0, 0, 0 }, new long[] { 0, 0, 0, 0 });
    model.addRegion("a", Arrays.asList(details1, details2, details3), new FakeOfflineDetails(), true);
    // we expect 8 moves
    assertEquals(8, doMoves(new CompositeDirector(true, true, false, false), model));
    // The bucket creates should do all of the creates on member 3
    // because member2 failed.
    List<Create> expectedCreates = new ArrayList<Create>();
    expectedCreates.add(new Create(member3, 0));
    expectedCreates.add(new Create(member3, 1));
    expectedCreates.add(new Create(member3, 2));
    expectedCreates.add(new Create(member3, 3));
    assertEquals(expectedCreates, op.creates);
}
Also used : Completion(org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion) PartitionedRegionLoadModel(org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ArrayList(java.util.ArrayList) Map(java.util.Map) CompositeDirector(org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

Completion (org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion)8 UnitTest (org.apache.geode.test.junit.categories.UnitTest)7 Test (org.junit.Test)7 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)3 ArrayList (java.util.ArrayList)2 PartitionRebalanceDetailsImpl (org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl)2 CompositeDirector (org.apache.geode.internal.cache.partitioned.rebalance.CompositeDirector)2 PartitionedRegionLoadModel (org.apache.geode.internal.cache.partitioned.rebalance.PartitionedRegionLoadModel)2 Map (java.util.Map)1 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 PartitionedRegionRebalanceOp (org.apache.geode.internal.cache.partitioned.PartitionedRegionRebalanceOp)1 Before (org.junit.Before)1