可观察的onErrorReturn在生产中没有触发,但在单元测试中工作

时间:2017-06-16 17:44:08

标签: java unit-testing error-handling rx-java observable

我目前遇到一段代码问题,其中.onErrorReturn语句在运行单元测试时按预期触发,但不在生产中。

代码段如下所示:

var form = $("#cloneThisDiv").clone();
$("#"+tabId).append(form);

基本上flatMap有时会返回一个异常,我想重试一下。重试三次后,我希望触发onErrorReturn并返回错误值。只是给出一个想法,这是单元测试的输出(重试时按预期工作,onErrorReturn触发)

return restApiAdapter.createPosition(createPositionRequest)
    .flatMap(dealReference -> restApiAdapter.getDealConfirmationObservable(dealReference.getValue())
        .retryWhen(new RetryWithDelay(3, 1500))
        .map(dealConfirmationResponse -> buyConfirmationHandler(dealConfirmationResponse, createPositionRequest.getDirection(), tradeParams))
    )
    .onErrorReturn(e -> {
                LOG.debug("Broker buy failed, returning error value {}", ZorroReturnValues.BROKER_BUY_FAIL.getValue());
                return ZorroReturnValues.BROKER_BUY_FAIL.getValue();
    })
    .blockingSingle();

但是在生产中,当抛出异常时,我得到的就是:

[RxComputationThreadPool-1] DEBUG c.danlind.igz.adapter.RestApiAdapter - Attempting to get confirmation for dealReference TestDealReference
[RxComputationThreadPool-1] WARN  c.danlind.igz.adapter.RestApiAdapter - Order with deal id TestDealId was rejected with reason code ATTACHED_ORDER_LEVEL_ERROR
[RxComputationThreadPool-1] DEBUG com.danlind.igz.misc.RetryWithDelay - Retry 1 of 3
[RxComputationThreadPool-2] DEBUG c.danlind.igz.adapter.RestApiAdapter - Attempting to get confirmation for dealReference TestDealReference
[RxComputationThreadPool-2] WARN  c.danlind.igz.adapter.RestApiAdapter - Order with deal id TestDealId was rejected with reason code ATTACHED_ORDER_LEVEL_ERROR
[RxComputationThreadPool-2] DEBUG com.danlind.igz.misc.RetryWithDelay - Retry 2 of 3
[RxComputationThreadPool-3] DEBUG c.danlind.igz.adapter.RestApiAdapter - Attempting to get confirmation for dealReference TestDealReference
[RxComputationThreadPool-3] WARN  c.danlind.igz.adapter.RestApiAdapter - Order with deal id TestDealId was rejected with reason code ATTACHED_ORDER_LEVEL_ERROR
[RxComputationThreadPool-3] DEBUG com.danlind.igz.misc.RetryWithDelay - Max retries exceeded, passing error downstream
[RxComputationThreadPool-3] DEBUG com.danlind.igz.brokerapi.BrokerBuy - Broker buy failed, returning error value 0

我无法弄清楚为什么我的单元测试按预期工作,但生产系统没有。我错过了什么?

RetryWithDelay代码:

[RxComputationThreadPool-1] DEBUG c.danlind.igz.adapter.RestApiAdapter - Attempting to get confirmation for dealReference 94ZY4P5RMP244TP
[RxComputationThreadPool-1] WARN  c.danlind.igz.adapter.RestApiAdapter - Order with deal id DIAAAABB9R4L4AM was rejected with reason code ATTACHED_ORDER_LEVEL_ERROR
[RxComputationThreadPool-1] DEBUG com.danlind.igz.misc.RetryWithDelay - Retry 1 of 3
[RxComputationThreadPool-1] DEBUG c.danlind.igz.adapter.RestApiAdapter - Attempting to get confirmation for dealReference 94ZY4P5RMP244TP
[RxComputationThreadPool-1] WARN  c.danlind.igz.adapter.RestApiAdapter - Order with deal id DIAAAABB9R4L4AM was rejected with reason code ATTACHED_ORDER_LEVEL_ERROR
[RxComputationThreadPool-1] DEBUG com.danlind.igz.misc.RetryWithDelay - Retry 2 of 3
[RxComputationThreadPool-1] DEBUG c.danlind.igz.adapter.RestApiAdapter - Attempting to get confirmation for dealReference 94ZY4P5RMP244TP
[RxComputationThreadPool-1] WARN  c.danlind.igz.adapter.RestApiAdapter - Order with deal id DIAAAABB9R4L4AM was rejected with reason code ATTACHED_ORDER_LEVEL_ERROR
[RxComputationThreadPool-1] DEBUG com.danlind.igz.misc.RetryWithDelay - Max retries exceeded, passing error downstream

0 个答案:

没有答案