use of io.github.resilience4j.bulkhead.BulkheadRegistry in project resilience4j by resilience4j.
the class BulkheadMetricsTest method shouldUseCustomPrefix.
@Test
public void shouldUseCustomPrefix() throws Throwable {
// Given
BulkheadRegistry bulkheadRegistry = BulkheadRegistry.ofDefaults();
Bulkhead bulkhead = bulkheadRegistry.bulkhead("testBulkhead");
metricRegistry.registerAll(BulkheadMetrics.ofIterable("testPre", bulkheadRegistry.getAllBulkheads()));
// Given latch to verify bulkhead
CountDownLatch countDownLatch = new CountDownLatch(1);
// Given the HelloWorldService returns Hello world
BDDMockito.given(helloWorldService.returnHelloWorld()).will(invocation -> {
if (countDownLatch.await(10, TimeUnit.SECONDS)) {
return "Hello world";
} else {
throw new IllegalStateException("Timeout - test failure");
}
});
// When
Future<String> future = executorService.submit(() -> bulkhead.executeSupplier(helloWorldService::returnHelloWorld));
// Then metrics are present and show value
assertThat(metricRegistry.getMetrics()).hasSize(1);
assertThat(metricRegistry.getGauges().get("testPre.testBulkhead.available_concurrent_calls").getValue()).isIn(DEFAULT_MAX_CONCURRENT_CALLS, DEFAULT_MAX_CONCURRENT_CALLS - 1);
// Then release latch and verify result
countDownLatch.countDown();
assertThat(future.get(10, TimeUnit.SECONDS)).isEqualTo("Hello world");
BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld();
// Then check metrics again
assertThat(metricRegistry.getMetrics()).hasSize(1);
assertThat(metricRegistry.getGauges().get("testPre.testBulkhead.available_concurrent_calls").getValue()).isIn(DEFAULT_MAX_CONCURRENT_CALLS, DEFAULT_MAX_CONCURRENT_CALLS);
}
use of io.github.resilience4j.bulkhead.BulkheadRegistry in project resilience4j by resilience4j.
the class BulkheadMetricsTest method shouldRegisterMetrics.
@Test
public void shouldRegisterMetrics() throws Throwable {
// Given
BulkheadRegistry bulkheadRegistry = BulkheadRegistry.ofDefaults();
Bulkhead bulkhead = bulkheadRegistry.bulkhead("testBulkhead");
metricRegistry.registerAll(BulkheadMetrics.ofBulkhead(bulkhead));
// Given latch to verify bulkhead
CountDownLatch countDownLatch = new CountDownLatch(1);
// Given the HelloWorldService returns Hello world
BDDMockito.given(helloWorldService.returnHelloWorld()).will(invocation -> {
if (countDownLatch.await(10, TimeUnit.SECONDS)) {
return "Hello world";
} else {
throw new IllegalStateException("Timeout - test failure");
}
});
// When
Future<String> future = executorService.submit(() -> bulkhead.executeSupplier(helloWorldService::returnHelloWorld));
// Then metrics are present and show value
assertThat(metricRegistry.getMetrics()).hasSize(1);
assertThat(metricRegistry.getGauges().get("resilience4j.bulkhead.testBulkhead.available_concurrent_calls").getValue()).isIn(DEFAULT_MAX_CONCURRENT_CALLS, DEFAULT_MAX_CONCURRENT_CALLS - 1);
// Then release latch and verify result
countDownLatch.countDown();
assertThat(future.get(10, TimeUnit.SECONDS)).isEqualTo("Hello world");
BDDMockito.then(helloWorldService).should(times(1)).returnHelloWorld();
// Then check metrics again
assertThat(metricRegistry.getMetrics()).hasSize(1);
assertThat(metricRegistry.getGauges().get("resilience4j.bulkhead.testBulkhead.available_concurrent_calls").getValue()).isIn(DEFAULT_MAX_CONCURRENT_CALLS, DEFAULT_MAX_CONCURRENT_CALLS);
}
use of io.github.resilience4j.bulkhead.BulkheadRegistry in project resilience4j by resilience4j.
the class BulkheadMetricsTest method shouldRegisterMetrics.
@Test
public void shouldRegisterMetrics() {
BulkheadRegistry bulkheadRegistry = BulkheadRegistry.ofDefaults();
bulkheadRegistry.bulkhead("testName");
BulkheadMetrics bulkheadMetrics = BulkheadMetrics.ofBulkheadRegistry(bulkheadRegistry);
bulkheadMetrics.bindTo(meterRegistry);
final List<String> metricNames = meterRegistry.getMeters().stream().map(Meter::getId).map(Meter.Id::getName).collect(Collectors.toList());
final List<String> expectedMetrics = newArrayList("resilience4j.bulkhead.testName.available_concurrent_calls");
assertThat(metricNames).hasSameElementsAs(expectedMetrics);
}
Aggregations