コード例 #1
0
  private void withdrawFromAccount(
      String transactionId, String accountId, double amountToWithdraw, boolean independentTest)
      throws Throwable {
    Throwable[] ex = new Throwable[1];
    if (independentTest) {
      this.host.testStart(1);
    }
    BankAccountServiceRequest body = new BankAccountServiceRequest();
    body.kind = BankAccountServiceRequest.Kind.WITHDRAW;
    body.amount = amountToWithdraw;
    Operation patch = createWithdrawOperation(transactionId, accountId, amountToWithdraw);
    patch.setCompletion(
        (o, e) -> {
          if (operationFailed(o, e)) {
            if (e instanceof IllegalStateException) {
              ex[0] = e;
              this.host.completeIteration();
            } else {
              this.host.failIteration(e);
            }
            return;
          }
          this.host.completeIteration();
        });
    this.host.send(patch);
    if (independentTest) {
      this.host.testWait();
    }

    if (ex[0] != null) {
      throw ex[0];
    }
  }
コード例 #2
0
  private Operation createWithdrawOperation(String transactionId, String accountId, double amount) {
    BankAccountServiceRequest body = new BankAccountServiceRequest();
    body.kind = BankAccountServiceRequest.Kind.WITHDRAW;
    body.amount = amount;
    Operation patch = Operation.createPatch(buildAccountUri(accountId)).setBody(body);
    if (transactionId != null) {
      patch.setTransactionId(transactionId);
    }

    return patch;
  }