@Test public void shouldPropagateError() { StepVerifier.create( Mono.error(new IOException("BAM!")) .transform(BulkheadOperator.of(bulkhead))) .expectSubscription() .expectError(IOException.class) .verify(Duration.ofSeconds(1)); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@Test public void shouldEmitErrorWithBulkheadFullException() { bulkhead.isCallPermitted(); Maybe.just(1) .lift(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0); }
@Test public void shouldReleaseBulkheadOnlyOnce() { Single.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); } }
@Test public void shouldPropagateError() { Single.error(new IOException("BAM!")) .lift(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(IOException.class) .assertNotComplete(); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@Test public void shouldEmitAllEvents() { Single.just(1) .lift(BulkheadOperator.of(bulkhead)) .test() .assertResult(1); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@Test public void shouldEmitErrorWithBulkheadFullException() { bulkhead.isCallPermitted(); Flowable.fromArray("Event 1", "Event 2") .lift(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0); }
@Test public void shouldEmitAllEvents() { Flowable.fromArray("Event 1", "Event 2") .lift(BulkheadOperator.of(bulkhead)) .test() .assertResult("Event 1", "Event 2"); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@Test public void shouldDecorateCheckedConsumerAndReturnWithSuccess() throws Throwable { // Given Bulkhead bulkhead = Bulkhead.of("test", config); // When Bulkhead.decorateCheckedConsumer(bulkhead, helloWorldService::sayHelloWorldWithNameWithException) .accept("Tom"); // Then assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); BDDMockito.then(helloWorldService).should(times(1)).sayHelloWorldWithNameWithException("Tom"); }
@Test public void shouldEmitErrorWithBulkheadFullException() { bulkhead.isCallPermitted(); Completable.complete() .lift(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0); }
@Test public void shouldPropagateError() { Completable.error(new IOException("BAM!")) .lift(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(IOException.class) .assertNotComplete(); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@Test public void shouldEmitEvent() { StepVerifier.create( Flux.just("Event 1", "Event 2") .transform(BulkheadOperator.of(bulkhead))) .expectNext("Event 1") .expectNext("Event 2") .verifyComplete(); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@Test public void shouldPropagateError() { Observable.error(new IOException("BAM!")) .lift(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(IOException.class) .assertNotComplete(); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@Override public void bindTo(MeterRegistry registry) { for (Bulkhead bulkhead : bulkheads) { final String name = bulkhead.getName(); Gauge.builder(getName(prefix, name, AVAILABLE_CONCURRENT_CALLS), bulkhead, (cb) -> cb.getMetrics().getAvailableConcurrentCalls()) .register(registry); } } }
@Test public void shouldEmitErrorWithBulkheadFullException() { bulkhead.isCallPermitted(); Single.just(1) .lift(BulkheadOperator.of(bulkhead)) .test() .assertSubscribed() .assertError(BulkheadFullException.class) .assertNotComplete(); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(0); }
@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 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(); }
@Test public void shouldDecorateCheckedSupplierAndReturnWithSuccess() throws Throwable { // Given Bulkhead bulkhead = Bulkhead.of("test", config); BDDMockito.given(helloWorldService.returnHelloWorldWithException()).willReturn("Hello world"); // When CheckedFunction0<String> checkedSupplier = Bulkhead.decorateCheckedSupplier(bulkhead, helloWorldService::returnHelloWorldWithException); // Then assertThat(checkedSupplier.apply()).isEqualTo("Hello world"); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorldWithException(); }
@Test public void shouldDecorateSupplierAndReturnWithSuccess() { // Given Bulkhead bulkhead = Bulkhead.of("test", config); BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world"); // When Supplier<String> supplier = Bulkhead.decorateSupplier(bulkhead, helloWorldService::returnHelloWorld); // Then assertThat(supplier.get()).isEqualTo("Hello world"); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld(); }
@Test public void shouldEmitAllEvents() { Observable.fromArray("Event 1", "Event 2") .lift(BulkheadOperator.of(bulkhead)) .test() .assertResult("Event 1", "Event 2"); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(1); }
@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); } }