Search in sources :

Example 1 with Completion

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

the class BucketOperatorWrapperTest method bucketWrapperShouldInvokeOnSuccessWhenCreateBucketSucceeds.

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

        public Object answer(InvocationOnMock invocation) {
            // 3rd argument is Completion object sent to BucketOperatorImpl.createRedundantBucket
            ((Completion) invocation.getArguments()[3]).onSuccess();
            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(completionSentToWrapper, times(1)).onSuccess();
}
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 2 with Completion

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

the class BucketOperatorWrapperTest method bucketWrapperShouldNotRecordNumberOfBucketsCreatedIfCreateBucketFails.

@Test
public void bucketWrapperShouldNotRecordNumberOfBucketsCreatedIfCreateBucketFails() {
    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 create buckets is not recorded
    for (PartitionRebalanceDetailsImpl details : rebalanceDetails) {
        verify(details, times(0)).incTransfers(anyLong(), anyLong());
    }
}
Also used : Completion(org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PartitionRebalanceDetailsImpl(org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 3 with Completion

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

the class BucketOperatorWrapperTest method bucketWrapperShouldRecordNumberOfBucketsCreatedIfCreateBucketSucceeds.

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

        public Object answer(InvocationOnMock invocation) {
            // 3rd argument is Completion object sent to BucketOperatorImpl.createRedundantBucket
            ((Completion) invocation.getArguments()[3]).onSuccess();
            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 create buckets is recorded
    for (PartitionRebalanceDetailsImpl details : rebalanceDetails) {
        if (details.getRegionPath().equalsIgnoreCase(PR_LEADER_REGION_NAME))
            verify(details, times(1)).incCreates(eq(colocatedRegionBytes.get(PR_LEADER_REGION_NAME)), anyLong());
        else if (details.getRegionPath().equals(PR_COLOCATED_REGION_NAME))
            verify(details, times(1)).incTransfers(colocatedRegionBytes.get(PR_COLOCATED_REGION_NAME), // elapsed is recorded only if its leader
            0);
    }
}
Also used : Completion(org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PartitionRebalanceDetailsImpl(org.apache.geode.internal.cache.control.PartitionRebalanceDetailsImpl) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 4 with Completion

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

the class BucketOperatorWrapperTest method bucketWrapperShouldDelegateCreateBucketToEnclosedOperator.

@Test
public void bucketWrapperShouldDelegateCreateBucketToEnclosedOperator() {
    Completion completionSentToWrapper = mock(Completion.class);
    doNothing().when(delegate).createRedundantBucket(targetMember, bucketId, colocatedRegionBytes, completionSentToWrapper);
    wrapper.createRedundantBucket(targetMember, bucketId, colocatedRegionBytes, completionSentToWrapper);
    verify(delegate, times(1)).createRedundantBucket(eq(targetMember), eq(bucketId), eq(colocatedRegionBytes), any(Completion.class));
}
Also used : Completion(org.apache.geode.internal.cache.partitioned.rebalance.BucketOperator.Completion) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Example 5 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)

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