Light, fluffy, and always free - The AWS Local Emulator alternative
fix(neptune): throw a mappable capacity fault when the proxy-port range is exhausted (#1879)
Ahmed khaledfe531e2be884
diff --git a/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneService.java b/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneService.javaindex dc0f70d342..765f0823c4 100644--- a/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneService.java+++ b/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneService.java@@ -308,8 +308,11 @@ public class NeptuneService {return port;}}- throw new AwsException("InsufficientNeptuneCapacity",- "No available proxy ports in range " + base + "-" + max, 503);+ // Wire code the SDK maps to InsufficientStorageClusterCapacityFault (the only+ // capacity fault CreateDBCluster declares); "InsufficientNeptuneCapacity" isn't a+ // real Neptune code, so callers got an unmapped generic NeptuneException.+ throw new AwsException("InsufficientStorageClusterCapacity",+ "No available proxy ports in range " + base + "-" + max, 400);}private void releaseProxyPort(int port) {diff --git a/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneServiceTest.javaindex b0173c663b..4dc0b2ac3a 100644--- a/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneServiceTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/neptune/NeptuneServiceTest.java@@ -1,6 +1,7 @@package io.github.hectorvent.floci.services.neptune;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.storage.InMemoryStorage;import io.github.hectorvent.floci.core.storage.StorageFactory;@@ -32,6 +33,7 @@ class NeptuneServiceTest {private NeptuneService service;private NeptuneContainerManager containerManager;private NeptuneProxyManager proxyManager;+ private EmulatorConfig.NeptuneServiceConfig neptuneConfig;@BeforeEachvoid setUp() {@@ -42,7 +44,7 @@ class NeptuneServiceTest {RegionResolver regionResolver = mock(RegionResolver.class);EmulatorConfig.ServicesConfig servicesConfig = mock(EmulatorConfig.ServicesConfig.class);- EmulatorConfig.NeptuneServiceConfig neptuneConfig = mock(EmulatorConfig.NeptuneServiceConfig.class);+ neptuneConfig = mock(EmulatorConfig.NeptuneServiceConfig.class);when(config.services()).thenReturn(servicesConfig);when(servicesConfig.neptune()).thenReturn(neptuneConfig);when(neptuneConfig.proxyBasePort()).thenReturn(18182);@@ -140,4 +142,18 @@ class NeptuneServiceTest {assertEquals(18182, recovered.getProxyPort(),"Port from the failed create must be released so the next cluster reuses it");}++ @Test+ void exhaustedProxyPortRangeThrowsMappableCapacityFault() {+ // Shrink the range to one port so the second create exhausts it.+ when(neptuneConfig.proxyMaxPort()).thenReturn(18182);+ service.createDbCluster("c1", "1.3.2.1", false);++ AwsException e = assertThrows(AwsException.class,+ () -> service.createDbCluster("c2", "1.3.2.1", false));+ // Real Neptune wire code (maps to InsufficientStorageClusterCapacityFault), not the+ // fabricated "InsufficientNeptuneCapacity" the SDK couldn't map to a typed exception.+ assertEquals("InsufficientStorageClusterCapacity", e.getErrorCode());+ assertEquals(400, e.getHttpStatus());+ }}