本文整理了Java中io.github.resilience4j.bulkhead.Bulkhead.decorateCallable()
方法的一些代码示例,展示了Bulkhead.decorateCallable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bulkhead.decorateCallable()
方法的具体详情如下:
包路径:io.github.resilience4j.bulkhead.Bulkhead
类名称:Bulkhead
方法名:decorateCallable
[英]Returns a callable which is decorated by a bulkhead.
[中]返回由隔板装饰的可调用项。
代码示例来源:origin: resilience4j/resilience4j
/**
* Decorates and executes the decorated Callable.
*
* @param callable the original Callable
*
* @return the result of the decorated Callable.
* @param <T> the result type of callable
* @throws Exception if unable to compute a result
*/
default <T> T executeCallable(Callable<T> callable) throws Exception{
return decorateCallable(this, callable).call();
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void shouldDecorateCallableAndReturnWithSuccess() throws Throwable {
// Given
Bulkhead bulkhead = Bulkhead.of("test", config);
BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willReturn("Hello world");
// When
Callable<String> callable = Bulkhead.decorateCallable(bulkhead, helloWorldService::returnHelloWorldWithException);
// Then
assertThat(callable.call()).isEqualTo("Hello world");
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorldWithException();
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void shouldDecorateCallableAndReturnWithException() throws Throwable {
// Given
Bulkhead bulkhead = Bulkhead.of("test", config);
BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willThrow(new RuntimeException("BAM!"));
// When
Callable<String> callable = Bulkhead.decorateCallable(bulkhead, helloWorldService::returnHelloWorldWithException);
Try<String> result = Try.of(callable::call);
// Then
assertThat(result.isFailure()).isTrue();
assertThat(result.failed().get()).isInstanceOf(RuntimeException.class);
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorldWithException();
}
内容来源于网络,如有侵权,请联系作者删除!