Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

refactor(elasticache): move library usages to imports (#3899)

Vũ Thế Huy22bff32e190f
diff --git a/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java
index a24f3469fc..1a61f63e0f 100644
--- a/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandler.java
@@ -2,15 +2,15 @@ package io.github.hectorvent.floci.services.elasticache;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
-import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.AwsNamespaces;
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
+import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.XmlBuilder;
import io.github.hectorvent.floci.services.elasticache.model.AuthMode;
import io.github.hectorvent.floci.services.elasticache.model.CacheCluster;
import io.github.hectorvent.floci.services.elasticache.model.CacheParameterGroup;
-import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
import io.github.hectorvent.floci.services.elasticache.model.CacheSubnetGroup;
+import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
import io.github.hectorvent.floci.services.elasticache.model.ElastiCacheUser;
import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
@@ -23,6 +23,9 @@ import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
+import java.net.URI;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
@@ -183,7 +186,7 @@ public class ElastiCacheQueryHandler {
String filterId = params.getFirst("ReplicationGroupId");
try {
Collection<ReplicationGroup> groups = service.listReplicationGroups(filterId);
- var xml = new XmlBuilder().start("ReplicationGroups");
+ XmlBuilder xml = new XmlBuilder().start("ReplicationGroups");
for (ReplicationGroup g : groups) {
xml.raw(replicationGroupXml(g));
}
@@ -272,7 +275,7 @@ public class ElastiCacheQueryHandler {
String filterEngine = params.getFirst("Engine");
try {
Collection<ElastiCacheUser> users = service.listUsers(filterId, filterEngine);
- var xml = new XmlBuilder().start("Users");
+ XmlBuilder xml = new XmlBuilder().start("Users");
for (ElastiCacheUser u : users) {
xml.start("member").raw(userXml(u)).end("member");
}
@@ -346,7 +349,7 @@ public class ElastiCacheQueryHandler {
} else {
clusterList = memcachedService.listCacheClusters(filterId);
}
- var xml = new XmlBuilder().start("CacheClusters");
+ XmlBuilder xml = new XmlBuilder().start("CacheClusters");
for (CacheCluster c : clusterList) {
xml.raw(cacheClusterXml(c));
}
@@ -363,7 +366,7 @@ public class ElastiCacheQueryHandler {
private String memberCacheClusterXml(ElastiCacheService.MemberCacheCluster member, boolean showNodeInfo) {
ReplicationGroup g = member.group();
boolean authTokenEnabled = g.getAuthMode() == AuthMode.PASSWORD;
- var xml = new XmlBuilder()
+ XmlBuilder xml = new XmlBuilder()
.start("CacheCluster")
.elem("CacheClusterId", member.cacheClusterId())
.elem("CacheClusterStatus", memberCacheClusterStatus(g))
@@ -440,7 +443,7 @@ public class ElastiCacheQueryHandler {
params.getFirst("CacheSubnetGroupDescription"),
parseSubnetIds(params),
parseTags(params));
- var xml = new XmlBuilder();
+ XmlBuilder xml = new XmlBuilder();
appendSubnetGroup(xml, group);
return Response.ok(AwsQueryResponse.envelope("CreateCacheSubnetGroup", AwsNamespaces.EC, xml.build())).build();
} catch (AwsException e) {
@@ -452,7 +455,7 @@ public class ElastiCacheQueryHandler {
try {
List<CacheSubnetGroup> groups =
service.describeCacheSubnetGroups(params.getFirst("CacheSubnetGroupName"));
- var xml = new XmlBuilder().start("CacheSubnetGroups");
+ XmlBuilder xml = new XmlBuilder().start("CacheSubnetGroups");
groups.forEach(group -> appendSubnetGroup(xml, group));
xml.end("CacheSubnetGroups");
return Response.ok(AwsQueryResponse.envelope("DescribeCacheSubnetGroups", AwsNamespaces.EC, xml.build())).build();
@@ -467,7 +470,7 @@ public class ElastiCacheQueryHandler {
params.getFirst("CacheSubnetGroupName"),
params.getFirst("CacheSubnetGroupDescription"),
parseSubnetIds(params));
- var xml = new XmlBuilder();
+ XmlBuilder xml = new XmlBuilder();
appendSubnetGroup(xml, group);
return Response.ok(AwsQueryResponse.envelope("ModifyCacheSubnetGroup", AwsNamespaces.EC, xml.build())).build();
} catch (AwsException e) {
@@ -525,7 +528,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
params.getFirst("CacheParameterGroupFamily"),
params.getFirst("Description"),
parseTags(params));
- var xml = new XmlBuilder();
+ XmlBuilder xml = new XmlBuilder();
appendParameterGroup(xml, group);
return Response.ok(AwsQueryResponse.envelope("CreateCacheParameterGroup", AwsNamespaces.EC, xml.build())).build();
} catch (AwsException e) {
@@ -537,7 +540,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
try {
List<CacheParameterGroup> groups =
service.describeCacheParameterGroups(params.getFirst("CacheParameterGroupName"));
- var xml = new XmlBuilder().start("CacheParameterGroups");
+ XmlBuilder xml = new XmlBuilder().start("CacheParameterGroups");
groups.forEach(group -> appendParameterGroup(xml, group));
xml.end("CacheParameterGroups");
return Response.ok(AwsQueryResponse.envelope("DescribeCacheParameterGroups", AwsNamespaces.EC, xml.build())).build();
@@ -550,7 +553,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
try {
String name = params.getFirst("CacheParameterGroupName");
service.modifyCacheParameterGroup(name, parseParameterNameValues(params));
- var xml = new XmlBuilder().elem("CacheParameterGroupName", name);
+ XmlBuilder xml = new XmlBuilder().elem("CacheParameterGroupName", name);
return Response.ok(AwsQueryResponse.envelope("ModifyCacheParameterGroup", AwsNamespaces.EC, xml.build())).build();
} catch (AwsException e) {
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.EC, e.getHttpStatus());
@@ -565,7 +568,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
String source = params.getFirst("Source");
boolean includeUserParameters = source == null || source.isBlank() || "user".equals(source);
- var xml = new XmlBuilder().start("Parameters");
+ XmlBuilder xml = new XmlBuilder().start("Parameters");
if (includeUserParameters) {
group.getParameters().forEach((name, value) -> xml
.start("Parameter")
@@ -632,7 +635,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
arn[6] + " is not present", 404))
.getTags();
}
- var xml = new XmlBuilder().start("TagList");
+ XmlBuilder xml = new XmlBuilder().start("TagList");
tags.forEach((key, value) -> xml.start("Tag")
.elem("Key", key)
.elem("Value", value)
@@ -731,7 +734,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
private String cacheClusterXml(CacheCluster c) {
Endpoint ep = c.getConfigurationEndpoint();
- var xml = new XmlBuilder()
+ XmlBuilder xml = new XmlBuilder()
.start("CacheCluster")
.elem("CacheClusterId", c.getCacheClusterId())
.elem("CacheClusterStatus", c.getCacheClusterStatus().name().toLowerCase())
@@ -762,7 +765,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
Endpoint ep = g.getConfigurationEndpoint();
boolean authTokenEnabled = g.getAuthMode() == AuthMode.PASSWORD;
List<ElastiCacheService.MemberCacheCluster> members = service.memberCacheClusters(g);
- var xml = new XmlBuilder()
+ XmlBuilder xml = new XmlBuilder()
.start("ReplicationGroup")
.elem("ReplicationGroupId", g.getReplicationGroupId())
.elem("Description", g.getDescription())
@@ -902,7 +905,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
private static String extractUriHost(String token) {
try {
- return java.net.URI.create("http://" + token).getHost();
+ return URI.create("http://" + token).getHost();
} catch (Exception e) {
return "";
}
@@ -910,15 +913,15 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
private static String extractQueryParam(String token, String name) {
try {
- String rawQuery = java.net.URI.create("http://" + token).getRawQuery();
+ String rawQuery = URI.create("http://" + token).getRawQuery();
if (rawQuery == null) {
return "";
}
for (String pair : rawQuery.split("&")) {
int eq = pair.indexOf('=');
if (eq >= 0 && name.equals(pair.substring(0, eq))) {
- return java.net.URLDecoder.decode(pair.substring(eq + 1),
- java.nio.charset.StandardCharsets.UTF_8);
+ return URLDecoder.decode(pair.substring(eq + 1),
+ StandardCharsets.UTF_8);
}
}
} catch (Exception ignored) {}
diff --git a/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java b/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java
index 9a0c975712..763ae168d7 100644
--- a/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheService.java
@@ -11,6 +11,8 @@ import io.github.hectorvent.floci.core.resource.SupportedResourceType;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.ec2.Ec2Service;
+import io.github.hectorvent.floci.services.ec2.model.Subnet;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerHandle;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;
import io.github.hectorvent.floci.services.elasticache.container.ValkeyClusterFormation;
@@ -18,13 +20,14 @@ import io.github.hectorvent.floci.services.elasticache.model.AuthMode;
import io.github.hectorvent.floci.services.elasticache.model.CacheParameterGroup;
import io.github.hectorvent.floci.services.elasticache.model.CacheSubnetGroup;
import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
-import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
import io.github.hectorvent.floci.services.elasticache.model.ElastiCacheUser;
+import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
+import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupStatus;
-import io.github.hectorvent.floci.services.ec2.Ec2Service;
-import io.github.hectorvent.floci.services.ec2.model.Subnet;
import io.github.hectorvent.floci.services.elasticache.proxy.ElastiCacheProxyManager;
+import io.github.hectorvent.floci.services.kms.KmsService;
+import io.github.hectorvent.floci.services.kms.model.KmsKey;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.jboss.logging.Logger;
@@ -35,13 +38,11 @@ import java.net.UnknownHostException;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
-import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
-import io.github.hectorvent.floci.services.kms.KmsService;
-import io.github.hectorvent.floci.services.kms.model.KmsKey;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
@@ -1200,7 +1201,7 @@ public class ElastiCacheService implements ResourceProvider {
}
/** The group by that name, whether stored or one of the published defaults. */
- public java.util.Optional<CacheParameterGroup> findParameterGroup(String name) {
+ public Optional<CacheParameterGroup> findParameterGroup(String name) {
return parameterGroups.get(name)
.or(() -> defaultParameterGroups().stream()
.filter(group -> group.getName().equals(name))
diff --git a/src/main/java/io/github/hectorvent/floci/services/elasticache/container/ValkeyClusterFormation.java b/src/main/java/io/github/hectorvent/floci/services/elasticache/container/ValkeyClusterFormation.java
index 3f61c5f661..8a5b96927e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/elasticache/container/ValkeyClusterFormation.java
+++ b/src/main/java/io/github/hectorvent/floci/services/elasticache/container/ValkeyClusterFormation.java
@@ -12,6 +12,7 @@ import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Predicate;
/**
* Forms a Valkey cluster out of freshly started cluster-enabled nodes, the way
@@ -158,7 +159,7 @@ public class ValkeyClusterFormation {
}
private static boolean allMatch(List<RespClient> clients,
- java.util.function.Predicate<String> infoPredicate) throws IOException {
+ Predicate<String> infoPredicate) throws IOException {
for (RespClient client : clients) {
if (!infoPredicate.test(client.callString("CLUSTER", "INFO"))) {
return false;
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/CacheParameterGroupConcurrencyTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/CacheParameterGroupConcurrencyTest.java
index 03b94e1283..084e68cf25 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/CacheParameterGroupConcurrencyTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/CacheParameterGroupConcurrencyTest.java
@@ -8,13 +8,16 @@ import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.IntStream;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -35,12 +38,12 @@ class CacheParameterGroupConcurrencyTest {
// Without a lock held across the existence check and the write, both creates see no group
// and both succeed, so a duplicate never reports one.
String name = "concurrent-create-pg";
- var pool = Executors.newFixedThreadPool(8);
- var start = new CountDownLatch(1);
- var created = new AtomicInteger();
- var rejected = new AtomicInteger();
+ ExecutorService pool = Executors.newFixedThreadPool(8);
+ CountDownLatch start = new CountDownLatch(1);
+ AtomicInteger created = new AtomicInteger();
+ AtomicInteger rejected = new AtomicInteger();
try {
- List<Future<Object>> attempts = java.util.stream.IntStream.range(0, 8)
+ List<Future<Object>> attempts = IntStream.range(0, 8)
.mapToObj(i -> pool.submit(() -> {
start.await();
try {
@@ -73,11 +76,11 @@ class CacheParameterGroupConcurrencyTest {
// The modify reads its record inside the lock, so a delete that got there first leaves it
// with nothing to write back.
String name = "modify-delete-race-pg";
- var pool = Executors.newFixedThreadPool(2);
+ ExecutorService pool = Executors.newFixedThreadPool(2);
try {
for (int attempt = 0; attempt < 40; attempt++) {
service.createCacheParameterGroup(name, "redis7", "race", Map.of());
- var start = new CountDownLatch(1);
+ CountDownLatch start = new CountDownLatch(1);
Future<?> modify = pool.submit(() -> {
start.await();
@@ -137,8 +140,8 @@ class CacheParameterGroupConcurrencyTest {
// load.
ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
CacheParameterGroup group = new CacheParameterGroup("persisted-pg", "redis7", "persisted");
- group.setParameters(new java.util.LinkedHashMap<>(Map.of("maxmemory-policy", "allkeys-lru")));
- group.setTags(new java.util.LinkedHashMap<>(Map.of("env", "prod")));
+ group.setParameters(new LinkedHashMap<>(Map.of("maxmemory-policy", "allkeys-lru")));
+ group.setTags(new LinkedHashMap<>(Map.of("env", "prod")));
Map<String, CacheParameterGroup> reloaded = mapper.readValue(
mapper.writeValueAsString(Map.of("persisted-pg", group)),
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheIntegrationTest.java
index ef7b2a24f7..ad48ebe447 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheIntegrationTest.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.elasticache;
import io.quarkus.test.junit.QuarkusTest;
+import org.jboss.logging.Logger;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
@@ -10,19 +11,18 @@ import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import java.io.IOException;
-import java.util.List;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.nio.charset.StandardCharsets;
-
-import org.jboss.logging.Logger;
+import java.util.List;
import static io.restassured.RestAssured.given;
-import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@@ -318,7 +318,7 @@ class ElastiCacheIntegrationTest {
.post("/")
.then()
.statusCode(200)
- .body("DescribeUsersResponse.DescribeUsersResult.Users.member.UserId", org.hamcrest.Matchers.not(equalTo(USER_ID)));
+ .body("DescribeUsersResponse.DescribeUsersResult.Users.member.UserId", not(equalTo(USER_ID)));
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedIntegrationTest.java
index 67d37fc470..97cdaa89d9 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedIntegrationTest.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.elasticache;
import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.path.xml.XmlPath;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeAll;
@@ -52,8 +53,7 @@ class ElastiCacheMemcachedIntegrationTest {
@Test
@Order(1)
void createCacheCluster() {
- var response =
- given()
+ XmlPath response = given()
.formParam("Action", "CreateCacheCluster")
.formParam("CacheClusterId", CLUSTER_ID)
.formParam("Engine", "memcached")
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedServiceTest.java
index e5f84923ba..3ab63226f8 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheMemcachedServiceTest.java
@@ -19,6 +19,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class ElastiCacheMemcachedServiceTest {
@@ -140,7 +142,6 @@ class ElastiCacheMemcachedServiceTest {
// Delete must not reach for a container that was never created.
service.deleteCacheCluster("no-docker-cluster");
- org.mockito.Mockito.verify(containerManager, org.mockito.Mockito.never())
- .stop(org.mockito.ArgumentMatchers.any());
+ verify(containerManager, never()).stop(any());
}
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheParameterGroupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheParameterGroupIntegrationTest.java
index 8fbe334d02..906f46e16c 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheParameterGroupIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheParameterGroupIntegrationTest.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.elasticache;
import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@@ -29,7 +30,7 @@ class ElastiCacheParameterGroupIntegrationTest {
private static final String AUTH_HEADER =
"AWS4-HMAC-SHA256 Credential=test/20260412/us-east-1/elasticache/aws4_request";
- private static io.restassured.specification.RequestSpecification query(String action) {
+ private static RequestSpecification query(String action) {
return given()
.header("Authorization", AUTH_HEADER)
.formParam("Action", action)
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandlerTest.java
index 157430beea..4a2a63ad7a 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandlerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheQueryHandlerTest.java
@@ -1,36 +1,30 @@
package io.github.hectorvent.floci.services.elasticache;
+import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.elasticache.model.AuthMode;
import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
+import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupStatus;
import io.github.hectorvent.floci.services.elasticache.proxy.SigV4Validator;
import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.BeforeEach;
-import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
-import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
-import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupStatus;
-import io.github.hectorvent.floci.services.elasticache.model.AuthMode;
-import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
-import io.github.hectorvent.floci.core.common.AwsException;
-import java.util.List;
-import java.util.Map;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.mockito.ArgumentMatchers.*;
-import static org.mockito.Mockito.*;
-import org.mockito.ArgumentCaptor;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
import java.time.Instant;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import static org.junit.jupiter.api.Assertions.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.ArgumentMatchers.*;
+import static org.mockito.Mockito.*;
/**
* Verifies the empty-list read responses for the subnet/parameter group describes, so
@@ -206,7 +200,7 @@ class ElastiCacheQueryHandlerTest {
private static ReplicationGroup group(String id) {
ReplicationGroup g = new ReplicationGroup(id, "d", ReplicationGroupStatus.AVAILABLE, AuthMode.NO_AUTH,
- new Endpoint("localhost", 6379), java.time.Instant.now(), 6379);
+ new Endpoint("localhost", 6379), Instant.now(), 6379);
g.setArn("arn:aws:elasticache:us-east-1:000000000000:replicationgroup:" + id);
return g;
}
@@ -301,7 +295,7 @@ class ElastiCacheQueryHandlerTest {
verify(service, times(7)).createReplicationGroup(captor.capture());
List<Boolean> seen = captor.getAllValues().stream()
.map(r -> r.settings().atRestEncryptionEnabled()).toList();
- assertEquals(java.util.Arrays.asList(true, true, true, true, false, false, null), seen);
+ assertEquals(Arrays.asList(true, true, true, true, false, false, null), seen);
}
@Test
@@ -378,7 +372,7 @@ class ElastiCacheQueryHandlerTest {
@Test
void listTagsForResource_readsAReplicationGroupByItsArn() {
ReplicationGroup g = group("g1");
- g.setTags(new java.util.LinkedHashMap<>(Map.of("Name", "g1")));
+ g.setTags(new LinkedHashMap<>(Map.of("Name", "g1")));
when(service.getReplicationGroup("g1")).thenReturn(g);
when(service.getReplicationGroup("absent")).thenThrow(
new AwsException("ReplicationGroupNotFoundFault", "Replication group absent not found.", 404));
@@ -398,13 +392,14 @@ class ElastiCacheQueryHandlerTest {
// not the one this ARN names
ReplicationGroup elsewhere = group("g2");
elsewhere.setArn("arn:aws:elasticache:eu-west-1:000000000000:replicationgroup:g2");
- elsewhere.setTags(new java.util.LinkedHashMap<>(Map.of("Name", "west")));
+ elsewhere.setTags(new LinkedHashMap<>(Map.of("Name", "west")));
when(service.getReplicationGroup("g2")).thenReturn(elsewhere);
p = params();
p.add("ResourceName", "arn:aws:elasticache:us-east-1:000000000000:replicationgroup:g2");
response = handler.handle("ListTagsForResource", p, "us-east-1");
- assertEquals(404, response.getStatus(), (String) response.getEntity());
- assertFalse(((String) response.getEntity()).contains("west"));
+ String entity = (String) response.getEntity();
+ assertEquals(404, response.getStatus(), entity);
+ assertFalse(entity.contains("west"));
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServiceTest.java
index 2c4c409a24..a962e20b15 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheServiceTest.java
@@ -3,35 +3,35 @@ package io.github.hectorvent.floci.services.elasticache;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageFactory;
-import io.github.hectorvent.floci.core.common.RegionResolver;
-import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
-import io.github.hectorvent.floci.core.storage.InMemoryStorage;
-import io.github.hectorvent.floci.services.kms.KmsService;
-import io.github.hectorvent.floci.services.kms.model.KmsKey;
-import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerHandle;
import io.github.hectorvent.floci.services.elasticache.container.ElastiCacheContainerManager;
import io.github.hectorvent.floci.services.elasticache.container.ValkeyClusterFormation;
import io.github.hectorvent.floci.services.elasticache.model.AuthMode;
import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
+import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupStatus;
import io.github.hectorvent.floci.services.elasticache.proxy.ElastiCacheProxyManager;
+import io.github.hectorvent.floci.services.kms.KmsService;
+import io.github.hectorvent.floci.services.kms.model.KmsKey;
+import jakarta.enterprise.inject.Instance;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
-
-import jakarta.enterprise.inject.Instance;
+import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -41,8 +41,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -73,14 +75,14 @@ class ElastiCacheServiceTest {
when(ecConfig.proxyBasePort()).thenReturn(16379);
when(ecConfig.proxyMaxPort()).thenReturn(16399);
when(ecConfig.defaultImage()).thenReturn("valkey/valkey:8");
- when(config.hostname()).thenReturn(java.util.Optional.of("localhost"));
+ when(config.hostname()).thenReturn(Optional.of("localhost"));
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
when(containerManager.tryStart(anyString(), anyString()))
.thenReturn(new ElastiCacheContainerHandle("cid", "grp", "localhost", 6379));
doNothing().when(proxyManager).startProxy(anyString(), any(), anyInt(), anyString(), anyInt(), any());
- Ec2Service ec2Service = org.mockito.Mockito.mock(Ec2Service.class);
- kmsService = org.mockito.Mockito.mock(KmsService.class);
+ Ec2Service ec2Service = mock(Ec2Service.class);
+ kmsService = mock(KmsService.class);
when(kmsService.describeKey(any(), any())).thenThrow(
new AwsException("NotFoundException", "Key not found", 404));
clusterFormation = mock(ValkeyClusterFormation.class);
@@ -106,15 +108,15 @@ class ElastiCacheServiceTest {
when(ec.proxyBasePort()).thenReturn(17000);
when(ec.proxyMaxPort()).thenReturn(17000);
when(ec.defaultImage()).thenReturn("valkey/valkey:8");
- when(cfg.hostname()).thenReturn(java.util.Optional.of("localhost"));
+ when(cfg.hostname()).thenReturn(Optional.of("localhost"));
when(sf.create(anyString(), anyString(), any())).thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
when(cm.start(anyString(), anyString()))
.thenReturn(new ElastiCacheContainerHandle("cid", "grp", "localhost", 6379));
doNothing().when(pm).startProxy(anyString(), any(), anyInt(), anyString(), anyInt(), any());
ElastiCacheService svc = new ElastiCacheService(cm, pm, mock(ValkeyClusterFormation.class),
- sf, cfg, org.mockito.Mockito.mock(Ec2Service.class),
+ sf, cfg, mock(Ec2Service.class),
new RegionResolver("us-east-1", "000000000000"),
- org.mockito.Mockito.mock(KmsService.class));
+ mock(KmsService.class));
svc.createReplicationGroup("g1", "d", AuthMode.PASSWORD, null, "us-east-1");
@@ -430,7 +432,7 @@ class ElastiCacheServiceTest {
@Test
void clusterAnnounceHostnameOverrideIsAnnouncedAndReported() {
when(config.services().elasticache().clusterAnnounceHostname())
- .thenReturn(java.util.Optional.of("localhost.floci.io"));
+ .thenReturn(Optional.of("localhost.floci.io"));
stubPerNodeContainers();
ReplicationGroup group = service.createReplicationGroup(clusterRequest("grp", 1, 0));
@@ -469,7 +471,7 @@ class ElastiCacheServiceTest {
when(ecConfig.proxyBasePort()).thenReturn(16379);
when(ecConfig.proxyMaxPort()).thenReturn(16399);
when(ecConfig.defaultImage()).thenReturn("valkey/valkey:8");
- when(config.hostname()).thenReturn(java.util.Optional.of("localhost"));
+ when(config.hostname()).thenReturn(Optional.of("localhost"));
return new ElastiCacheService(containerManager, proxyManager, clusterFormation,
storageFactory, config, mock(Ec2Service.class),
new RegionResolver("us-east-1", "000000000000"), mock(KmsService.class));
@@ -615,7 +617,7 @@ class ElastiCacheServiceTest {
key.setEnabled(true);
key.setKeyState("Enabled");
for (String form : forms) {
- org.mockito.Mockito.doReturn(key).when(kmsService).describeKey(form, "us-east-1");
+ doReturn(key).when(kmsService).describeKey(form, "us-east-1");
}
return key;
}
@@ -655,7 +657,7 @@ class ElastiCacheServiceTest {
assertEquals("InvalidParameterValue", missing.getErrorCode());
assertEquals("KMS key does not exist with key id: alias/does-not-exist", missing.getMessage());
assertThrows(AwsException.class, () -> service.getReplicationGroup("g1"));
- org.mockito.Mockito.verify(containerManager, org.mockito.Mockito.never()).start(anyString(), anyString());
+ verify(containerManager, never()).start(anyString(), anyString());
AwsException combination = assertThrows(AwsException.class, () -> service.createReplicationGroup(
"g1", "d", AuthMode.NO_AUTH, null, "us-east-1",
@@ -723,18 +725,18 @@ class ElastiCacheServiceTest {
// modify has read the group, delete removes it, modify writes its copy back — the store is
// held inside modify's put so the delete can be run in exactly that window
PausingStorageBackend<ReplicationGroup> pausing = new PausingStorageBackend<>(new InMemoryStorage<>());
- StorageFactory factory = org.mockito.Mockito.mock(StorageFactory.class);
+ StorageFactory factory = mock(StorageFactory.class);
when(factory.create(anyString(), eq("elasticache-groups.json"), any()))
.thenAnswer(inv -> new AccountAwareStorageBackend<>(pausing, null, "000000000000"));
- when(factory.create(anyString(), org.mockito.ArgumentMatchers.argThat(f -> !"elasticache-groups.json".equals(f)), any()))
+ when(factory.create(anyString(), argThat(f -> !"elasticache-groups.json".equals(f)), any()))
.thenAnswer(inv -> AccountAwareStorageBackend.inMemory("000000000000"));
ElastiCacheService svc = new ElastiCacheService(containerManager, proxyManager, clusterFormation,
- factory, config, org.mockito.Mockito.mock(Ec2Service.class),
+ factory, config, mock(Ec2Service.class),
new RegionResolver("us-east-1", "000000000000"), kmsService);
svc.createReplicationGroup("g1", "d", AuthMode.NO_AUTH, null, "us-east-1");
pausing.pauseOn(PausingStorageBackend.Call.PUT, "g1");
- java.util.concurrent.atomic.AtomicReference<Throwable> modifyOutcome = new java.util.concurrent.atomic.AtomicReference<>();
+ AtomicReference<Throwable> modifyOutcome = new AtomicReference<>();
Thread modify = new Thread(() -> {
try {
svc.modifyReplicationGroup("g1", null, null, new ReplicationGroupSettings(null, null, 3, null));
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheSubnetGroupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheSubnetGroupIntegrationTest.java
index 13649704c2..c8a13bc368 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheSubnetGroupIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/ElastiCacheSubnetGroupIntegrationTest.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.elasticache;
import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@@ -8,6 +9,8 @@ import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
+import static org.hamcrest.Matchers.matchesPattern;
+import static org.hamcrest.Matchers.not;
/**
* Cache subnet groups over the Query protocol.
@@ -30,14 +33,14 @@ class ElastiCacheSubnetGroupIntegrationTest {
private static String secondSubnet;
private static String vpcId;
- private static io.restassured.specification.RequestSpecification elasticache(String action) {
+ private static RequestSpecification elasticache(String action) {
return given().header("Authorization", EC_AUTH)
.formParam("Action", action)
.formParam("Version", "2015-02-02");
}
private static String ec2(String region, String action, String... formParams) {
- var request = given().header("Authorization", EC2_AUTH.formatted(region))
+ RequestSpecification request = given().header("Authorization", EC2_AUTH.formatted(region))
.formParam("Action", action)
.formParam("Version", "2016-11-15");
for (int i = 0; i < formParams.length; i += 2) {
@@ -80,7 +83,7 @@ class ElastiCacheSubnetGroupIntegrationTest {
.body(containsString(":subnetgroup:" + GROUP + "</ARN>"))
// In the order they were given: the subnets are read back from a store whose scan
// order is its own, so the group would otherwise report them in an arbitrary order.
- .body(org.hamcrest.Matchers.matchesPattern(
+ .body(matchesPattern(
"(?s).*<SubnetIdentifier>" + firstSubnet + "</SubnetIdentifier>.*"
+ "<SubnetIdentifier>" + secondSubnet + "</SubnetIdentifier>.*"));
}
@@ -157,7 +160,7 @@ class ElastiCacheSubnetGroupIntegrationTest {
.when().post("/")
.then()
.statusCode(200)
- .body(org.hamcrest.Matchers.not(containsString(secondSubnet)));
+ .body(not(containsString(secondSubnet)));
}
@Test
diff --git a/src/test/java/io/github/hectorvent/floci/services/elasticache/PausingStorageBackend.java b/src/test/java/io/github/hectorvent/floci/services/elasticache/PausingStorageBackend.java
index 40e6fd7b86..f6bbe54a7d 100644
--- a/src/test/java/io/github/hectorvent/floci/services/elasticache/PausingStorageBackend.java
+++ b/src/test/java/io/github/hectorvent/floci/services/elasticache/PausingStorageBackend.java
@@ -7,6 +7,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
/**
@@ -26,8 +27,7 @@ final class PausingStorageBackend<V> implements StorageBackend<String, V> {
private final StorageBackend<String, V> delegate;
private volatile Call pauseOn;
private volatile String pauseKey;
- private final java.util.concurrent.atomic.AtomicInteger skip =
- new java.util.concurrent.atomic.AtomicInteger();
+ private final AtomicInteger skip = new AtomicInteger();
private final CountDownLatch reached = new CountDownLatch(1);
private final CountDownLatch release = new CountDownLatch(1);