io.github.resilience4j.bulkhead.Bulkhead.decorateRunnable()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中io.github.resilience4j.bulkhead.Bulkhead.decorateRunnable()方法的一些代码示例,展示了Bulkhead.decorateRunnable()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bulkhead.decorateRunnable()方法的具体详情如下:
包路径:io.github.resilience4j.bulkhead.Bulkhead
类名称:Bulkhead
方法名:decorateRunnable

Bulkhead.decorateRunnable介绍

[英]Returns a runnable which is decorated by a bulkhead.
[中]返回由隔板装饰的可运行文件。

代码示例

代码示例来源:origin: resilience4j/resilience4j

public DecorateRunnable withBulkhead(Bulkhead bulkhead) {
  runnable = Bulkhead.decorateRunnable(bulkhead, runnable);
  return this;
}

代码示例来源:origin: resilience4j/resilience4j

/**
 * Decorates and executes the decorated Runnable.
 *
 * @param runnable the original Runnable
 */
default void executeRunnable(Runnable runnable){
  decorateRunnable(this, runnable).run();
}

代码示例来源:origin: resilience4j/resilience4j

@Test
public void shouldDecorateRunnableAndReturnWithException() throws Throwable {
 
  // Given
  Bulkhead bulkhead = Bulkhead.of("test", config);
  // When
  Runnable runnable = Bulkhead.decorateRunnable(bulkhead, () -> {throw new RuntimeException("BAM!");});
  Try<Void> result = Try.run(runnable::run);
  //Then
  assertThat(result.isFailure()).isTrue();
  assertThat(result.failed().get()).isInstanceOf(RuntimeException.class);
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}

代码示例来源:origin: resilience4j/resilience4j

@Test
public void shouldDecorateRunnableAndReturnWithSuccess() throws Throwable {
  // Given
  Bulkhead bulkhead = Bulkhead.of("test", config);
  //When
  Bulkhead.decorateRunnable(bulkhead, helloWorldService::sayHelloWorld)
      .run();
  //Then
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
  BDDMockito.then(helloWorldService).should(times(1)).sayHelloWorld();
}

相关文章