Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(athena): serialize timestamps as epoch seconds in GetWorkGroup and GetTableMetadata responses (#1524)

Maciej72146eeb02da
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AthenaTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AthenaTest.java
index 31e7b031cf..167cc0ce1f 100644
--- a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AthenaTest.java
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/AthenaTest.java
@@ -3,10 +3,13 @@ package com.floci.test;
import org.junit.jupiter.api.*;
import software.amazon.awssdk.services.athena.AthenaClient;
import software.amazon.awssdk.services.athena.model.*;
+import software.amazon.awssdk.services.glue.GlueClient;
-import java.time.Duration;
+import java.time.Instant;
+import java.util.UUID;
-import static org.assertj.core.api.Assertions.*;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
@DisplayName("Athena Query Execution")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@@ -106,4 +109,72 @@ class AthenaTest {
.build()))
.isInstanceOf(InvalidRequestException.class);
}
+
+ /**
+ * Reproduces issue #1498: the AthenaClient fails to unmarshal the {@code CreationTime} field returned by Floci's
+ * {@code GetWorkGroup} response.
+ */
+ @Test
+ @Order(6)
+ @DisplayName("getWorkGroup must unmarshal creationTime successfully")
+ void getWorkGroupCreationTimeCanBeUnmarshalledBySdk() {
+ String groupName = UUID.randomUUID().toString();
+ athena.createWorkGroup(
+ CreateWorkGroupRequest.builder()
+ .name(groupName)
+ .build()
+ );
+
+ GetWorkGroupResponse response = athena.getWorkGroup(
+ GetWorkGroupRequest.builder()
+ .workGroup(groupName)
+ .build()
+ );
+
+ Instant creationTime = response.workGroup().creationTime();
+ assertThat(creationTime)
+ .as("creationTime must be parseable by the AWS SDK")
+ .isNotNull();
+ }
+
+ @Test
+ @Order(7)
+ @DisplayName("getTableMetadata must unmarshal timestamps successfully")
+ void getTableMetadataTimestampsCanBeUnmarshalledBySdk() {
+ GlueClient glue = TestFixtures.glueClient();
+ String dbName = "athena_ts_test_" + UUID.randomUUID().toString().replace("-", "").substring(0, 8);
+ String tableName = "orders";
+
+ glue.createDatabase(r -> r.databaseInput(i -> i.name(dbName)));
+ glue.createTable(r -> r
+ .databaseName(dbName)
+ .tableInput(t -> t
+ .name(tableName)
+ .tableType("EXTERNAL_TABLE")
+ .storageDescriptor(
+ sd -> sd
+ .location("s3://test-bucket/" + dbName + "/")
+ .columns(c -> c.name("id").type("string"))
+ )
+ )
+ );
+
+ GetTableMetadataResponse response = athena.getTableMetadata(
+ GetTableMetadataRequest.builder()
+ .catalogName("AwsDataCatalog")
+ .databaseName(dbName)
+ .tableName(tableName)
+ .build()
+ );
+
+ assertThat(response.tableMetadata().createTime())
+ .as("createTime must be parseable by the AWS SDK")
+ .isNotNull();
+ assertThat(response.tableMetadata().lastAccessTime())
+ .as("lastAccessTime must be parseable by the AWS SDK")
+ .isNotNull();
+
+ glue.close();
+ }
}
+
diff --git a/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java b/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java
index 69b9156711..9eb04f11c9 100644
--- a/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java
@@ -369,7 +369,7 @@ public class AthenaService {
detail.put("Description", workGroup.getDescription());
}
if (workGroup.getCreationTime() != null) {
- detail.put("CreationTime", workGroup.getCreationTime());
+ detail.put("CreationTime", workGroup.getCreationTime().getEpochSecond());
}
if (workGroup.getConfiguration() != null) {
detail.put("Configuration", workGroup.getConfiguration());
@@ -475,8 +475,8 @@ public class AthenaService {
private Map<String, Object> tableMetadata(String catalog, String database, Table table) {
Map<String, Object> metadata = new LinkedHashMap<>();
metadata.put("Name", table.getName());
- metadata.put("CreateTime", table.getCreateTime() != null ? table.getCreateTime() : Instant.now());
- metadata.put("LastAccessTime", table.getLastAccessTime() != null ? table.getLastAccessTime() : Instant.now());
+ metadata.put("CreateTime", (table.getCreateTime() != null ? table.getCreateTime() : Instant.now()).getEpochSecond());
+ metadata.put("LastAccessTime", (table.getLastAccessTime() != null ? table.getLastAccessTime() : Instant.now()).getEpochSecond());
metadata.put("TableType", table.getTableType() != null ? table.getTableType() : "EXTERNAL_TABLE");
metadata.put("Columns", athenaColumns(table));
metadata.put("Parameters", table.getParameters() != null ? table.getParameters() : Map.of());
diff --git a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaGetWorkGroupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaGetWorkGroupIntegrationTest.java
index 59a6b0eeeb..7a82bc33f2 100644
--- a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaGetWorkGroupIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaGetWorkGroupIntegrationTest.java
@@ -6,8 +6,7 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.*;
@QuarkusTest
class AthenaGetWorkGroupIntegrationTest {
@@ -74,6 +73,38 @@ class AthenaGetWorkGroupIntegrationTest {
equalTo("Athena engine version 3"));
}
+ /**
+ * Reproduces issue #1498: the AthenaClient fails to unmarshal the {@code CreationTime} field returned by Floci's
+ * {@code GetWorkGroup} response.
+ */
+ @Test
+ void getWorkGroupCreationTimeIsSerializedAsEpochSecondsNumber() {
+ given()
+ .header("X-Amz-Target", "AmazonAthena.CreateWorkGroup")
+ .contentType(CONTENT_TYPE)
+ .body("""
+ {
+ "Name": "timestamp-format-bug-wg"
+ }
+ """)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ var response = given()
+ .header("X-Amz-Target", "AmazonAthena.GetWorkGroup")
+ .contentType(CONTENT_TYPE)
+ .body("{ \"WorkGroup\": \"timestamp-format-bug-wg\" }")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("WorkGroup.Name", equalTo("timestamp-format-bug-wg"))
+ .body("WorkGroup.CreationTime", notNullValue())
+ .body("WorkGroup.CreationTime", instanceOf(Number.class));
+ }
+
@Test
void getWorkGroupNotFoundReturnsInvalidRequestException() {
given()
diff --git a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java
index 3046cf36a9..926143c0ea 100644
--- a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java
@@ -2,11 +2,7 @@ package io.github.hectorvent.floci.services.athena;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
-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 org.junit.jupiter.api.*;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@@ -335,4 +331,50 @@ class AthenaIntegrationTest {
.body("__type", equalTo("InvalidRequestException"))
.body("message", equalTo("The primary workgroup cannot be deleted."));
}
+
+ @Test
+ @Order(12)
+ void getTableMetadataTimestampsAreSerializedAsEpochSecondsNumbers() {
+ given()
+ .header("X-Amz-Target", "AWSGlue.CreateDatabase")
+ .contentType(CONTENT_TYPE)
+ .body("{ \"DatabaseInput\": { \"Name\": \"ts-format-test\" } }")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ given()
+ .header("X-Amz-Target", "AWSGlue.CreateTable")
+ .contentType(CONTENT_TYPE)
+ .body("""
+ {
+ "DatabaseName": "ts-format-test",
+ "TableInput": {
+ "Name": "events",
+ "TableType": "EXTERNAL_TABLE",
+ "StorageDescriptor": {
+ "Location": "s3://bucket/events",
+ "Columns": [ { "Name": "id", "Type": "string" } ]
+ }
+ }
+ }
+ """)
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200);
+
+ given()
+ .header("X-Amz-Target", "AmazonAthena.GetTableMetadata")
+ .contentType(CONTENT_TYPE)
+ .body("{ \"CatalogName\": \"AwsDataCatalog\", \"DatabaseName\": \"ts-format-test\", \"TableName\": \"events\" }")
+ .when()
+ .post("/")
+ .then()
+ .statusCode(200)
+ .body("TableMetadata.Name", equalTo("events"))
+ .body("TableMetadata.CreateTime", instanceOf(Number.class))
+ .body("TableMetadata.LastAccessTime", instanceOf(Number.class));
+ }
}