|
1 | 1 | package com.iluwatar.rate.limiting.pattern; |
2 | 2 |
|
| 3 | +import java.security.SecureRandom; |
3 | 4 | import java.util.concurrent.*; |
4 | 5 | import java.util.concurrent.atomic.AtomicBoolean; |
5 | 6 | import java.util.concurrent.atomic.AtomicInteger; |
@@ -101,13 +102,13 @@ private static void shutdownExecutor(ExecutorService service, String name) { |
101 | 102 |
|
102 | 103 | static Runnable createClientTask( |
103 | 104 | int clientId, RateLimiter s3Limiter, RateLimiter dynamoDbLimiter, RateLimiter lambdaLimiter) { |
| 105 | + |
104 | 106 | return () -> { |
105 | 107 | String[] services = {"s3", "dynamodb", "lambda"}; |
106 | 108 | String[] operations = { |
107 | | - "GetObject", "PutObject", "Query", "Scan", "PutItem", "Invoke", "ListFunctions" |
| 109 | + "GetObject", "PutObject", "Query", "Scan", "PutItem", "Invoke", "ListFunctions" |
108 | 110 | }; |
109 | | - // Safe: ThreadLocalRandom is used per-thread for concurrent simulation |
110 | | - ThreadLocalRandom random = ThreadLocalRandom.current(); |
| 111 | + SecureRandom random = new SecureRandom(); // ✅ Safe & compliant for SonarCloud |
111 | 112 |
|
112 | 113 | while (running.get() && !Thread.currentThread().isInterrupted()) { |
113 | 114 | try { |
@@ -138,10 +139,7 @@ static void makeRequest(int clientId, RateLimiter limiter, String service, Strin |
138 | 139 | throttledRequests.incrementAndGet(); |
139 | 140 | LOGGER.warn( |
140 | 141 | "Client {}: {}.{} - THROTTLED (Retry in {}ms)", |
141 | | - clientId, |
142 | | - service, |
143 | | - operation, |
144 | | - e.getRetryAfterMillis()); |
| 142 | + clientId, service, operation, e.getRetryAfterMillis()); |
145 | 143 | } catch (ServiceUnavailableException e) { |
146 | 144 | failedRequests.incrementAndGet(); |
147 | 145 | LOGGER.warn("Client {}: {}.{} - SERVICE UNAVAILABLE", clientId, service, operation); |
|
0 commit comments