feat(dynamodb): add the legacy global table operations (#4288)

* feat(dynamodb): add the 2017.11.29 global table operations

CreateGlobalTable, DescribeGlobalTable, UpdateGlobalTable and ListGlobalTables
were all UnknownOperationException, so a legacy global table could not be
created at all. The 2019.11.21 path through UpdateTable ReplicaUpdates already
worked, and these four now run on the same replica metadata.

Constraints come from the model. CreateGlobalTable builds on a table that
already exists, so an absent one is TableNotFoundException rather than the
item operations' ResourceNotFoundException, and a second create is
GlobalTableAlreadyExistsException. The one replica precondition a
single-process emulator can test is the stream, so a table joins only with
DynamoDB Streams enabled and a view type of NEW_AND_OLD_IMAGES.

DynamoDbIntegrationTest used CreateGlobalTable as its example of an
unsupported operation. It now uses DescribeGlobalTableSettings, which is still
unimplemented.

* fix(dynamodb): use the model's fault shapes on the global table surface

Two gaps on the new operations.

requireStreamWithBothImages raised InvalidParameterValue, which is not a
DynamoDB shape at all. Every other rejection in this file raises
ValidationException, seventy-six of them, so a client catching that one missed
this rejection alone. The test asserted only the status, never the code, which
is why nothing caught it.

UpdateGlobalTable delegated straight to applyReplicaUpdates, and that helper is
deliberately idempotent for UpdateTable and CloudFormation re-applies: a
duplicate add is skipped and an absent removal is a no-op. The model declares
ReplicaAlreadyExistsException and ReplicaNotFoundException for
UpdateGlobalTable and declares neither for UpdateTable, so sharing the path
dropped both. The membership check now lives in updateGlobalTable and the
helper keeps its idempotence.

Tests assert the codes rather than the status, cover both replica faults
including a re-add of the home region, and pin that UpdateTable still accepts
the same re-add.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-24 08:22:20 -04:00
1 parent 7cf8ab7d85
commit 72231c09cf
5 files changed
+380 -1

No files matched your search

@@ -0,0 +1,169 @@
package io.github.hectorvent.floci.services.dynamodb;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.parsing.Parser;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
/** CreateGlobalTable and its Describe, Update and List siblings, the 2017.11.29 API. */
@QuarkusTest
class DynamoDbGlobalTableIntegrationTest {
@BeforeAll
static void readTheJson10ResponsesAsJson() {
RestAssured.registerParser("application/x-amz-json-1.0", Parser.JSON);
}
private static io.restassured.response.Response call(String target, String body) {
return given()
.header("X-Amz-Target", "DynamoDB_20120810." + target)
.contentType("application/x-amz-json-1.0")
.body(body.getBytes(java.nio.charset.StandardCharsets.UTF_8))
.when().post("/");
}
private static void createTable(String name, boolean streams, String viewType) {
String stream = streams
? ",\"StreamSpecification\":{\"StreamEnabled\":true,\"StreamViewType\":\"" + viewType + "\"}"
: "";
call("CreateTable", "{\"TableName\":\"" + name + "\","
+ "\"AttributeDefinitions\":[{\"AttributeName\":\"pk\",\"AttributeType\":\"S\"}],"
+ "\"KeySchema\":[{\"AttributeName\":\"pk\",\"KeyType\":\"HASH\"}],"
+ "\"BillingMode\":\"PAY_PER_REQUEST\"" + stream + "}")
.then().statusCode(200);
}
@Test
void createDescribeAndUpdateAGlobalTable() {
String name = "gt-lifecycle-" + Long.toString(System.nanoTime(), 36);
createTable(name, true, "NEW_AND_OLD_IMAGES");
call("CreateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicationGroup\":[{\"RegionName\":\"eu-west-1\"}]}")
.then().statusCode(200)
.body("GlobalTableDescription.GlobalTableName", is(name))
.body("GlobalTableDescription.GlobalTableStatus", is("ACTIVE"))
.body("GlobalTableDescription.ReplicationGroup.RegionName",
containsInAnyOrder("eu-west-1", "us-east-1"))
.body("GlobalTableDescription.ReplicationGroup.ReplicaStatus", hasItem("ACTIVE"));
call("DescribeGlobalTable", "{\"GlobalTableName\":\"" + name + "\"}")
.then().statusCode(200)
.body("GlobalTableDescription.ReplicationGroup.RegionName", hasItem("eu-west-1"));
call("UpdateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicaUpdates\":[{\"Create\":{\"RegionName\":\"ap-south-1\"}},"
+ "{\"Delete\":{\"RegionName\":\"eu-west-1\"}}]}")
.then().statusCode(200)
.body("GlobalTableDescription.ReplicationGroup.RegionName", hasItem("ap-south-1"))
.body("GlobalTableDescription.ReplicationGroup.RegionName", not(hasItem("eu-west-1")));
call("ListGlobalTables", "{}")
.then().statusCode(200)
.body("GlobalTables.GlobalTableName", hasItem(name));
}
@Test
void aSecondCreateOnTheSameTableIsRefused() {
String name = "gt-dup-" + Long.toString(System.nanoTime(), 36);
createTable(name, true, "NEW_AND_OLD_IMAGES");
call("CreateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicationGroup\":[{\"RegionName\":\"eu-west-1\"}]}").then().statusCode(200);
call("CreateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicationGroup\":[{\"RegionName\":\"eu-west-1\"}]}")
.then().statusCode(400)
.body("__type", is("GlobalTableAlreadyExistsException"));
}
@Test
void aTableThatDoesNotExistIsTableNotFound() {
call("CreateGlobalTable", "{\"GlobalTableName\":\"gt-missing-table\","
+ "\"ReplicationGroup\":[{\"RegionName\":\"eu-west-1\"}]}")
.then().statusCode(400)
.body("__type", is("TableNotFoundException"));
}
@Test
void aTableWithoutBothStreamImagesCannotJoin() {
String noStream = "gt-nostream-" + Long.toString(System.nanoTime(), 36);
createTable(noStream, false, null);
call("CreateGlobalTable", "{\"GlobalTableName\":\"" + noStream + "\","
+ "\"ReplicationGroup\":[{\"RegionName\":\"eu-west-1\"}]}")
.then().statusCode(400)
// The code matters: this file raises ValidationException everywhere else, so a
// different shape here would slip past a client catching that one.
.body("__type", is("ValidationException"));
String newOnly = "gt-newonly-" + Long.toString(System.nanoTime(), 36);
createTable(newOnly, true, "NEW_IMAGE");
call("CreateGlobalTable", "{\"GlobalTableName\":\"" + newOnly + "\","
+ "\"ReplicationGroup\":[{\"RegionName\":\"eu-west-1\"}]}")
.then().statusCode(400)
.body("__type", is("ValidationException"));
}
@Test
void describingATableThatIsNotGlobalIsNotFound() {
String name = "gt-plain-" + Long.toString(System.nanoTime(), 36);
createTable(name, true, "NEW_AND_OLD_IMAGES");
call("DescribeGlobalTable", "{\"GlobalTableName\":\"" + name + "\"}")
.then().statusCode(400)
.body("__type", is("GlobalTableNotFoundException"));
}
@Test
void updateRefusesADuplicateAddAndAnAbsentRemove() {
String name = "gt-replicafault-" + Long.toString(System.nanoTime(), 36);
createTable(name, true, "NEW_AND_OLD_IMAGES");
call("CreateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicationGroup\":[{\"RegionName\":\"eu-west-1\"}]}").then().statusCode(200);
call("UpdateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicaUpdates\":[{\"Create\":{\"RegionName\":\"eu-west-1\"}}]}")
.then().statusCode(400)
.body("__type", is("ReplicaAlreadyExistsException"));
// The home region is a replica of its own global table, so re-adding it clashes too.
call("UpdateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicaUpdates\":[{\"Create\":{\"RegionName\":\"us-east-1\"}}]}")
.then().statusCode(400)
.body("__type", is("ReplicaAlreadyExistsException"));
call("UpdateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicaUpdates\":[{\"Delete\":{\"RegionName\":\"ap-northeast-1\"}}]}")
.then().statusCode(400)
.body("__type", is("ReplicaNotFoundException"));
// UpdateTable keeps its idempotent behaviour: the same re-add is accepted there, because
// the model declares neither fault for it.
call("UpdateTable", "{\"TableName\":\"" + name + "\","
+ "\"ReplicaUpdates\":[{\"Create\":{\"RegionName\":\"eu-west-1\"}}]}")
.then().statusCode(200);
}
@Test
void listFiltersByRegion() {
String name = "gt-filter-" + Long.toString(System.nanoTime(), 36);
createTable(name, true, "NEW_AND_OLD_IMAGES");
call("CreateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
+ "\"ReplicationGroup\":[{\"RegionName\":\"sa-east-1\"}]}").then().statusCode(200);
call("ListGlobalTables", "{\"RegionName\":\"sa-east-1\"}")
.then().statusCode(200)
.body("GlobalTables.GlobalTableName", hasItem(name));
call("ListGlobalTables", "{\"RegionName\":\"me-south-1\"}")
.then().statusCode(200)
.body("GlobalTables.GlobalTableName", not(hasItem(name)));
}
}
@@ -3379,7 +3379,7 @@ given()
@Test
void unsupportedOperation() {
given()
.header("X-Amz-Target", "DynamoDB_20120810.CreateGlobalTable")
.header("X-Amz-Target", "DynamoDB_20120810.DescribeGlobalTableSettings")
.contentType(DYNAMODB_CONTENT_TYPE)
.body("{}")
.when()