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

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

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

Bulkhead.getMetrics介绍

[英]Get the Metrics of this Bulkhead.
[中]获取此舱壁的度量。

代码示例

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

private BulkheadMetrics(String prefix, Iterable<Bulkhead> bulkheads) {
  requireNonNull(prefix);
  requireNonNull(bulkheads);
  bulkheads.forEach(bulkhead -> {
        String name = bulkhead.getName();
    //number of available concurrent calls as an integer
        metricRegistry.register(name(prefix, name, AVAILABLE_CONCURRENT_CALLS),
            (Gauge<Integer>) () -> bulkhead.getMetrics().getAvailableConcurrentCalls());
      }
  );
}

代码示例来源: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 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 shouldDecorateConsumerAndReturnWithSuccess() throws Throwable {
  // Given
  Bulkhead bulkhead = Bulkhead.of("test", config);
  // When
  Bulkhead.decorateConsumer(bulkhead, helloWorldService::sayHelloWorldWithName)
      .accept("Tom");
  // Then
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
  BDDMockito.then(helloWorldService).should(times(1)).sayHelloWorldWithName("Tom");
}

代码示例来源: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 shouldEmitEvent() {
  StepVerifier.create(
      Mono.just("Event")
          .transform(BulkheadOperator.of(bulkhead)))
      .expectNext("Event")
      .verifyComplete();
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}

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

@Test
public void shouldPropagateError() {
  StepVerifier.create(
      Flux.error(new IOException("BAM!"))
          .transform(BulkheadOperator.of(bulkhead)))
      .expectSubscription()
      .expectError(IOException.class)
      .verify(Duration.ofSeconds(1));
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}

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

@Test
public void shouldExecuteSupplierAndReturnWithSuccess() {
  // Given
  Bulkhead bulkhead = Bulkhead.of("test", config);
  BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world");
  // When
  String result = bulkhead.executeSupplier(helloWorldService::returnHelloWorld);
  // Then
  assertThat(result).isEqualTo("Hello world");
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
  BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld();
}

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

@Test
public void shouldExecuteCallableAndReturnWithSuccess()  throws Throwable {
  // Given
  Bulkhead bulkhead = Bulkhead.of("test", config);
  BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willReturn("Hello world");
  // When
  String result = bulkhead.executeCallable(helloWorldService::returnHelloWorldWithException);
  // Then
  assertThat(result).isEqualTo("Hello world");
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
  BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorldWithException();
}

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

@Test
public void shouldEmitErrorWithBulkheadFullException() {
  bulkhead.isCallPermitted();
  StepVerifier.create(
      Mono.just("Event")
          .transform(BulkheadOperator.of(bulkhead)))
      .expectSubscription()
      .expectError(BulkheadFullException.class)
      .verify(Duration.ofSeconds(1));
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
}

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

@Test
public void shouldReturnTheCorrectName() {
  Bulkhead bulkhead = registry.bulkhead("test");
  assertThat(bulkhead).isNotNull();
  assertThat(bulkhead.getName()).isEqualTo("test");
  assertThat(bulkhead.getBulkheadConfig().getMaxConcurrentCalls()).isEqualTo(25);
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(25);
}

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

@Test
public void shouldEmitAllEvents() {
  Maybe.just(1)
    .lift(BulkheadOperator.of(bulkhead))
    .test()
    .assertResult(1);
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}

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

@Test
  public void shouldEmitBulkheadFullExceptionEvenWhenErrorNotOnSubscribe() {
    bulkhead.isCallPermitted();

    StepVerifier.create(
        Mono.error(new IOException("BAM!")).delayElement(Duration.ofMillis(1))
            .transform(BulkheadOperator.of(bulkhead, Schedulers.immediate())))
        .expectSubscription()
        .expectError(BulkheadFullException.class)
        .verify(Duration.ofSeconds(1));

    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
  }
}

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

@Test
public void shouldPropagateError() {
  Flowable.error(new IOException("BAM!"))
    .lift(BulkheadOperator.of(bulkhead))
    .test()
    .assertSubscribed()
    .assertError(IOException.class)
    .assertNotComplete();
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}

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

@Test
public void shouldPropagateError() {
  Maybe.error(new IOException("BAM!"))
    .lift(BulkheadOperator.of(bulkhead))
    .test()
    .assertSubscribed()
    .assertError(IOException.class)
    .assertNotComplete();
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}

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

@Test
  public void shouldReleaseBulkheadOnlyOnce() {
    Maybe.just(Arrays.asList(1, 2, 3))
      .lift(BulkheadOperator.of(bulkhead))
      .flatMapObservable(Observable::fromIterable)
      .take(2) //this with the previous line triggers an extra dispose
      .test()
      .assertResult(1, 2);

    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
  }
}

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

@Test
  public void shouldEmitBulkheadFullExceptionEvenWhenErrorNotOnSubscribe() {
    bulkhead.isCallPermitted();

    StepVerifier.create(
        Flux.error(new IOException("BAM!"), true)
            .transform(BulkheadOperator.of(bulkhead, Schedulers.immediate())))
        .expectSubscription()
        .expectError(BulkheadFullException.class)
        .verify(Duration.ofSeconds(1));

    assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
  }
}

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

@Test
public void shouldEmitBulkheadFullExceptionEvenWhenErrorDuringSubscribe() {
  bulkhead.isCallPermitted();
  StepVerifier.create(
      Mono.error(new IOException("BAM!"))
          .transform(BulkheadOperator.of(bulkhead, Schedulers.immediate())))
      .expectSubscription()
      .expectError(BulkheadFullException.class)
      .verify(Duration.ofSeconds(1));
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
}

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

@Test
public void shouldComplete() {
  Completable.complete()
    .lift(BulkheadOperator.of(bulkhead))
    .test()
    .assertSubscribed()
    .assertComplete();
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1);
}

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

@Test
public void shouldEmitErrorWithBulkheadFullException() {
  bulkhead.isCallPermitted();
  StepVerifier.create(
      Flux.just("Event")
          .transform(BulkheadOperator.of(bulkhead)))
      .expectSubscription()
      .expectError(BulkheadFullException.class)
      .verify(Duration.ofSeconds(1));
  assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0);
}

相关文章