mardi 28 novembre 2017

How to implement an integration test to check if my circuit breaker fallback is called?

In my application, I need to call an external endpoint and if it is too slow a fallback is activated.

The following code is an example of how my app looks like:

@FeignClient(name = "${config.name}", url = "${config.url:}", fallback = ExampleFallback.class)
public interface Example {
@RequestMapping(method = RequestMethod.GET, value = "/endpoint", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    MyReturnObject find(@RequestParam("myParam") String myParam);
}

And its fallback implementation:

@Component
public Class ExampleFallback implements Example {

    private final FallbackService fallback;

    @Autowired
    public ExampleFallback(final FallbackService fallback) {
        this.fallback = fallback;
    }

    @Override
    public MyReturnObject find(final String myParam) {
        return fallback.find(myParam);
    }

Also, a configured timeout for circuit breaker: hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000

How can I implement an integration test to check if my circuit break is working, i.e, if my endpoint (mocked in that case) is slow or if it returns an error like 4xx or 5xx?

I'm using Spring Boot 1.5.3 with Spring Cloud (Feign + Hystrix)

Aucun commentaire:

Enregistrer un commentaire