mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix: DynamoDB table creation compatibility with Terraform AWS provider v6 (#89)
Hey @kurtmc, you're amazing! Thank you so much --- The Terraform AWS provider v6 calls waitTableWarmThroughputActive after creating a DynamoDB table, which checks DescribeTable for WarmThroughput.Status == "ACTIVE". Without this field the waiter retried for ~2.5 minutes then failed with "couldn't find resource (21 retries)". - Add WarmThroughput with Status ACTIVE to DescribeTable/CreateTable responses - Add BillingModeSummary for PAY_PER_REQUEST tables - Parse BillingMode and Tags from CreateTable/UpdateTable requests - Add DeletionProtectionEnabled field to table responses - Extend CBOR protocol handlers to support DynamoDB, SQS, SNS, StepFunctions
This commit is contained in:
1 parent
f82b370ab2
commit
7b87bf2c1f
4 files changed
+304
-37
No files matched your search
+176
@@ -0,0 +1,176 @@
|
||||
package io.github.hectorvent.floci.services.dynamodb;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import org.junit.jupiter.api.MethodOrderer;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Tests the smithy-rpc-v2-cbor protocol for DynamoDB.
|
||||
* AWS SDK v2 sends DynamoDB requests as CBOR to /service/DynamoDB/operation/{op}.
|
||||
*/
|
||||
@QuarkusTest
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
class DynamoDbCborIntegrationTest {
|
||||
|
||||
private static final ObjectMapper CBOR_MAPPER = new ObjectMapper(new CBORFactory());
|
||||
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
void createTableViaCbor() throws Exception {
|
||||
JsonNode request = JSON_MAPPER.readTree("""
|
||||
{
|
||||
"TableName": "CborTable",
|
||||
"KeySchema": [
|
||||
{"AttributeName": "pk", "KeyType": "HASH"}
|
||||
],
|
||||
"AttributeDefinitions": [
|
||||
{"AttributeName": "pk", "AttributeType": "S"}
|
||||
],
|
||||
"ProvisionedThroughput": {
|
||||
"ReadCapacityUnits": 5,
|
||||
"WriteCapacityUnits": 5
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
byte[] cborBody = CBOR_MAPPER.writeValueAsBytes(request);
|
||||
|
||||
byte[] responseBytes = given()
|
||||
.contentType("application/cbor")
|
||||
.accept("application/cbor")
|
||||
.body(cborBody)
|
||||
.when()
|
||||
.post("/service/DynamoDB/operation/CreateTable")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/cbor")
|
||||
.extract().asByteArray();
|
||||
|
||||
JsonNode response = CBOR_MAPPER.readTree(responseBytes);
|
||||
assertThat(response.path("TableDescription").path("TableName").asText(), equalTo("CborTable"));
|
||||
assertThat(response.path("TableDescription").path("TableStatus").asText(), equalTo("ACTIVE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
void describeTableViaCbor() throws Exception {
|
||||
JsonNode request = JSON_MAPPER.readTree("""
|
||||
{"TableName": "CborTable"}
|
||||
""");
|
||||
|
||||
byte[] cborBody = CBOR_MAPPER.writeValueAsBytes(request);
|
||||
|
||||
byte[] responseBytes = given()
|
||||
.contentType("application/cbor")
|
||||
.accept("application/cbor")
|
||||
.body(cborBody)
|
||||
.when()
|
||||
.post("/service/DynamoDB/operation/DescribeTable")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType("application/cbor")
|
||||
.extract().asByteArray();
|
||||
|
||||
JsonNode response = CBOR_MAPPER.readTree(responseBytes);
|
||||
assertThat(response.path("Table").path("TableName").asText(), equalTo("CborTable"));
|
||||
assertThat(response.path("Table").path("TableStatus").asText(), equalTo("ACTIVE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
void describeNonExistentTableViaCbor() throws Exception {
|
||||
JsonNode request = JSON_MAPPER.readTree("""
|
||||
{"TableName": "NoSuchTable"}
|
||||
""");
|
||||
|
||||
byte[] cborBody = CBOR_MAPPER.writeValueAsBytes(request);
|
||||
|
||||
byte[] responseBytes = given()
|
||||
.contentType("application/cbor")
|
||||
.accept("application/cbor")
|
||||
.body(cborBody)
|
||||
.when()
|
||||
.post("/service/DynamoDB/operation/DescribeTable")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.extract().asByteArray();
|
||||
|
||||
JsonNode response = CBOR_MAPPER.readTree(responseBytes);
|
||||
assertThat(response.path("__type").asText(), equalTo("ResourceNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(4)
|
||||
void putAndGetItemViaCbor() throws Exception {
|
||||
JsonNode putRequest = JSON_MAPPER.readTree("""
|
||||
{
|
||||
"TableName": "CborTable",
|
||||
"Item": {
|
||||
"pk": {"S": "cbor-1"},
|
||||
"data": {"S": "hello cbor"}
|
||||
}
|
||||
}
|
||||
""");
|
||||
|
||||
given()
|
||||
.contentType("application/cbor")
|
||||
.accept("application/cbor")
|
||||
.body(CBOR_MAPPER.writeValueAsBytes(putRequest))
|
||||
.when()
|
||||
.post("/service/DynamoDB/operation/PutItem")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
JsonNode getRequest = JSON_MAPPER.readTree("""
|
||||
{
|
||||
"TableName": "CborTable",
|
||||
"Key": {"pk": {"S": "cbor-1"}}
|
||||
}
|
||||
""");
|
||||
|
||||
byte[] responseBytes = given()
|
||||
.contentType("application/cbor")
|
||||
.accept("application/cbor")
|
||||
.body(CBOR_MAPPER.writeValueAsBytes(getRequest))
|
||||
.when()
|
||||
.post("/service/DynamoDB/operation/GetItem")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().asByteArray();
|
||||
|
||||
JsonNode response = CBOR_MAPPER.readTree(responseBytes);
|
||||
assertThat(response.path("Item").path("data").path("S").asText(), equalTo("hello cbor"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(5)
|
||||
void deleteTableViaCbor() throws Exception {
|
||||
JsonNode request = JSON_MAPPER.readTree("""
|
||||
{"TableName": "CborTable"}
|
||||
""");
|
||||
|
||||
byte[] responseBytes = given()
|
||||
.contentType("application/cbor")
|
||||
.accept("application/cbor")
|
||||
.body(CBOR_MAPPER.writeValueAsBytes(request))
|
||||
.when()
|
||||
.post("/service/DynamoDB/operation/DeleteTable")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().asByteArray();
|
||||
|
||||
JsonNode response = CBOR_MAPPER.readTree(responseBytes);
|
||||
assertThat(response.path("TableDescription").path("TableStatus").asText(), equalTo("DELETING"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user