mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(redshift): keep two creates of one parameter or subnet group name from both succeeding (#8605)
* fix(redshift): keep two creates of one parameter or subnet group name from both succeeding * fix(redshift): refuse a taken subnet group name before asking EC2 about its subnets
This commit is contained in:
1 parent
faf2287433
commit
43363c0f8d
2 files changed
+76
-12
No files matched your search
@@ -40,6 +40,7 @@ import io.floci.aws.services.redshiftserverless.model.Namespace;
|
||||
import io.floci.aws.services.s3.S3Service;
|
||||
import io.floci.aws.services.secretsmanager.SecretsManagerService;
|
||||
import io.floci.aws.services.secretsmanager.model.Secret;
|
||||
import io.floci.aws.testing.ParkingStore;
|
||||
import jakarta.ws.rs.core.MultivaluedHashMap;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -75,6 +76,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static io.floci.aws.testing.InlineMocks.inlineMock;
|
||||
import static io.floci.aws.testing.ParkingStoreAssertions.assertOperationWaitsForParkedStore;
|
||||
import static io.floci.aws.testing.ThreadStates.awaitBlockedOrDone;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -4180,6 +4182,52 @@ class RedshiftServiceTest {
|
||||
service.createClusterSubnetGroup("existing", "d", "vpc-1", List.of("subnet-1")));
|
||||
}
|
||||
|
||||
/** Two creates of one subnet group name at once: the second waits for the first, then finds the name taken. */
|
||||
@Test
|
||||
void twoCreatesOfOneSubnetGroupNameCanNotBothSucceed() throws Exception {
|
||||
ParkingStore<ClusterSubnetGroup> groups = backedByParkingStore(subnetGroupBackend);
|
||||
|
||||
assertOnlyTheFirstCreateSucceeds(groups,
|
||||
() -> service.createClusterSubnetGroup("racy", "d", "vpc-1", List.of("subnet-1")),
|
||||
"ClusterSubnetGroupAlreadyExists");
|
||||
|
||||
assertEquals(Set.of(regionalKey("racy")), groups.keys());
|
||||
}
|
||||
|
||||
/** As above, for a cluster parameter group. */
|
||||
@Test
|
||||
void twoCreatesOfOneParameterGroupNameCanNotBothSucceed() throws Exception {
|
||||
ParkingStore<ClusterParameterGroup> groups = backedByParkingStore(parameterGroupBackend);
|
||||
|
||||
assertOnlyTheFirstCreateSucceeds(groups,
|
||||
() -> service.createClusterParameterGroup("racy", "redshift-1.0", "d"),
|
||||
"ClusterParameterGroupAlreadyExists");
|
||||
|
||||
assertEquals(Set.of(regionalKey("racy")), groups.keys());
|
||||
}
|
||||
|
||||
/** {@code backend}'s reads and writes, served by a store a test can hold inside its next write. */
|
||||
private static <V> ParkingStore<V> backedByParkingStore(AccountAwareStorageBackend<V> backend) {
|
||||
ParkingStore<V> store = new ParkingStore<>();
|
||||
when(backend.get(anyString())).thenAnswer(call -> store.get(call.getArgument(0)));
|
||||
doAnswer(call -> {
|
||||
store.put(call.getArgument(0), call.getArgument(1));
|
||||
return null;
|
||||
}).when(backend).put(anyString(), any());
|
||||
return store;
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds the first {@code create} inside its write, after its check that the name is free, and runs a second one:
|
||||
* the second must wait for the first, then answer {@code alreadyExists}.
|
||||
*/
|
||||
private static void assertOnlyTheFirstCreateSucceeds(ParkingStore<?> store, Runnable create, String alreadyExists)
|
||||
throws Exception {
|
||||
store.parkNextWrite();
|
||||
assertOperationWaitsForParkedStore(store, create,
|
||||
() -> assertEquals(alreadyExists, assertThrows(AwsException.class, create::run).getErrorCode()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeClusterSubnetGroups() {
|
||||
ClusterSubnetGroup group = new ClusterSubnetGroup("my-group", "d", "vpc-1", List.of("subnet-1"));
|
||||
|
||||
Reference in new issue
Block a user