@Test
  @Parameters({"true, true", "true, false", "false, false"})
  public void testSuccessfulCancelExecution(boolean isPartitionedRegion,
      boolean isParallelGatewaySender) throws Exception {
    List<VM> serversInA = Arrays.asList(vm5, vm6, vm7);
    List<VM> serversInB = Collections.singletonList(vm3);
    VM serverInC = vm4;
    VM client = vm8;
    String senderIdInA = "B";
    String senderIdInB = "C";

    int senderLocatorPort = create3WanSitesAndClient(isPartitionedRegion, vm0,
        vm1, vm2, serversInA, serversInB, serverInC, client,
        senderIdInA, senderIdInB, true);

    int wanCopyRegionBatchSize = 20;
    int entries = 100;
    String regionName = getRegionName(isPartitionedRegion);
    // Put entries
    client.invoke(() -> doPutsFrom(regionName, 0, entries));

    // Create senders and receivers
    createSender(isParallelGatewaySender, serversInA, senderIdInA, 2);
    createSender(isParallelGatewaySender, serversInB, senderIdInB, 3);
    createReceivers(serversInB, serverInC);

    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, String.valueOf(1))
          .getCommandString();
      try {
        gfsh.connectAndVerify(senderLocatorPort, GfshCommandRule.PortType.locator);
      } catch (Exception e) {
        errorCollector.addError(e);
      }
      return gfsh.executeAndAssertThat(command).statusIsError();
    };

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

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

    // Cancel wan-copy region command
    GfshCommandRule gfshCancelCommand = new GfshCommandRule();
    gfshCancelCommand.connectAndVerify(senderLocatorPort, GfshCommandRule.PortType.locator);
    String cancelCommand = new CommandStringBuilder(WAN_COPY_REGION)
        .addOption(WAN_COPY_REGION__REGION, regionName)
        .addOption(WAN_COPY_REGION__SENDERID, senderIdInA)
        .addOption(WAN_COPY_REGION__CANCEL)
        .getCommandString();
    CommandResultAssert cancelCommandResult =
        gfshCancelCommand.executeAndAssertThat(cancelCommand);

    if (isPartitionedRegion && isParallelGatewaySender) {
      verifyStatusIsOk(cancelCommandResult, serversInA.size());
      cancelCommandResult
          .hasTableSection(ResultModel.MEMBER_STATUS_SECTION)
          .hasColumn("Message")
          .containsExactlyInAnyOrder(WAN_COPY_REGION__MSG__EXECUTION__CANCELED,
              WAN_COPY_REGION__MSG__EXECUTION__CANCELED,
              WAN_COPY_REGION__MSG__EXECUTION__CANCELED);
    } else {
      verifyStatusIsOkInOneServer(cancelCommandResult);
      String msg1 = CliStrings.format(WAN_COPY_REGION__MSG__NO__RUNNING__COMMAND,
          regionName, senderIdInA);
      cancelCommandResult
          .hasTableSection(ResultModel.MEMBER_STATUS_SECTION)
          .hasColumn("Message")
          .containsExactlyInAnyOrder(msg1, msg1, WAN_COPY_REGION__MSG__EXECUTION__CANCELED);
    }

    // Check wan-copy region command output
    CommandResultAssert wanCopyCommandResult = wanCopyCommandFuture.get();
    if (isPartitionedRegion && isParallelGatewaySender) {
      verifyStatusIsError(wanCopyCommandResult, serversInA.size());
      String msg = WAN_COPY_REGION__MSG__CANCELED__BEFORE__HAVING__COPIED;
      wanCopyCommandResult
          .hasTableSection(ResultModel.MEMBER_STATUS_SECTION)
          .hasColumn("Message")
          .containsExactly(msg, msg, msg);
    } else {
      verifyStatusIsErrorInOneServer(wanCopyCommandResult);
      String msg1 = CliStrings
          .format(WAN_COPY_REGION__MSG__SENDER__SERIAL__AND__NOT__PRIMARY, senderIdInA);
      wanCopyCommandResult
          .hasTableSection(ResultModel.MEMBER_STATUS_SECTION)
          .hasColumn("Message")
          .containsExactlyInAnyOrder(WAN_COPY_REGION__MSG__CANCELED__BEFORE__HAVING__COPIED, msg1,
              msg1);
    }
    addIgnoredExceptionsForClosingAfterCancelCommand();
  }
Scenario with 3 WAN sites: "A", "B" and "C".
Initially, no replication is configured between sites.
Several entries are put in WAN site "A".

The following gateway senders are created and started:
- In "A" site: to replicate region entries to "B" site. Sender called "B".
- In "B" site: to replicate region entries to "C" site. Sender called "C".
(Replication is as follows: A -> B -> C)

The "wan-copy region" command is run from "A" site passing sender "B"
in a different thread. The maxRate is set to a very low value so that there is
time to cancel it before it finishes.

The "wan-copy region" command with the cancel option
is run from "A" site passing sender "B".

It must be verified that the command is canceled.
Also, the output of the command must show
the number of entries copied before the command was canceled.
geode-wan/src/distributedTest/java/org/apache/geode/cache/wan/internal/cli/commands/WanCopyRegionCommandDistributedTest.java