【问题标题】:How to Test @HystrixCommand fallback method in Springboot Application如何在 Spring Boot 应用程序中测试 @HystrixCommand 回退方法
【发布时间】:2017-12-30 13:08:22
【问题描述】:

我在我的方法中使用@HystrixCommand,如下所示

@HystrixCommand(fallbackMethod = "fallbackCircuit", groupKey = "group-key", commandProperties = {
            @HystrixProperty(name = "requestCache.enabled", value = "true"),
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")})

 public void someMethod(String input){
 ...
 }


 public void fallbackCircuit(String input, Throwable e){
 ...
 }

但我无法测试回退方法?我的测试中没有调用回退方法。我想我没有正确设置测试。测试回退方法的更好方法是什么?

【问题讨论】:

    标签: spring-boot hystrix spring-boot-test


    【解决方案1】:

    虽然没有直接测试回退方法,但我回答的另一个问题有一个解决方案,显示断路器已被触发。 见How can I unit-test javanica @HystrixCommand annotated methods? 如果你有兴趣。

    【讨论】:

      【解决方案2】:

      如果您想在 UT 中测试回退方法,则无需测试 @HystrixCommand(),您可以在单元测试中直接调用回退方法并断言其响应/结果。

      【讨论】:

        猜你喜欢
        • 2019-09-05
        • 2019-05-27
        • 2016-10-20
        • 2023-03-10
        • 2016-04-05
        • 1970-01-01
        • 2016-11-06
        • 2022-01-13
        • 2019-05-02
        相关资源
        最近更新 更多