mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(redshift-serverless): add release track, managed workgroup and reservation reads (#5691)
* feat(redshift-serverless): add release track, managed workgroup and reservation reads Add GetTrack, ListTracks, ListManagedWorkgroups, ListReservations, ListReservationOfferings, GetReservation, GetReservationOffering and CreateReservation so SDK, CLI and IaC clients no longer get an unknown operation error. Floci models no zero-ETL managed workgroups and sells no reservations, so the lists are empty and the reservation lookups answer ResourceNotFoundException. The two release tracks are current and trailing. Required members, patterns and lengths come from the AWS model through RedshiftServerlessRequestShapes; only the track names, which the model leaves unenumerated, are checked by hand. * refactor(redshift-serverless): reuse Pagination.paginate and remove unused admin handle method Rely on Pagination.paginate for maxResults and nextToken validation in listTracks and listWithoutItems, matching the other Redshift Serverless lists. Remove the unused handle method and its duplicate unknown-operation response in RedshiftServerlessAdminJsonHandler.
This commit is contained in:
1 parent
2ec88794b5
commit
d3fce14256
11 files changed
+319
-9
No files matched your search
+120
@@ -0,0 +1,120 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.redshift.RedshiftIamDbUserResolver;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Covers the metadata-only Redshift Serverless actions through the handler, so both the stored
|
||||
* behavior and the response shape the SDKs deserialize are checked.
|
||||
*/
|
||||
class RedshiftServerlessAdministrationHandlerTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private RedshiftServerlessJsonHandler handler;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
handler = new RedshiftServerlessJsonHandler(mock(RedshiftServerlessService.class), mapper,
|
||||
mock(RedshiftIamDbUserResolver.class), mock(RedshiftServerlessUsageLimitService.class),
|
||||
new RedshiftServerlessAdminJsonHandler(mapper));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tracksAreTheTwoAwsReleaseTracks() {
|
||||
JsonNode track = ok("GetTrack", "{\"trackName\":\"trailing\"}").get("track");
|
||||
assertEquals("trailing", track.get("trackName").textValue());
|
||||
assertEquals(0, track.get("updateTargets").size());
|
||||
assertEquals("ResourceNotFoundException", errorType("GetTrack", "{\"trackName\":\"nightly\"}"));
|
||||
assertEquals("ResourceNotFoundException", errorType("GetTrack", "{\"trackName\":\"preview\"}"));
|
||||
assertEquals("ValidationException", errorType("GetTrack", "{\"trackName\":\"not valid!\"}"));
|
||||
assertEquals("ValidationException", errorType("GetTrack", "{}"));
|
||||
|
||||
assertEquals(2, ok("ListTracks", "{}").get("tracks").size());
|
||||
JsonNode page = ok("ListTracks", "{\"maxResults\":1}");
|
||||
assertEquals("current", page.get("tracks").get(0).get("trackName").textValue());
|
||||
String next = page.get("nextToken").textValue();
|
||||
JsonNode rest = ok("ListTracks", "{\"nextToken\":\"" + next + "\"}");
|
||||
assertEquals(1, rest.get("tracks").size());
|
||||
assertEquals("trailing", rest.get("tracks").get(0).get("trackName").textValue());
|
||||
assertFalse(rest.has("nextToken"));
|
||||
assertEquals("ValidationException", errorType("ListTracks", "{\"maxResults\":\"x\"}"));
|
||||
assertEquals("ValidationException", errorType("ListTracks", "{\"maxResults\":0}"));
|
||||
assertEquals("ValidationException", errorType("ListTracks", "{\"maxResults\":101}"));
|
||||
assertEquals("ValidationException", errorType("ListTracks", "{\"nextToken\":\"bad-token\"}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void managedWorkgroupsAndReservationsAreEmptyBecauseFlociModelsNone() {
|
||||
assertEquals(0, ok("ListManagedWorkgroups", "{}").get("managedWorkgroups").size());
|
||||
assertEquals("ValidationException", errorType("ListManagedWorkgroups", "{\"sourceArn\":\"nope\"}"));
|
||||
assertEquals(0, ok("ListManagedWorkgroups", "{\"sourceArn\":\"arn:aws:glue:us-east-1:123456789012:"
|
||||
+ "database/db\"}").get("managedWorkgroups").size());
|
||||
assertEquals("ValidationException", errorType("ListManagedWorkgroups", "{\"maxResults\":0}"));
|
||||
assertEquals("ValidationException", errorType("ListManagedWorkgroups", "{\"maxResults\":101}"));
|
||||
|
||||
assertEquals(0, ok("ListReservations", "{}").get("reservationsList").size());
|
||||
assertEquals("ValidationException", errorType("ListReservations", "{\"maxResults\":0}"));
|
||||
assertEquals("ValidationException", errorType("ListReservations", "{\"maxResults\":101}"));
|
||||
|
||||
assertEquals(0, ok("ListReservationOfferings", "{}").get("reservationOfferingsList").size());
|
||||
assertEquals("ValidationException", errorType("ListReservationOfferings", "{\"maxResults\":0}"));
|
||||
assertEquals("ValidationException", errorType("ListReservationOfferings", "{\"maxResults\":101}"));
|
||||
|
||||
assertEquals("ValidationException",
|
||||
errorType("ListManagedWorkgroups", "{\"nextToken\":\"bad-token\"}"));
|
||||
assertEquals("ValidationException",
|
||||
errorType("ListReservations", "{\"nextToken\":\"bad-token\"}"));
|
||||
assertEquals("ValidationException",
|
||||
errorType("ListReservationOfferings", "{\"nextToken\":\"bad-token\"}"));
|
||||
|
||||
assertEquals("ResourceNotFoundException", errorType("GetReservation", "{\"reservationId\":\"r-1\"}"));
|
||||
assertEquals("ValidationException", errorType("GetReservation", "{}"));
|
||||
assertEquals("ValidationException", errorType("GetReservation", "{\"reservationId\":\"\"}"));
|
||||
assertEquals("ResourceNotFoundException", errorType("GetReservationOffering", "{\"offeringId\":\"o-1\"}"));
|
||||
assertEquals("ValidationException", errorType("GetReservationOffering", "{}"));
|
||||
assertEquals("ValidationException", errorType("GetReservationOffering", "{\"offeringId\":\"\"}"));
|
||||
assertEquals("ResourceNotFoundException",
|
||||
errorType("CreateReservation", "{\"capacity\":128,\"offeringId\":\"o-1\"}"));
|
||||
assertEquals("ValidationException", errorType("CreateReservation", "{\"offeringId\":\"o-1\"}"));
|
||||
assertEquals("ValidationException",
|
||||
errorType("CreateReservation", "{\"capacity\":\"nope\",\"offeringId\":\"o-1\"}"));
|
||||
assertEquals("ValidationException",
|
||||
errorType("CreateReservation", "{\"capacity\":128,\"offeringId\":\"o-1\",\"clientToken\":123}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnknownActionIsStillRejected() {
|
||||
assertEquals("UnknownOperationException", errorType("NoSuchOperation", "{}"));
|
||||
}
|
||||
|
||||
private JsonNode ok(String action, String json) {
|
||||
Response response = invoke(action, json);
|
||||
assertEquals(200, response.getStatus(), action + " failed: " + response.getEntity());
|
||||
return mapper.valueToTree(response.getEntity());
|
||||
}
|
||||
|
||||
private String errorType(String action, String json) {
|
||||
Response response = invoke(action, json);
|
||||
assertEquals(400, response.getStatus(), action + " should be rejected: " + response.getEntity());
|
||||
return mapper.valueToTree(response.getEntity()).path("__type").asText(null);
|
||||
}
|
||||
|
||||
private Response invoke(String action, String json) {
|
||||
try {
|
||||
return handler.handle(action, mapper.readTree(json), REGION);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+27
@@ -10,6 +10,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -481,6 +482,32 @@ class RedshiftServerlessIntegrationTest {
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void releaseTracksAndEmptyListsRoundTripOverTheWire() {
|
||||
call("ListTracks", "{}")
|
||||
.statusCode(200)
|
||||
.body("tracks.trackName", equalTo(List.of("current", "trailing")));
|
||||
call("GetTrack", "{\"trackName\":\"trailing\"}")
|
||||
.statusCode(200)
|
||||
.body("track.trackName", equalTo("trailing"));
|
||||
call("GetTrack", "{\"trackName\":\"preview\"}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
call("GetTrack", "{}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
|
||||
call("ListManagedWorkgroups", "{}").statusCode(200).body("managedWorkgroups", hasSize(0));
|
||||
call("ListReservations", "{}").statusCode(200).body("reservationsList", hasSize(0));
|
||||
call("ListReservationOfferings", "{}").statusCode(200).body("reservationOfferingsList", hasSize(0));
|
||||
call("GetReservation", "{\"reservationId\":\"r-1\"}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ResourceNotFoundException"));
|
||||
call("CreateReservation", "{\"offeringId\":\"o-1\"}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse call(String action, String body) {
|
||||
return given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + action)
|
||||
|
||||
+2
-1
@@ -86,7 +86,8 @@ class RedshiftServerlessJsonHandlerTest {
|
||||
RedshiftServerlessService service =
|
||||
new RedshiftServerlessService(storageFactory, regionResolver, endpoints, runtime, config);
|
||||
handler = new RedshiftServerlessJsonHandler(service, mapper, iamDbUserResolver,
|
||||
new RedshiftServerlessUsageLimitService(storageFactory, regionResolver, service));
|
||||
new RedshiftServerlessUsageLimitService(storageFactory, regionResolver, service),
|
||||
new RedshiftServerlessAdminJsonHandler(mapper));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+17
@@ -1069,6 +1069,23 @@ class RedshiftServerlessServiceTest {
|
||||
assertThrows(AwsException.class, () -> service.updateSnapshot(null, 5, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void creatingWorkgroupWithUnknownTrackNameIsRejected() {
|
||||
create("tr-ns");
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.createWorkgroup("tr-wg", "tr-ns", settings(null, null, null, "nightly"), null, REGION));
|
||||
assertEquals("ValidationException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingWorkgroupWithUnknownTrackNameIsRejected() {
|
||||
create("upd-tr-ns");
|
||||
createWorkgroup("upd-tr-wg", "upd-tr-ns");
|
||||
AwsException ex = assertThrows(AwsException.class, () ->
|
||||
service.updateWorkgroup("upd-tr-wg", settings(null, null, null, "preview"), REGION));
|
||||
assertEquals("ValidationException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
private Namespace create(String namespaceName) {
|
||||
return service.createNamespace(namespaceName, "admin", null, null, null, null, null, Map.of(), REGION);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user