use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class Resilience4JPluginTest method circuitBreakerTest.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void circuitBreakerTest() {
RuleData data = mock(RuleData.class);
data.setSelectorId("SHENYU");
data.setId("SHENYU");
Resilience4JHandle resilience4JHandle = GsonUtils.getGson().fromJson(HANDLER, Resilience4JHandle.class);
Resilience4JHandler.CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(data), resilience4JHandle);
CombinedExecutor combinedExecutor = new CombinedExecutor();
resilience4JPlugin = new Resilience4JPlugin(combinedExecutor, new RateLimiterExecutor());
Mono mono = Mono.error(CallNotPermittedException.createCallNotPermittedException(circuitBreaker)).onErrorResume(throwable -> {
if (throwable instanceof CallNotPermittedException) {
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
}
return Mono.error(throwable);
});
when(data.getHandle()).thenReturn(HANDLER);
when(chain.execute(exchange)).thenReturn(mono);
when(data.getSelectorId()).thenReturn("circuitBreaker");
when(data.getName()).thenReturn("ruleData");
Resilience4JHandler.CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(data), resilience4JHandle);
SelectorData selectorData = mock(SelectorData.class);
StepVerifier.create(resilience4JPlugin.doExecute(exchange, chain, selectorData, data)).expectSubscription().expectError().verify();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, exchange.getResponse().getStatusCode());
}
Aggregations