@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(); }
@Test public void shouldConsumeOnCallPermittedEvent() { // Given Bulkhead bulkhead = Bulkhead.of("test", config); BDDMockito.given(helloWorldService.returnHelloWorld()).willReturn("Hello world"); // When bulkhead.getEventPublisher() .onCallPermitted(event -> logger.info(event.getEventType().toString())); String result = bulkhead.executeSupplier(helloWorldService::returnHelloWorld); // Then assertThat(result).isEqualTo("Hello world"); then(logger).should(times(1)).info("CALL_PERMITTED"); }
Future<String> future = executorService.submit(() -> bulkhead.executeSupplier(helloWorldService::returnHelloWorld));
Future<String> future = executorService.submit(() -> bulkhead.executeSupplier(helloWorldService::returnHelloWorld));