Light, fluffy, and always free - The AWS Local Emulator alternative
fix(elasticache): return the modeled capacity fault on proxy-port exhaustion (#2423)
Hector Venturaf40d2e34f3e6
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.javaindex 049a6cab44..fa9c9631aa 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@@ -326,8 +326,14 @@ public class ElastiCacheService {return port;}}- throw new AwsException("InsufficientReplicationGroupCapacity",- "No available proxy ports in range " + base + "-" + max, 503);+ // Proxy-port exhaustion is a Floci-side limit, but on the wire it must look like the+ // modeled capacity fault. botocore/smithy declare InsufficientCacheClusterCapacityFault+ // for CreateReplicationGroup: awsQueryError code InsufficientCacheClusterCapacity,+ // HTTP 400, Sender fault. The old InsufficientReplicationGroupCapacity/503 is invented —+ // no such shape exists, so SDK clients cannot map it. Keep the real cause in the log.+ LOG.warnv("ElastiCache proxy port range {0}-{1} exhausted; returning InsufficientCacheClusterCapacity", base, max);+ throw new AwsException("InsufficientCacheClusterCapacity",+ "The requested cache node type is not available in the specified Availability Zone.", 400);}private void releaseProxyPort(int port) {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.javaindex d1ac73b0d2..f7c45781c1 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@@ -65,6 +65,40 @@ class ElastiCacheServiceTest {ec2Service, new RegionResolver("us-east-1", "000000000000"));}+ @Test+ void proxyPortExhaustionSurfacesModeledCapacityFault() {+ // A one-port range: the first replication group claims it, so the second must fail with+ // the botocore/smithy-modeled fault for CreateReplicationGroup — wire code+ // InsufficientCacheClusterCapacity at HTTP 400 (Sender) — not the invented+ // InsufficientReplicationGroupCapacity/503 that no SDK can map.+ ElastiCacheContainerManager cm = mock(ElastiCacheContainerManager.class);+ ElastiCacheProxyManager pm = mock(ElastiCacheProxyManager.class);+ StorageFactory sf = mock(StorageFactory.class);+ EmulatorConfig cfg = mock(EmulatorConfig.class);+ EmulatorConfig.ServicesConfig sc = mock(EmulatorConfig.ServicesConfig.class);+ EmulatorConfig.ElastiCacheServiceConfig ec = mock(EmulatorConfig.ElastiCacheServiceConfig.class);+ when(cfg.services()).thenReturn(sc);+ when(sc.elasticache()).thenReturn(ec);+ 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(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, sf, cfg,+ org.mockito.Mockito.mock(Ec2Service.class),+ new RegionResolver("us-east-1", "000000000000"));++ svc.createReplicationGroup("g1", "d", AuthMode.PASSWORD, null);++ AwsException ex = assertThrows(AwsException.class,+ () -> svc.createReplicationGroup("g2", "d", AuthMode.PASSWORD, null));+ assertEquals("InsufficientCacheClusterCapacity", ex.getErrorCode());+ assertEquals(400, ex.getHttpStatus());+ }+@Testvoid singleArgAuthMatchesDefaultUserOnly() {service.createReplicationGroup("grp", "test", AuthMode.PASSWORD, null);