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();
}
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);
}
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);
}
Aggregations