11package redis .clients .jedis .scenario ;
22
3+ import io .github .resilience4j .ratelimiter .RateLimiter ;
4+ import io .github .resilience4j .ratelimiter .RateLimiterConfig ;
5+ import io .github .resilience4j .ratelimiter .RateLimiterRegistry ;
36import redis .clients .jedis .UnifiedJedis ;
47import redis .clients .jedis .exceptions .JedisConnectionException ;
58
1114public class MultiThreadedFakeApp extends FakeApp {
1215
1316 private final ExecutorService executorService ;
17+ private final RateLimiter rateLimiter ;
1418
1519 public MultiThreadedFakeApp (UnifiedJedis client , FakeApp .ExecutedAction action , int numThreads ) {
20+ this (client , action , numThreads , null );
21+ }
22+
23+ public MultiThreadedFakeApp (UnifiedJedis client , FakeApp .ExecutedAction action , int numThreads , RateLimiterConfig config ) {
1624 super (client , action );
1725 this .executorService = Executors .newFixedThreadPool (numThreads );
26+
27+ if (config != null ) {
28+ this .rateLimiter = RateLimiterRegistry .of (config ).rateLimiter ("fakeAppLimiter" );
29+ } else {
30+ this .rateLimiter = null ;
31+ }
1832 }
1933
2034 @ Override
@@ -28,6 +42,9 @@ public void run() {
2842 Duration .ofSeconds (checkEachSeconds ), Duration .ofSeconds (keepExecutingForSeconds ),
2943 Duration .ofSeconds (timeoutSeconds ))) {
3044 try {
45+ if (rateLimiter != null ) {
46+ RateLimiter .waitForPermission (rateLimiter );
47+ }
3148 executorService .submit (() -> action .run (client ));
3249 } catch (JedisConnectionException e ) {
3350 log .error ("Error executing action" , e );
0 commit comments