mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 16:11:48 -05:00
fix(dynamodb): export the table as of ExportTime (#6132)
* fix(dynamodb): export the table as of ExportTime * refactor(dynamodb): share the epoch seconds conversions * fix(dynamodb): treat a table that is still being created as not found on export * docs(dynamodb): note the writes made before point-in-time recovery is enabled * fix(dynamodb): round timestamp inputs to milliseconds as AWS does * fix(dynamodb): check the ListBackups time range limits * fix(dynamodb): check the ListBackups ExclusiveStartBackupArn length * refactor(dynamodb): reuse requireBackupSource for the export table lookup
This commit is contained in:
1 parent
f7576eda1a
commit
da66550c70
12 files changed
+396
-37
No files matched your search
+47
@@ -12,6 +12,8 @@ import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
@@ -53,6 +55,11 @@ class DynamoDbExportTest {
|
||||
.billingMode(BillingMode.PAY_PER_REQUEST)
|
||||
.build());
|
||||
tableArn = tableResp.tableDescription().tableArn();
|
||||
ddb.updateContinuousBackups(UpdateContinuousBackupsRequest.builder()
|
||||
.tableName(TABLE_NAME)
|
||||
.pointInTimeRecoverySpecification(PointInTimeRecoverySpecification.builder()
|
||||
.pointInTimeRecoveryEnabled(true).build())
|
||||
.build());
|
||||
|
||||
// Insert 3 items
|
||||
ddb.putItem(PutItemRequest.builder().tableName(TABLE_NAME)
|
||||
@@ -224,6 +231,46 @@ class DynamoDbExportTest {
|
||||
.isInstanceOf(software.amazon.awssdk.services.dynamodb.model.DynamoDbException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void exportTableToPointInTime_exportTime_exportsTheItemsOfThatTime() throws InterruptedException {
|
||||
Thread.sleep(50);
|
||||
Instant beforeFourthItem = Instant.now();
|
||||
Thread.sleep(50);
|
||||
ddb.putItem(PutItemRequest.builder().tableName(TABLE_NAME)
|
||||
.item(Map.of(
|
||||
"pk", AttributeValue.fromS("user-4"),
|
||||
"sk", AttributeValue.fromS("order-004"),
|
||||
"total", AttributeValue.fromN("10")))
|
||||
.build());
|
||||
|
||||
ExportDescription desc = ddb.exportTableToPointInTime(ExportTableToPointInTimeRequest.builder()
|
||||
.tableArn(tableArn)
|
||||
.s3Bucket(BUCKET_NAME)
|
||||
.s3Prefix("exports-time")
|
||||
.exportTime(beforeFourthItem)
|
||||
.build()).exportDescription();
|
||||
assertThat(desc.exportTime()).isEqualTo(beforeFourthItem.truncatedTo(ChronoUnit.MILLIS));
|
||||
|
||||
try (DynamoDbWaiter waiter = DynamoDbWaiter.builder().client(ddb).build()) {
|
||||
waiter.waitUntilExportCompleted(r -> r.exportArn(desc.exportArn()));
|
||||
}
|
||||
assertThat(ddb.describeExport(DescribeExportRequest.builder().exportArn(desc.exportArn()).build())
|
||||
.exportDescription().itemCount()).isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void exportTableToPointInTime_futureExportTime_throwsInvalidExportTimeException() {
|
||||
assertThatThrownBy(() -> ddb.exportTableToPointInTime(ExportTableToPointInTimeRequest.builder()
|
||||
.tableArn(tableArn)
|
||||
.s3Bucket(BUCKET_NAME)
|
||||
.exportTime(Instant.now().plusSeconds(3600))
|
||||
.build()))
|
||||
.isInstanceOf(InvalidExportTimeException.class)
|
||||
.hasMessageContaining("Export Time is invalid");
|
||||
}
|
||||
|
||||
private String decompressGzip(byte[] data) throws Exception {
|
||||
try (GZIPInputStream gzip = new GZIPInputStream(new ByteArrayInputStream(data));
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(gzip, StandardCharsets.UTF_8))) {
|
||||
|
||||
Reference in new issue
Block a user