use of com.alibaba.csp.sentinel.slots.block.SentinelRpcException in project Sentinel by alibaba.
the class FooConsumerBootstrap method main.
public static void main(String[] args) {
initFlowRule();
AnnotationConfigApplicationContext consumerContext = new AnnotationConfigApplicationContext();
consumerContext.register(ConsumerConfiguration.class);
consumerContext.refresh();
FooServiceConsumer service = consumerContext.getBean(FooServiceConsumer.class);
for (int i = 0; i < 10; i++) {
pool.submit(() -> {
try {
String message = service.sayHello("Eric");
System.out.println("Success: " + message);
} catch (SentinelRpcException ex) {
System.out.println("Blocked");
} catch (Exception ex) {
ex.printStackTrace();
}
});
pool.submit(() -> System.out.println("Another: " + service.doAnother()));
}
}
use of com.alibaba.csp.sentinel.slots.block.SentinelRpcException in project Sentinel by alibaba.
the class DefaultSofaRpcFallbackTest method testHandle.
@Test
public void testHandle() {
SofaRpcFallback sofaRpcFallback = new DefaultSofaRpcFallback();
BlockException blockException = mock(BlockException.class);
boolean throwSentinelRpcException = false;
boolean causeIsBlockException = false;
try {
sofaRpcFallback.handle(null, null, blockException);
} catch (Exception e) {
throwSentinelRpcException = e instanceof SentinelRpcException;
causeIsBlockException = e.getCause() instanceof BlockException;
}
assertTrue(throwSentinelRpcException);
assertTrue(causeIsBlockException);
}
Aggregations