use of com.alibaba.csp.sentinel.slots.block.flow.FlowException in project Sentinel by alibaba.
the class DubboFallbackRegistryTest method testDefaultFallback.
@Test
public void testDefaultFallback() {
// Test for default fallback.
BlockException ex = new FlowException("xxx");
Result result = new DefaultDubboFallback().handle(null, null, ex);
Assert.assertTrue(result.hasException());
Assert.assertEquals(SentinelRpcException.class, result.getException().getClass());
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowException in project Sentinel by alibaba.
the class DubboFallbackRegistryTest method testCustomFallback.
@Test
public void testCustomFallback() {
BlockException ex = new FlowException("xxx");
DubboAdapterGlobalConfig.setConsumerFallback(new DubboFallback() {
@Override
public Result handle(Invoker<?> invoker, Invocation invocation, BlockException e) {
return new RpcResult("Error: " + e.getClass().getName());
}
});
Result result = DubboAdapterGlobalConfig.getConsumerFallback().handle(null, null, ex);
Assert.assertFalse("The invocation should not fail", result.hasException());
Assert.assertEquals("Error: " + ex.getClass().getName(), result.getValue());
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowException in project Sentinel by alibaba.
the class ApacheHttpClientFallbackTest method testDefaultOkHttpFallback.
@Test(expected = SentinelRpcException.class)
public void testDefaultOkHttpFallback() {
BlockException e = new FlowException("xxx");
ApacheHttpClientFallback fallback = new DefaultApacheHttpClientFallback();
fallback.handle(null, e);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowException in project Sentinel by alibaba.
the class OkHttpFallbackTest method testDefaultOkHttpFallback.
@Test(expected = SentinelRpcException.class)
public void testDefaultOkHttpFallback() {
BlockException e = new FlowException("xxx");
OkHttpFallback fallback = new DefaultOkHttpFallback();
fallback.handle(null, null, e);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowException in project Sentinel by alibaba.
the class ZuulBlockFallbackProviderTest method testFlowControlFallbackResponse.
@Test
public void testFlowControlFallbackResponse() throws Exception {
ZuulBlockFallbackProvider fallbackProvider = ZuulBlockFallbackManager.getFallbackProvider(ALL_ROUTE);
BlockResponse clientHttpResponse = fallbackProvider.fallbackResponse(ALL_ROUTE, new FlowException("flow exception"));
Assert.assertEquals(clientHttpResponse.getCode(), 429);
}
Aggregations