/** * Creates a new instance of {@link BulkheadExports} with specified metrics names prefix and * {@link Supplier} of bulkheads * * @param prefix the prefix of metrics names * @param bulkheadSupplier the supplier of bulkheads */ public static BulkheadExports ofSupplier(String prefix, Supplier<Iterable<Bulkhead>> bulkheadSupplier) { return new BulkheadExports(prefix, bulkheadSupplier); }
@Test public void testConstructors() { final BulkheadRegistry registry = new InMemoryBulkheadRegistry(BulkheadConfig.ofDefaults()); BulkheadExports.ofIterable("boo_bulkheads", singleton(Bulkhead.ofDefaults("foo"))); BulkheadExports.ofBulkheadRegistry("boo_bulkheads", registry); BulkheadExports.ofSupplier("boo_bulkheads", () -> singleton(Bulkhead.ofDefaults("foo"))); BulkheadExports.ofIterable(singleton(Bulkhead.ofDefaults("foo"))); BulkheadExports.ofBulkheadRegistry(registry); BulkheadExports.ofSupplier(() -> singleton(Bulkhead.ofDefaults("foo"))); }
@Test public void testExportsCircuitBreakerStates() { // Given final CollectorRegistry registry = new CollectorRegistry(); final Bulkhead bulkhead = Bulkhead.ofDefaults("foo"); BulkheadExports.ofIterable("boo_bulkhead", singletonList(bulkhead)).register(registry); final Supplier<Map<String, Double>> values = () -> HashSet .of("available_concurrent_calls") .map(param -> Tuple.of(param, registry.getSampleValue( "boo_bulkhead", new String[]{"name", "param"}, new String[]{"foo", param}))) .toMap(t -> t); // When final Map<String, Double> initialValues = values.get(); // Then assertThat(initialValues).isEqualTo(HashMap.of("available_concurrent_calls", 25.0)); }
@Test(expected = NullPointerException.class) public void testConstructorWithNullSupplier() { BulkheadExports.ofSupplier("boo_bulkheads", null); } }
@Test(expected = NullPointerException.class) public void testConstructorWithNullName() { BulkheadExports.ofSupplier(null, () -> singleton(Bulkhead.ofDefaults("foo"))); }
/** * Creates a new instance of {@link BulkheadExports} with default metrics names prefix and * {@link Iterable} of bulkheads. * * @param bulkheads the bulkheads */ public static BulkheadExports ofIterable(Iterable<Bulkhead> bulkheads) { return new BulkheadExports(bulkheads); }
/** * Creates a new instance of {@link BulkheadExports} with specified metrics names prefix and * {@link BulkheadRegistry} as a source of bulkheads. * * @param prefix the prefix of metrics names * @param bulkheadRegistry the registry of bulkheads */ public static BulkheadExports ofBulkheadRegistry(String prefix, BulkheadRegistry bulkheadRegistry) { return new BulkheadExports(prefix, bulkheadRegistry); }
/** * Creates a new instance of {@link BulkheadExports} with default metrics names prefix and * {@link Supplier} of bulkheads * * @param bulkheadSupplier the supplier of bulkheads */ public static BulkheadExports ofSupplier(Supplier<Iterable<Bulkhead>> bulkheadSupplier) { return new BulkheadExports(DEFAULT_NAME, bulkheadSupplier); }
/** * Creates a new instance of {@link BulkheadExports} with specified metrics names prefix and * {@link Iterable} of bulkheads. * * @param prefix the prefix of metrics names * @param bulkheads the bulkheads */ public static BulkheadExports ofIterable(String prefix, Iterable<Bulkhead> bulkheads) { return new BulkheadExports(prefix, bulkheads); }
/** * Creates a new instance of {@link BulkheadExports} with default metrics names prefix and * a bulkhead as a source. * * @param bulkhead the bulkhead */ public static BulkheadExports ofBulkhead(Bulkhead bulkhead) { return new BulkheadExports(Array.of(bulkhead)); }
/** * Creates a new instance of {@link BulkheadExports} with default metrics names prefix and * {@link BulkheadRegistry} as a source of bulkheads. * @param bulkheadRegistry the registry of bulkheads */ public static BulkheadExports ofBulkheadRegistry(BulkheadRegistry bulkheadRegistry) { return new BulkheadExports(bulkheadRegistry.getAllBulkheads()); }
/** * Creates a new instance of {@link BulkheadExports} with default metrics names prefix and * a bulkhead as a source. * * @param prefix the prefix of metrics names * @param bulkhead the bulkhead */ public static BulkheadExports ofBulkhead(String prefix, Bulkhead bulkhead) { return new BulkheadExports(prefix, Array.of(bulkhead)); }