public DecorateConsumer<T> withBulkhead(Bulkhead bulkhead) { consumer = Bulkhead.decorateConsumer(bulkhead, consumer); return this; }
@Test public void shouldDecorateConsumerAndReturnWithException() throws Throwable { // Given Bulkhead bulkhead = Bulkhead.of("test", config); // When Consumer<String> consumer = Bulkhead.decorateConsumer(bulkhead, (value) -> {throw new RuntimeException("BAM!");}); Try<Void> result = Try.run(() -> consumer.accept("Tom")); // Then assertThat(result.isFailure()).isTrue(); assertThat(result.failed().get()).isInstanceOf(RuntimeException.class); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@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"); }