Java Code Examples for io.github.resilience4j.bulkhead.Bulkhead#of()

The following examples show how to use io.github.resilience4j.bulkhead.Bulkhead#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TaggedBulkheadMetricsTest.java    From resilience4j with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReplaceMetrics() {
    Collection<Gauge> gauges = meterRegistry
        .get(DEFAULT_BULKHEAD_MAX_ALLOWED_CONCURRENT_CALLS_METRIC_NAME).gauges();

    Optional<Gauge> successful = findMeterByNamesTag(gauges, bulkhead.getName());
    assertThat(successful).isPresent();
    assertThat(successful.get().value())
        .isEqualTo(bulkhead.getMetrics().getMaxAllowedConcurrentCalls());

    Bulkhead newBulkhead = Bulkhead.of(bulkhead.getName(), BulkheadConfig.custom()
        .maxConcurrentCalls(100).build());

    bulkheadRegistry.replace(bulkhead.getName(), newBulkhead);

    gauges = meterRegistry.get(DEFAULT_BULKHEAD_MAX_ALLOWED_CONCURRENT_CALLS_METRIC_NAME)
        .gauges();

    successful = findMeterByNamesTag(gauges, newBulkhead.getName());
    assertThat(successful).isPresent();
    assertThat(successful.get().value())
        .isEqualTo(newBulkhead.getMetrics().getMaxAllowedConcurrentCalls());

}
 
Example 2
Source File: TaggedBulkheadMetricsPublisherTest.java    From resilience4j with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReplaceMetrics() {
    Collection<Gauge> gauges = meterRegistry
        .get(DEFAULT_BULKHEAD_MAX_ALLOWED_CONCURRENT_CALLS_METRIC_NAME).gauges();

    Optional<Gauge> successful = findMeterByNamesTag(gauges, bulkhead.getName());
    assertThat(successful).isPresent();
    assertThat(successful.get().value())
        .isEqualTo(bulkhead.getMetrics().getMaxAllowedConcurrentCalls());

    Bulkhead newBulkhead = Bulkhead.of(bulkhead.getName(), BulkheadConfig.custom()
        .maxConcurrentCalls(100).build());

    bulkheadRegistry.replace(bulkhead.getName(), newBulkhead);

    gauges = meterRegistry.get(DEFAULT_BULKHEAD_MAX_ALLOWED_CONCURRENT_CALLS_METRIC_NAME)
        .gauges();

    successful = findMeterByNamesTag(gauges, newBulkhead.getName());
    assertThat(successful).isPresent();
    assertThat(successful.get().value())
        .isEqualTo(newBulkhead.getMetrics().getMaxAllowedConcurrentCalls());

}
 
Example 3
Source File: AsyncSqsClientImpl.java    From dynein with Apache License 2.0 5 votes vote down vote up
AsyncSqsClientImpl(
    @NonNull final SqsAsyncClient client,
    @NonNull final AsyncConveyorMetrics metrics,
    @NonNull final ExecutorService executor,
    long maxCacheSize,
    int receiveWaitTimeoutSeconds,
    int bulkheadMaxWaitMillis,
    int consumerConcurrency) {

  this.client = client;
  this.metrics = metrics;
  this.urlCache = initUrlCache(maxCacheSize);
  this.executor = executor;
  this.receiveWaitTimeoutSeconds = receiveWaitTimeoutSeconds;
  this.bulkhead =
      Bulkhead.of(
          "conveyor-async",
          BulkheadConfig.custom()
              .maxConcurrentCalls(consumerConcurrency)
              .maxWaitTimeDuration(Duration.ofMillis(bulkheadMaxWaitMillis))
              .build());
  this.bulkhead
      .getEventPublisher()
      .onCallPermitted(event -> metrics.consumePermitted())
      .onCallFinished(event -> metrics.consumeFinished())
      .onCallRejected(event -> metrics.consumeRejected())
      .onEvent(event -> metrics.bulkheadMetrics(this.bulkhead.getMetrics()));
}
 
Example 4
Source File: ConcurrentBulkheadTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
public ConcurrentBulkheadTest() {

        bulkhead = Bulkhead.of("test", BulkheadConfig.custom().maxConcurrentCalls(1).build());

        callRejectectedEventSubscriber = RxJava2Adapter.toFlowable(bulkhead.getEventPublisher())
            .filter(event -> event.getEventType() == Type.CALL_REJECTED)
            .map(BulkheadEvent::getEventType)
            .test();
    }
 
Example 5
Source File: SemaphoreBulkheadTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    BulkheadConfig config = BulkheadConfig.custom()
        .maxConcurrentCalls(2)
        .maxWaitDuration(Duration.ofMillis(0))
        .build();
    bulkhead = Bulkhead.of("test", config);
    testSubscriber = RxJava2Adapter.toFlowable(bulkhead.getEventPublisher())
        .map(BulkheadEvent::getEventType)
        .test();
}
 
Example 6
Source File: TaggedBulkheadMetricsPublisherTest.java    From resilience4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplaceNewMeter(){
    Bulkhead oldOne = Bulkhead.of("backendC", BulkheadConfig.ofDefaults());
    // add meters of old
    taggedBulkheadMetricsPublisher.addMetrics(meterRegistry, oldOne);
    // one success call
    oldOne.tryAcquirePermission();

    assertThat(taggedBulkheadMetricsPublisher.meterIdMap).containsKeys("backendC");
    assertThat(taggedBulkheadMetricsPublisher.meterIdMap.get("backendC")).hasSize(2);
    Collection<Gauge> gauges = meterRegistry
        .get(DEFAULT_BULKHEAD_MAX_ALLOWED_CONCURRENT_CALLS_METRIC_NAME).gauges();
    Optional<Gauge> successful = findMeterByNamesTag(gauges, oldOne.getName());
    assertThat(successful).isPresent();
    assertThat(successful.get().value())
        .isEqualTo(oldOne.getMetrics().getMaxAllowedConcurrentCalls());

    Bulkhead newOne = Bulkhead.of("backendC", BulkheadConfig.ofDefaults());

    // add meters of new
    taggedBulkheadMetricsPublisher.addMetrics(meterRegistry, newOne);
    // three success call
    newOne.tryAcquirePermission();
    newOne.tryAcquirePermission();
    newOne.tryAcquirePermission();

    assertThat(taggedBulkheadMetricsPublisher.meterIdMap).containsKeys("backendC");
    assertThat(taggedBulkheadMetricsPublisher.meterIdMap.get("backendC")).hasSize(2);
    gauges = meterRegistry
        .get(DEFAULT_BULKHEAD_MAX_ALLOWED_CONCURRENT_CALLS_METRIC_NAME).gauges();
    successful = findMeterByNamesTag(gauges, newOne.getName());
    assertThat(successful).isPresent();
    assertThat(successful.get().value())
        .isEqualTo(newOne.getMetrics().getMaxAllowedConcurrentCalls());

}