/** * Creates a bulkhead with a default config. * * @param name the name of this bulkhead */ public SemaphoreBulkhead(String name) { this(name, BulkheadConfig.ofDefaults()); }
/** * Returns a builder to create a custom BulkheadConfig. * * @return a {@link Builder} */ public static Builder custom(){ return new Builder(); }
public static void isCallPermitted(Bulkhead bulkhead) { if(!bulkhead.isCallPermitted()) { throw new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); } } }
@Override protected Throwable getThrowable() { return new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); }
@Before public void setUp() { // registry with default config registry = BulkheadRegistry.ofDefaults(); // registry with custom config config = BulkheadConfig.custom() .maxConcurrentCalls(100) .maxWaitTime(50) .build(); }
@Before public void setUp() { BulkheadConfig config = BulkheadConfig.custom() .maxConcurrentCalls(2) .maxWaitTime(0) .build(); bulkhead = Bulkhead.of("test", config); testSubscriber = RxJava2Adapter.toFlowable(bulkhead.getEventPublisher()) .map(BulkheadEvent::getEventType) .test(); }
@Before public void setUp(){ helloWorldService = mock(HelloWorldService.class); config = BulkheadConfig.custom() .maxConcurrentCalls(1) .build(); bulkhead= Bulkhead.of("test", config); logger = mock(Logger.class); }
@Override protected boolean isCallPermitted() { return bulkhead.isCallPermitted(); }
@Test(expected = IllegalArgumentException.class) public void testBuildWithIllegalMaxConcurrent() { // when BulkheadConfig.custom() .maxConcurrentCalls(-1) .build(); }
@Test(expected = IllegalArgumentException.class) public void testBuildWithIllegalMaxWait() { // when BulkheadConfig.custom() .maxWaitTime(-1) .build(); }
public DecorateRunnable withBulkhead(Bulkhead bulkhead) { runnable = Bulkhead.decorateRunnable(bulkhead, runnable); return this; }
public DecorateCompletionStage<T> withBulkhead(Bulkhead bulkhead) { stageSupplier = Bulkhead.decorateCompletionStage(bulkhead, stageSupplier); return this; }
public DecorateSupplier<T> withBulkhead(Bulkhead bulkhead) { supplier = Bulkhead.decorateSupplier(bulkhead, supplier); return this; }
public DecorateCheckedFunction<T, R> withBulkhead(Bulkhead bulkhead) { function = Bulkhead.decorateCheckedFunction(bulkhead, function); return this; }
public DecorateCheckedRunnable withBulkhead(Bulkhead bulkhead) { runnable = Bulkhead.decorateCheckedRunnable(bulkhead, runnable); return this; }
public DecorateConsumer<T> withBulkhead(Bulkhead bulkhead) { consumer = Bulkhead.decorateConsumer(bulkhead, consumer); return this; }
public DecorateCheckedSupplier<T> withBulkhead(Bulkhead bulkhead) { supplier = Bulkhead.decorateCheckedSupplier(bulkhead, supplier); return this; }
public DecorateFunction<T, R> withBulkhead(Bulkhead bulkhead) { function = Bulkhead.decorateFunction(bulkhead, function); return this; }
private Exception bulkheadFullException() { return new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); }