mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elasticache): return reachable Memcached configuration endpoints (#1258)
This commit is contained in:
1 parent
2aebe174d5
commit
94ad081241
3 files changed
+40
-6
No files matched your search
+10
-5
@@ -30,6 +30,7 @@ class ElastiCacheMemcachedIntegrationTest {
|
||||
private static final String CLUSTER_ID = "it-memcached-cluster";
|
||||
private static final int SOCKET_TIMEOUT_MS = 10_000;
|
||||
|
||||
private static String clusterHost;
|
||||
private static int clusterPort;
|
||||
|
||||
@BeforeAll
|
||||
@@ -51,7 +52,7 @@ class ElastiCacheMemcachedIntegrationTest {
|
||||
@Test
|
||||
@Order(1)
|
||||
void createCacheCluster() {
|
||||
clusterPort =
|
||||
var response =
|
||||
given()
|
||||
.formParam("Action", "CreateCacheCluster")
|
||||
.formParam("CacheClusterId", CLUSTER_ID)
|
||||
@@ -68,8 +69,12 @@ class ElastiCacheMemcachedIntegrationTest {
|
||||
.body("CreateCacheClusterResponse.CreateCacheClusterResult.CacheCluster.ConfigurationEndpoint.Address", notNullValue())
|
||||
.body("CreateCacheClusterResponse.CreateCacheClusterResult.CacheCluster.ConfigurationEndpoint.Port", notNullValue())
|
||||
.extract()
|
||||
.xmlPath()
|
||||
.getInt("CreateCacheClusterResponse.CreateCacheClusterResult.CacheCluster.ConfigurationEndpoint.Port");
|
||||
.xmlPath();
|
||||
|
||||
clusterHost = response.getString(
|
||||
"CreateCacheClusterResponse.CreateCacheClusterResult.CacheCluster.ConfigurationEndpoint.Address");
|
||||
clusterPort = response.getInt(
|
||||
"CreateCacheClusterResponse.CreateCacheClusterResult.CacheCluster.ConfigurationEndpoint.Port");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +111,7 @@ class ElastiCacheMemcachedIntegrationTest {
|
||||
@Test
|
||||
@Order(4)
|
||||
void memcachedAcceptsSetAndGet() throws Exception {
|
||||
try (Socket socket = new Socket("localhost", clusterPort)) {
|
||||
try (Socket socket = new Socket(clusterHost, clusterPort)) {
|
||||
socket.setSoTimeout(SOCKET_TIMEOUT_MS);
|
||||
OutputStream out = socket.getOutputStream();
|
||||
InputStream in = socket.getInputStream();
|
||||
@@ -128,7 +133,7 @@ class ElastiCacheMemcachedIntegrationTest {
|
||||
@Test
|
||||
@Order(5)
|
||||
void versionCommandResponds() throws Exception {
|
||||
try (Socket socket = new Socket("localhost", clusterPort)) {
|
||||
try (Socket socket = new Socket(clusterHost, clusterPort)) {
|
||||
socket.setSoTimeout(SOCKET_TIMEOUT_MS);
|
||||
socket.getOutputStream().write("version\r\n".getBytes(StandardCharsets.UTF_8));
|
||||
socket.getOutputStream().flush();
|
||||
|
||||
+25
@@ -96,4 +96,29 @@ class ElastiCacheMemcachedServiceTest {
|
||||
AwsException ex = assertThrows(AwsException.class, () -> service.getCacheCluster("my-cluster"));
|
||||
assertEquals("CacheClusterNotFound", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createClusterUsesContainerHostWhenHostnameNotConfigured() {
|
||||
ElastiCacheMemcachedContainerManager containerManager = mock(ElastiCacheMemcachedContainerManager.class);
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
|
||||
EmulatorConfig.ServicesConfig servicesConfig = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.ElastiCacheServiceConfig ecConfig = mock(EmulatorConfig.ElastiCacheServiceConfig.class);
|
||||
when(config.services()).thenReturn(servicesConfig);
|
||||
when(servicesConfig.elasticache()).thenReturn(ecConfig);
|
||||
when(ecConfig.defaultMemcachedImage()).thenReturn("memcached:1.6");
|
||||
when(config.hostname()).thenReturn(Optional.empty());
|
||||
|
||||
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(inv -> new InMemoryStorage<>());
|
||||
when(containerManager.start(anyString(), anyString()))
|
||||
.thenReturn(new ElastiCacheContainerHandle("cid", "cluster", "172.20.0.10", 11211));
|
||||
|
||||
ElastiCacheMemcachedService containerModeService =
|
||||
new ElastiCacheMemcachedService(containerManager, storageFactory, config);
|
||||
|
||||
CacheCluster cluster = containerModeService.createCacheCluster("container-cluster");
|
||||
|
||||
assertEquals("172.20.0.10", cluster.getConfigurationEndpoint().address());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user