本文整理了Java中io.github.resilience4j.bulkhead.Bulkhead.decorateCheckedRunnable()
方法的一些代码示例,展示了Bulkhead.decorateCheckedRunnable()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bulkhead.decorateCheckedRunnable()
方法的具体详情如下:
包路径:io.github.resilience4j.bulkhead.Bulkhead
类名称:Bulkhead
方法名:decorateCheckedRunnable
[英]Returns a runnable which is decorated by a bulkhead.
[中]返回由隔板装饰的可运行文件。
代码示例来源:origin: resilience4j/resilience4j
public DecorateCheckedRunnable withBulkhead(Bulkhead bulkhead) {
runnable = Bulkhead.decorateCheckedRunnable(bulkhead, runnable);
return this;
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void shouldDecorateCheckedRunnableAndReturnWithException() throws Throwable {
// Given
Bulkhead bulkhead = Bulkhead.of("test", config);
// When
CheckedRunnable checkedRunnable = Bulkhead.decorateCheckedRunnable(bulkhead, () -> {throw new RuntimeException("BAM!");});
Try<Void> result = Try.run(checkedRunnable);
// Then
assertThat(result.isFailure()).isTrue();
assertThat(result.failed().get()).isInstanceOf(RuntimeException.class);
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void shouldDecorateCheckedRunnableAndReturnWithSuccess() throws Throwable {
// Given
Bulkhead bulkhead = Bulkhead.of("test", config);
// When
Bulkhead.decorateCheckedRunnable(bulkhead, helloWorldService::sayHelloWorldWithException)
.run();
// Then
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
BDDMockito.then(helloWorldService).should(times(1)).sayHelloWorldWithException();
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void shouldReturnFailureWithRuntimeException() {
// Given
BulkheadConfig config = BulkheadConfig.custom().maxConcurrentCalls(2).build();
Bulkhead bulkhead = Bulkhead.of("test", config);
bulkhead.isCallPermitted();
//v When
CheckedRunnable checkedRunnable = Bulkhead.decorateCheckedRunnable(bulkhead, () -> {throw new RuntimeException("BAM!");});
Try result = Try.run(checkedRunnable);
//Then
assertThat(result.isFailure()).isTrue();
assertThat(result.failed().get()).isInstanceOf(RuntimeException.class);
assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}
代码示例来源:origin: resilience4j/resilience4j
@Test
public void shouldReturnFailureWithBulkheadFullException() {
// tag::bulkheadFullException[]
// Given
BulkheadConfig config = BulkheadConfig.custom().maxConcurrentCalls(2).build();
Bulkhead bulkhead = Bulkhead.of("test", config);
bulkhead.isCallPermitted();
bulkhead.isCallPermitted();
// When
CheckedRunnable checkedRunnable = Bulkhead.decorateCheckedRunnable(bulkhead, () -> {throw new RuntimeException("BAM!");});
Try result = Try.run(checkedRunnable);
//Then
assertThat(result.isFailure()).isTrue();
assertThat(result.failed().get()).isInstanceOf(BulkheadFullException.class);
// end::bulkheadFullException[]
}
内容来源于网络,如有侵权,请联系作者删除!