Java Code Examples for io.github.resilience4j.ratelimiter.RateLimiter#acquirePermission()
The following examples show how to use
io.github.resilience4j.ratelimiter.RateLimiter#acquirePermission() .
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: TaggedRateLimiterMetricsPublisherTest.java From resilience4j with Apache License 2.0 | 5 votes |
@Test public void testReplaceNewMeter() { RateLimiter oldOne = RateLimiter.of("backendC", RateLimiterConfig.ofDefaults()); // add meters of old taggedRateLimiterMetricsPublisher.addMetrics(meterRegistry, oldOne); // one permission class oldOne.acquirePermission(); assertThat(taggedRateLimiterMetricsPublisher.meterIdMap).containsKeys("backendC"); assertThat(taggedRateLimiterMetricsPublisher.meterIdMap.get("backendC")).hasSize(2); Collection<Gauge> gauges = meterRegistry.get(DEFAULT_AVAILABLE_PERMISSIONS_METRIC_NAME) .gauges(); Optional<Gauge> available = findMeterByNamesTag(gauges, oldOne.getName()); assertThat(available).isPresent(); assertThat(available.get().value()) .isEqualTo(oldOne.getMetrics().getAvailablePermissions()); RateLimiter newOne = RateLimiter.of("backendC", RateLimiterConfig.ofDefaults()); // add meters of old taggedRateLimiterMetricsPublisher.addMetrics(meterRegistry, newOne); // three permission call newOne.acquirePermission(3); assertThat(taggedRateLimiterMetricsPublisher.meterIdMap).containsKeys("backendC"); assertThat(taggedRateLimiterMetricsPublisher.meterIdMap.get("backendC")).hasSize(2); gauges = meterRegistry.get(DEFAULT_AVAILABLE_PERMISSIONS_METRIC_NAME) .gauges(); available = findMeterByNamesTag(gauges, newOne.getName()); assertThat(available).isPresent(); assertThat(available.get().value()) .isEqualTo(newOne.getMetrics().getAvailablePermissions()); }
Example 2
Source File: DecoratorsTest.java From resilience4j with Apache License 2.0 | 5 votes |
private void alignTime(RateLimiter rateLimiter) { RateLimiter.Metrics metrics = rateLimiter.getMetrics(); while (rateLimiter.acquirePermission()) { state = !state; } // Wait to the start of the next cycle in spin loop while (metrics.getAvailablePermissions() == 0) { state = !state; } System.out.println(state); }