Skip to content

Fix SonarCloud code smells #3991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
@SdkPublicApi
public final class TokenAcquisitionFailedException extends RuntimeException {
private final RetryToken token;
private final transient RetryToken token;

/**
* Exception construction accepting message with no root cause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

public class RetryStrategyBuilderTest {
class RetryStrategyBuilderTest {

public static Collection<TestCase> parameters() {
static Collection<TestCase> parameters() {
return Arrays.asList(
new TestCase()
.configure(b -> b.retryOnException(IllegalArgumentException.class))
Expand Down Expand Up @@ -105,7 +105,7 @@ public static Collection<TestCase> parameters() {

@ParameterizedTest
@MethodSource("parameters")
public void testCase(TestCase testCase) {
void testCase(TestCase testCase) {
assertThat(testCase.run()).isEqualTo(testCase.expected());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

public class ExponentialDelayWithJitterTest {
class ExponentialDelayWithJitterTest {
static final ComputedNextInt MIN_VALUE_RND = new ComputedNextInt(bound -> 0);
static final ComputedNextInt MID_VALUE_RND = new ComputedNextInt(bound -> bound / 2);
static final ComputedNextInt MAX_VALUE_RND = new ComputedNextInt(bound -> bound - 1);
static final Duration BASE_DELAY = Duration.ofMillis(23);
static final Duration MAX_DELAY = Duration.ofSeconds(20);

public static Collection<TestCase> parameters() {
static Collection<TestCase> parameters() {
return Arrays.asList(
// --- Using random that returns: bound - 1
new TestCase()
Expand Down Expand Up @@ -126,7 +126,7 @@ public static Collection<TestCase> parameters() {

@ParameterizedTest
@MethodSource("parameters")
public void testCase(TestCase testCase) {
void testCase(TestCase testCase) {
assertThat(testCase.run()).isEqualTo(testCase.expected());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

public class FixedDelayWithJitterTest {
class FixedDelayWithJitterTest {
static final ComputedNextInt MIN_VALUE_RND = new ComputedNextInt(bound -> 0);
static final ComputedNextInt MID_VALUE_RND = new ComputedNextInt(bound -> bound / 2);
static final ComputedNextInt MAX_VALUE_RND = new ComputedNextInt(bound -> bound - 1);
static final Duration BASE_DELAY = Duration.ofMillis(23);

public static Collection<TestCase> parameters() {
static Collection<TestCase> parameters() {
return Arrays.asList(
// --- Using random that returns: bound - 1
new TestCase()
Expand Down Expand Up @@ -126,7 +126,7 @@ public static Collection<TestCase> parameters() {

@ParameterizedTest
@MethodSource("parameters")
public void testCase(TestCase testCase) {
void testCase(TestCase testCase) {
assertThat(testCase.run()).isEqualTo(testCase.expected());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
* are made to a very resource-constrained set of resources, and we expect that the delays created by the rate limiter allows the
* perceived availability for the clients to be close to 1.0.
*/
public class AdaptiveRetryStrategyResourceConstrainedTest {
class AdaptiveRetryStrategyResourceConstrainedTest {

@Test
public void seemsToBeCorrectAndThreadSafe() {
void seemsToBeCorrectAndThreadSafe() {
// Arrange the test. We allocate a single thread for each server worker
// and for each client worker.
int serverWorkers = 1;
Expand Down Expand Up @@ -93,7 +93,7 @@ public void seemsToBeCorrectAndThreadSafe() {
executor.shutdown();
}

public static List<Client> createClients(Server server, AdaptiveRetryStrategy strategy, int amount, int jobsPerClient) {
private static List<Client> createClients(Server server, AdaptiveRetryStrategy strategy, int amount, int jobsPerClient) {
return IntStream.range(0, amount)
.mapToObj(idx -> createClient(server, strategy, jobsPerClient))
.collect(Collectors.toCollection(() -> new ArrayList<>(amount)));
Expand All @@ -103,7 +103,7 @@ private static Client createClient(Server server, AdaptiveRetryStrategy strategy
return new Client(createJobs(jobs), server, strategy);
}

public static List<Job> createJobs(int amount) {
private static List<Job> createJobs(int amount) {
// We use a non-small but fixed size here instead of random ones to have a more predictable workload.
int rows = 256;
int cols = 256 + 128;
Expand Down Expand Up @@ -142,13 +142,13 @@ static class Client {
this.strategy = strategy;
}

public void processAllJobs() {
void processAllJobs() {
for (Job job : jobs) {
process(job);
}
}

public void process(Job job) {
void process(Job job) {
// submit job
AcquireInitialTokenResponse response = strategy.acquireInitialToken(AcquireInitialTokenRequest.create("client"));
RetryToken token = response.token();
Expand Down Expand Up @@ -222,7 +222,7 @@ void stop() {
CompletableFuture.allOf(workers.toArray(new CompletableFuture[0])).join();
}

public void accept(Job job) {
void accept(Job job) {
if (!jobQueue.offer(job)) {
// No space left in the queue to take this job, throw a ThrottlingException to notify the
// client about it and let him retry at a later time.
Expand All @@ -238,6 +238,7 @@ static class ServerWorker implements Runnable {
this.jobQueue = jobQueue;
}

@Override
public void run() {
while (true) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public AcquireInitialTokenResponse acquireInitialToken(AcquireInitialTokenReques
@Override
public RefreshRetryTokenResponse refreshRetryToken(RefreshRetryTokenRequest request) {
DefaultRetryToken token = asStandardRetryToken(request.token());
AcquireResponse acquireResponse = requestAcquireCapacity(request, token);
AcquireResponse acquireResponse = requestAcquireCapacity(token);

// Check if we meet the preconditions needed for retrying. These will throw if the expected condition is not meet.
// 1) is retryable?
Expand Down Expand Up @@ -291,7 +291,7 @@ static DefaultRetryToken asStandardRetryToken(RetryToken token) {
token.getClass().getName());
}

private AcquireResponse requestAcquireCapacity(RefreshRetryTokenRequest request, DefaultRetryToken token) {
private AcquireResponse requestAcquireCapacity(DefaultRetryToken token) {
TokenBucket tokenBucket = tokenBucketStore.tokenBucketForScope(token.scope());
return tokenBucket.tryAcquire(exceptionCost);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public AcquireInitialTokenResponse acquireInitialToken(AcquireInitialTokenReques
@Override
public RefreshRetryTokenResponse refreshRetryToken(RefreshRetryTokenRequest request) {
DefaultRetryToken token = asStandardRetryToken(request.token());
AcquireResponse acquireResponse = requestAcquireCapacity(request, token);
AcquireResponse acquireResponse = requestAcquireCapacity(token);

// Check if we meet the preconditions needed for retrying. These will throw if the expected condition is not meet.
// 1) is retryable?
Expand Down Expand Up @@ -263,7 +263,7 @@ static DefaultRetryToken asStandardRetryToken(RetryToken token) {
token.getClass().getName());
}

private AcquireResponse requestAcquireCapacity(RefreshRetryTokenRequest request, DefaultRetryToken token) {
private AcquireResponse requestAcquireCapacity(DefaultRetryToken token) {
TokenBucket tokenBucket = tokenBucketStore.tokenBucketForScope(token.scope());
if (!circuitBreakerEnabled) {
return tokenBucket.tryAcquire(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
// The tests here are the same set of test from the StandardRetryStrategy, both should be passing the same battery of tests.
// Unfortunately It's not possible to create a single parametrized test on RetryStrategy given the different types required to
// configure each strategy.
public class AdaptiveRetryStrategyTest {
class AdaptiveRetryStrategyTest {
static final int TEST_BUCKET_CAPACITY = 100;
static final int TEST_EXCEPTION_COST = 5;
static final IllegalArgumentException IAE = new IllegalArgumentException();
static final RuntimeException RTE = new RuntimeException();

@ParameterizedTest
@MethodSource("parameters")
public void testCase(TestCase testCase) {
void testCase(TestCase testCase) {
testCase.run();
if (testCase.shouldSucceed) {
assertThat(testCase.thrown)
Expand All @@ -68,7 +68,7 @@ public void testCase(TestCase testCase) {
assertThat(testCase.token.state()).as(testCase.name).isEqualTo(testCase.expectedState);
}

public static Collection<TestCase> parameters() {
static Collection<TestCase> parameters() {
BackoffStrategy backoff = BackoffStrategy.exponentialDelay(Duration.ofMillis(10), Duration.ofSeconds(25));
return Arrays.asList(
new TestCase("Succeeds when no exceptions are thrown")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
* Tests that the circuit breaker remembers its previous state for separated
* requests.
*/
public class StandardRetryStrategyMiscTest {
class StandardRetryStrategyMiscTest {
static final int TEST_EXCEPTION_COST = 5;
static final int TEST_MAX = 50;
static final IllegalArgumentException IAE = new IllegalArgumentException();
static final RuntimeException RTE = new RuntimeException();

@Test
public void circuitBreakerRemembersState() {
void circuitBreakerRemembersState() {
BackoffStrategy backoff = BackoffStrategy.exponentialDelay(Duration.ofMillis(10), Duration.ofSeconds(25));
TestCase testCase = new TestCase("circuit breaker remembers state")
.configure(b -> b.maxAttempts(3))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@
import software.amazon.awssdk.retries.api.internal.AcquireInitialTokenRequestImpl;
import software.amazon.awssdk.retries.internal.circuitbreaker.TokenBucketStore;

public class StandardRetryStrategyTest {
class StandardRetryStrategyTest {
static final int TEST_BUCKET_CAPACITY = 100;
static final int TEST_EXCEPTION_COST = 5;
static final IllegalArgumentException IAE = new IllegalArgumentException();
static final RuntimeException RTE = new RuntimeException();

@ParameterizedTest
@MethodSource("parameters")
public void testCase(TestCase testCase) {
void testCase(TestCase testCase) {
testCase.run();
if (testCase.shouldSucceed) {
assertThat(testCase.thrown)
Expand All @@ -65,7 +65,7 @@ public void testCase(TestCase testCase) {

}

public static Collection<TestCase> parameters() {
static Collection<TestCase> parameters() {
BackoffStrategy backoff = BackoffStrategy.exponentialDelay(Duration.ofMillis(10), Duration.ofSeconds(25));
return Arrays.asList(
new TestCase("Succeeds when no exceptions are thrown")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

public class RateLimiterTokenBucketTest {
class RateLimiterTokenBucketTest {
private static MutableClock clock = null;
private static RateLimiterTokenBucket tokenBucket = null;
private static final double EPSILON = 0.0001;
Expand All @@ -37,7 +37,7 @@ static void setup() {

@ParameterizedTest
@MethodSource("parameters")
public void testCase(TestCase testCase) {
void testCase(TestCase testCase) {
clock.setCurrent(testCase.givenTimestamp);
RateLimiterUpdateResponse res;
tokenBucket.tryAcquire();
Expand All @@ -53,7 +53,7 @@ public void testCase(TestCase testCase) {
}


public static Collection<TestCase> parameters() {
static Collection<TestCase> parameters() {
return Arrays.asList(
new TestCase()
.givenSuccessResponse()
Expand Down