mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(dynamodb): show table creation times to the millisecond (#6325)
* fix(dynamodb): show table creation times to the millisecond * chore(dynamodb): share the time range check between the tests
This commit is contained in:
1 parent
33620a59c0
commit
80e5df933b
5 files changed
+71
-4
No files matched your search
@@ -4903,7 +4903,8 @@ public class DynamoDbService {
|
||||
|
||||
TableDefinition table = requireBackupSource(storageKey, tableArn);
|
||||
Instant startTime = clock.instant().truncatedTo(ChronoUnit.MILLIS);
|
||||
// Seconds, as CreationDateTime is shown, so an EarliestRestorableDateTime in the creation second passes.
|
||||
// AWS cannot enable point-in-time recovery until seconds after the creation, so its
|
||||
// EarliestRestorableDateTime is never in the creation second.
|
||||
if (exportTime != null && (exportTime.isBefore(table.getCreationDateTime().truncatedTo(ChronoUnit.SECONDS))
|
||||
|| startTime.isBefore(exportTime))) {
|
||||
throw new AwsException("InvalidExportTimeException", "Export Time is invalid", 400);
|
||||
|
||||
+3
-3
@@ -486,7 +486,7 @@ public class NativeDynamoDbJsonHandler {
|
||||
description.put("GlobalTableStatus", "ACTIVE");
|
||||
description.put("GlobalTableArn", table.getTableArn());
|
||||
if (table.getCreationDateTime() != null) {
|
||||
description.put("CreationDateTime", table.getCreationDateTime().getEpochSecond());
|
||||
description.put("CreationDateTime", epochSeconds(table.getCreationDateTime()));
|
||||
}
|
||||
description.set("ReplicationGroup", replicaNodes(table, objectMapper.createArrayNode(), true));
|
||||
return description;
|
||||
@@ -3133,7 +3133,7 @@ public class NativeDynamoDbJsonHandler {
|
||||
node.put("TableId", table.getTableId());
|
||||
node.put("TableStatus", table.getTableStatus());
|
||||
node.put("TableArn", table.getTableArn());
|
||||
node.put("CreationDateTime", table.getCreationDateTime().getEpochSecond());
|
||||
node.put("CreationDateTime", epochSeconds(table.getCreationDateTime()));
|
||||
node.put("ItemCount", table.getItemCount());
|
||||
node.put("TableSizeBytes", table.getTableSizeBytes());
|
||||
node.put("DeletionProtectionEnabled", table.isDeletionProtectionEnabled());
|
||||
@@ -3142,7 +3142,7 @@ public class NativeDynamoDbJsonHandler {
|
||||
ObjectNode billing = objectMapper.createObjectNode();
|
||||
billing.put("BillingMode", "PAY_PER_REQUEST");
|
||||
billing.put("LastUpdateToPayPerRequestDateTime",
|
||||
table.getCreationDateTime().getEpochSecond());
|
||||
epochSeconds(table.getCreationDateTime()));
|
||||
node.set("BillingModeSummary", billing);
|
||||
}
|
||||
|
||||
|
||||
+17
@@ -6,6 +6,10 @@ import io.restassured.parsing.Parser;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.DynamoDbRequests.assertEpochMillisBetween;
|
||||
import static io.github.hectorvent.floci.testing.DynamoDbRequests.decimalAt;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
@@ -71,6 +75,19 @@ class DynamoDbGlobalTableIntegrationTest {
|
||||
.body("GlobalTables.GlobalTableName", hasItem(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
void creationDateTimeHasMilliseconds() throws Exception {
|
||||
String name = "gt-created-" + Long.toString(System.nanoTime(), 36);
|
||||
long before = System.currentTimeMillis();
|
||||
createTable(name, true, "NEW_AND_OLD_IMAGES");
|
||||
|
||||
BigDecimal created = decimalAt(call("CreateGlobalTable", "{\"GlobalTableName\":\"" + name + "\","
|
||||
+ "\"ReplicationGroup\":[{\"RegionName\":\"eu-west-1\"}]}")
|
||||
.then().statusCode(200), "/GlobalTableDescription/CreationDateTime");
|
||||
long after = System.currentTimeMillis();
|
||||
assertEpochMillisBetween(before, created, after);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSecondCreateOnTheSameTableIsRefused() {
|
||||
String name = "gt-dup-" + Long.toString(System.nanoTime(), 36);
|
||||
|
||||
+43
@@ -5,18 +5,22 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
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 java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
import static io.github.hectorvent.floci.testing.DynamoDbRequests.assertEpochMillisBetween;
|
||||
import static io.github.hectorvent.floci.testing.DynamoDbRequests.decimalAt;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -5879,6 +5883,45 @@ given()
|
||||
deleteTable(tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void tableTimesHaveMilliseconds() throws Exception {
|
||||
String tableName = "CreationMillisTable";
|
||||
long before = System.currentTimeMillis();
|
||||
BigDecimal created = decimalAt(given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.CreateTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{
|
||||
"TableName": "%s",
|
||||
"KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}],
|
||||
"AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}],
|
||||
"BillingMode": "PAY_PER_REQUEST"
|
||||
}
|
||||
""".formatted(tableName))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200), "/TableDescription/CreationDateTime");
|
||||
long after = System.currentTimeMillis();
|
||||
assertEpochMillisBetween(before, created, after);
|
||||
|
||||
ValidatableResponse described = given()
|
||||
.header("X-Amz-Target", "DynamoDB_20120810.DescribeTable")
|
||||
.contentType(DYNAMODB_CONTENT_TYPE)
|
||||
.body("""
|
||||
{"TableName": "%s"}
|
||||
""".formatted(tableName))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertEquals(0, created.compareTo(decimalAt(described, "/Table/CreationDateTime")));
|
||||
assertEquals(0, created.compareTo(
|
||||
decimalAt(described, "/Table/BillingModeSummary/LastUpdateToPayPerRequestDateTime")));
|
||||
|
||||
deleteTable(tableName);
|
||||
}
|
||||
|
||||
@Test
|
||||
void twoGsiDeletionsInSameRequestFailWithLimitExceeded() {
|
||||
// Catches: Floci deletes both indexes when one UpdateTable request carries two GSI deletes
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.restassured.response.ValidatableResponse;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public final class DynamoDbRequests {
|
||||
|
||||
@@ -28,4 +29,9 @@ public final class DynamoDbRequests {
|
||||
public static BigDecimal decimalAt(ValidatableResponse response, String pointer) throws Exception {
|
||||
return EXACT.readTree(response.extract().asString()).at(pointer).decimalValue();
|
||||
}
|
||||
|
||||
public static void assertEpochMillisBetween(long before, BigDecimal epochSeconds, long after) {
|
||||
long millis = epochSeconds.movePointRight(3).longValueExact();
|
||||
assertTrue(before <= millis && millis <= after, epochSeconds + " is not between " + before + " and " + after);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user