@Test
  public void testRedundancySatisfactionWithAsyncFailures() throws UnknownHostException {
    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.emptySet(), partitionedRegion);
    PartitionMemberInfoImpl details1 = buildDetails(member1,
        new long[] {1, 1, 1, 1, 1, 1}, new long[] {1, 1, 1, 1, 1, 1});
    PartitionMemberInfoImpl details2 = buildDetails(member2,
        new long[] {0, 0, 0, 0, 0, 0}, new long[] {0, 0, 0, 0, 0, 0});
    PartitionMemberInfoImpl details3 = buildDetails(member3,
        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");
    assertThat(details.size()).isEqualTo(3);

    PartitionMemberInfo[] memberInfo = details.toArray(new PartitionMemberInfo[0]);

    assertThat(memberInfo[0].getBucketCount()).isEqualTo(6);
    assertThat(memberInfo[0].getConfiguredMaxMemory()).isEqualTo(500);
    assertThat(memberInfo[0].getPrimaryCount()).isEqualTo(6);

    // we expect 6 moves (3 of these will fail)
    assertThat(doMoves(new CompositeDirector(true, true, false, false), model)).isEqualTo(6);

    PartitionMemberInfo[] memberInfo2 =
        model.getPartitionedMemberDetails("a").toArray(new PartitionMemberInfo[0]);

    assertThat(memberInfo2[0].getBucketCount()).isEqualTo(6);
    assertThat(memberInfo2[0].getConfiguredMaxMemory()).isEqualTo(500);
    assertThat(memberInfo2[0].getPrimaryCount()).isEqualTo(6);

    assertThat(bucketOperator.creates.size()).isEqualTo(3);
    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)
    assertThat(doMoves(new CompositeDirector(true, true, false, false), model)).isEqualTo(3);

    List<Create> expectedCreates = new ArrayList<>();
    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));
    assertThat(bucketOperator.creates).isEqualTo(expectedCreates);
  }
Test that redundancy satisfation can handle asynchronous failures and complete the job
correctly.
geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/rebalance/PartitionedRegionLoadModelJUnitTest.java