mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -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
+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