@Test
  @Parameters({"false, false", "false, true", "true, true"})
  public void testDetectOngoingExecution(boolean useParallel,
      boolean usePartitionedRegion)
      throws Exception {
    final int wanCopyRegionBatchSize = 10;
    final int entries = 1000;

    final String regionName = getRegionName(usePartitionedRegion);

    // Site A
    VM locatorInA = vm0;
    VM server1InA = vm1;
    VM server2InA = vm2;
    VM server3InA = vm3;
    List<VM> serversInA = Arrays.asList(server1InA, server2InA, server3InA);
    final String senderIdInA = "B";

    // Site B
    VM locatorInB = vm4;
    VM server1InB = vm5;
    VM server2InB = vm6;
    VM server3InB = vm7;
    List<VM> serversInB = Arrays.asList(server1InB, server2InB, server3InB);
    VM client = vm8;

    int locatorAPort = create2WanSitesAndClient(locatorInA, serversInA, senderIdInA, locatorInB,
        serversInB, client, usePartitionedRegion, regionName);

    // Put entries
    client.invoke(() -> doPutsFrom(regionName, 0, entries));
    for (VM member : serversInA) {
      member.invoke(() -> validateRegionSize(regionName, entries));
    }

    // Create senders and receivers with replication as follows: "A" -> "B"
    if (useParallel) {
      createReceiverInVMs(server1InB, server2InB, server3InB);
      createSender(useParallel, serversInA, senderIdInA, 2);
    } else {
      // Senders will connect to receiver in server1InB
      server1InB.invoke(WANTestBase::createReceiver);
      createSender(useParallel, serversInA, senderIdInA, 2);
      createReceiverInVMs(server2InB, server3InB);
    }

    Callable<CommandResultAssert> wanCopyCommandCallable = () -> {
      String command = new CommandStringBuilder(WAN_COPY_REGION)
          .addOption(WAN_COPY_REGION__REGION, regionName)
          .addOption(WAN_COPY_REGION__SENDERID, senderIdInA)
          .addOption(WAN_COPY_REGION__BATCHSIZE, String.valueOf(wanCopyRegionBatchSize))
          .addOption(WAN_COPY_REGION__MAXRATE, "5")
          .getCommandString();
      try {
        gfsh.connectAndVerify(locatorAPort, GfshCommandRule.PortType.locator);
      } catch (Exception e) {
        errorCollector.addError(e);
      }
      return gfsh.executeAndAssertThat(command);
    };

    Future<CommandResultAssert> wanCopyCommandFuture =
        executorServiceRule.submit(wanCopyCommandCallable);

    // Wait for the wan-copy command to start
    waitForWanCopyRegionCommandToStart(useParallel, usePartitionedRegion, serversInA);

    // Execute again the same wan-copy region command
    String commandString = new CommandStringBuilder(WAN_COPY_REGION)
        .addOption(WAN_COPY_REGION__REGION, regionName)
        .addOption(WAN_COPY_REGION__SENDERID, senderIdInA)
        .addOption(WAN_COPY_REGION__BATCHSIZE, String.valueOf(wanCopyRegionBatchSize))
        .getCommandString();

    // Check command status and output
    Condition<String> exceptionError = new Condition<>(
        s -> s.equals(CliStrings.format(WAN_COPY_REGION__MSG__ALREADY__RUNNING__COMMAND,
            regionName, senderIdInA)),
        "already running");
    if (useParallel) {
      CommandResultAssert command =
          verifyStatusIsError(gfsh.executeAndAssertThat(commandString), serversInA.size());
      command
          .hasTableSection(ResultModel.MEMBER_STATUS_SECTION)
          .hasColumn("Message")
          .asList()
          .haveExactly(3, exceptionError);
    } else {
      CommandResultAssert command =
          verifyStatusIsErrorInOneServer(gfsh.executeAndAssertThat(commandString));
      Condition<String> senderNotPrimary = new Condition<>(
          s -> s.equals(CliStrings
              .format(WAN_COPY_REGION__MSG__SENDER__SERIAL__AND__NOT__PRIMARY,
                  senderIdInA)),
          "sender not primary");
      command
          .hasTableSection(ResultModel.MEMBER_STATUS_SECTION)
          .hasColumn("Message")
          .asList()
          .haveExactly(1, exceptionError)
          .haveExactly(2, senderNotPrimary);
    }

    // cancel command
    String commandString1 = new CommandStringBuilder(WAN_COPY_REGION)
        .addOption(WAN_COPY_REGION__REGION, regionName)
        .addOption(WAN_COPY_REGION__SENDERID, senderIdInA)
        .addOption(WAN_COPY_REGION__BATCHSIZE, String.valueOf(wanCopyRegionBatchSize))
        .addOption(WAN_COPY_REGION__CANCEL)
        .getCommandString();
    gfsh.executeAndAssertThat(commandString1);
    wanCopyCommandFuture.get();
    addIgnoredExceptionsForClosingAfterCancelCommand();
  }
This test creates two sites A & B, each one containing 3 servers.
A region is created in both sites, and populated in site A.
After that replication is configured from site A to site B.
WanCopyRegionFunction is called, and while it is running, a sender in site A
or a receiver in site B are killed.
geode-wan/src/distributedTest/java/org/apache/geode/cache/wan/internal/cli/commands/WanCopyRegionCommandDistributedTest.java