Search in sources :

Example 1 with FlowException

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());
}
Also used : BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) FlowException(com.alibaba.csp.sentinel.slots.block.flow.FlowException) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Example 2 with FlowException

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());
}
Also used : BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) Invocation(com.alibaba.dubbo.rpc.Invocation) FlowException(com.alibaba.csp.sentinel.slots.block.flow.FlowException) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Test(org.junit.Test)

Example 3 with FlowException

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);
}
Also used : BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) FlowException(com.alibaba.csp.sentinel.slots.block.flow.FlowException) Test(org.junit.Test)

Example 4 with FlowException

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);
}
Also used : BlockException(com.alibaba.csp.sentinel.slots.block.BlockException) FlowException(com.alibaba.csp.sentinel.slots.block.flow.FlowException) Test(org.junit.Test)

Example 5 with FlowException

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);
}
Also used : FlowException(com.alibaba.csp.sentinel.slots.block.flow.FlowException) Test(org.junit.Test)

Aggregations

FlowException (com.alibaba.csp.sentinel.slots.block.flow.FlowException)12 Test (org.junit.Test)7 BlockException (com.alibaba.csp.sentinel.slots.block.BlockException)4 DegradeException (com.alibaba.csp.sentinel.slots.block.degrade.DegradeException)3 HttpHeaders (org.springframework.http.HttpHeaders)3 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)3 ResponseEntityExceptionHandler (org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler)3 AuthorityException (com.alibaba.csp.sentinel.slots.block.authority.AuthorityException)2 ParamFlowException (com.alibaba.csp.sentinel.slots.block.flow.param.ParamFlowException)2 SystemBlockException (com.alibaba.csp.sentinel.slots.system.SystemBlockException)2 Result (com.alibaba.dubbo.rpc.Result)2 RpcResult (com.alibaba.dubbo.rpc.RpcResult)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 BizException (com.actionworks.flashsale.app.exception.BizException)1 DomainException (com.actionworks.flashsale.domain.exception.DomainException)1 Context (com.alibaba.csp.sentinel.context.Context)1 StringResourceWrapper (com.alibaba.csp.sentinel.slotchain.StringResourceWrapper)1 Invocation (com.alibaba.dubbo.rpc.Invocation)1 PrintWriter (java.io.PrintWriter)1 ServerHttpRequest (org.springframework.http.server.reactive.ServerHttpRequest)1