feat(firehose): validate and persist DataFormatConversionConfiguration (#3236)

* feat(firehose): validate and persist DataFormatConversionConfiguration

Accept, validate, store, and echo the extended S3 destination's
DataFormatConversionConfiguration instead of silently ignoring it.
Validation messages and precedence follow probed AWS behavior: Smithy
ParquetSerDe bounds first, then compression, buffering floor, and
member checks in AWS order, identical on CreateDeliveryStream and
UpdateDestination, which now merges the configuration member-wise and
validates the merged effective state. OrcSerDe is rejected as a
documented deviation (the planned DuckDB engine cannot write ORC).
Conversion itself is not applied yet: delivery logs a warning and
ships records unconverted.

* docs(firehose): match the conversion helpers' wording to what they do

The legacy-shape helper clears DataFormatConversionConfiguration alone, not
every extended-only member, and the create/update warning fires on each call
that leaves conversion enabled rather than once. Rename the first and reword
both so the contract a reader infers is the one the code keeps.
This commit is contained in:
Kenshin Okinaka authored and GitHub committed 2026-09-08 09:01:31 -04:00
1 parent af42564cb3
commit 8a122d2b8c
10 files changed
+2267 -21

No files matched your search

@@ -0,0 +1,249 @@
package io.github.hectorvent.floci.services.firehose;
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 static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
* Wire-level coverage for DataFormatConversionConfiguration: the unit tests in
* {@link FirehoseDataFormatConversionTest} build model objects directly, so
* this class is what exercises the JSON-to-model mapping of the nested shapes
* and the error responses as an SDK would see them.
*/
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class FirehoseDataFormatConversionIntegrationTest {
private static final String STREAM_NAME = "test-format-conversion-stream";
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/firehose-delivery-role";
private static final String BUCKET_ARN = "arn:aws:s3:::conversion-archive";
private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
private static final String TARGET_PREFIX = "Firehose_20150804.";
private static final String DESCRIPTION_PATH =
"DeliveryStreamDescription.Destinations[0].ExtendedS3DestinationDescription";
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
@Order(1)
void createAcceptsAFullConversionConfiguration() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + "CreateDeliveryStream")
.body("""
{
"DeliveryStreamName": "%s",
"DeliveryStreamType": "DirectPut",
"ExtendedS3DestinationConfiguration": {
"RoleARN": "%s",
"BucketARN": "%s",
"CompressionFormat": "UNCOMPRESSED",
"BufferingHints": { "SizeInMBs": 64, "IntervalInSeconds": 60 },
"DataFormatConversionConfiguration": {
"Enabled": true,
"SchemaConfiguration": {
"RoleARN": "%s",
"DatabaseName": "analytics",
"TableName": "events",
"Region": "us-east-1"
},
"InputFormatConfiguration": { "Deserializer": { "OpenXJsonSerDe": {} } },
"OutputFormatConfiguration": {
"Serializer": { "ParquetSerDe": { "Compression": "GZIP", "WriterVersion": "V2" } }
}
}
}
}
""".formatted(STREAM_NAME, ROLE_ARN, BUCKET_ARN, ROLE_ARN))
.when()
.post("/")
.then()
.statusCode(200)
.body("DeliveryStreamARN", notNullValue());
}
/**
* The description echoes the configuration as given: no CatalogId or VersionId
* materialized, the empty OpenXJsonSerDe kept, and the conversion member absent
* from the plain S3DestinationDescription mirror, which does not have it in
* AWS's model.
*/
@Test
@Order(2)
void describeEchoesTheConversionConfigurationVerbatim() {
String conversionPath = DESCRIPTION_PATH + ".DataFormatConversionConfiguration";
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + "DescribeDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + STREAM_NAME + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body(conversionPath + ".Enabled", equalTo(true))
.body(conversionPath + ".SchemaConfiguration.RoleARN", equalTo(ROLE_ARN))
.body(conversionPath + ".SchemaConfiguration.DatabaseName", equalTo("analytics"))
.body(conversionPath + ".SchemaConfiguration.TableName", equalTo("events"))
.body(conversionPath + ".SchemaConfiguration.Region", equalTo("us-east-1"))
.body(conversionPath + ".SchemaConfiguration.CatalogId", nullValue())
.body(conversionPath + ".SchemaConfiguration.VersionId", nullValue())
.body(conversionPath + ".InputFormatConfiguration.Deserializer.OpenXJsonSerDe", notNullValue())
.body(conversionPath + ".OutputFormatConfiguration.Serializer.ParquetSerDe.Compression", equalTo("GZIP"))
.body(conversionPath + ".OutputFormatConfiguration.Serializer.ParquetSerDe.WriterVersion", equalTo("V2"))
.body(conversionPath + ".OutputFormatConfiguration.Serializer.ParquetSerDe.BlockSizeBytes", nullValue())
.body("DeliveryStreamDescription.Destinations[0].S3DestinationDescription"
+ ".DataFormatConversionConfiguration", nullValue());
}
@Test
@Order(3)
void updateCarryingOnlyEnabledFalseKeepsTheStoredMembers() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + "UpdateDestination")
.body("""
{
"DeliveryStreamName": "%s",
"CurrentDeliveryStreamVersionId": "1",
"DestinationId": "destinationId-000000000001",
"ExtendedS3DestinationUpdate": {
"DataFormatConversionConfiguration": { "Enabled": false }
}
}
""".formatted(STREAM_NAME))
.when()
.post("/")
.then()
.statusCode(200);
String conversionPath = DESCRIPTION_PATH + ".DataFormatConversionConfiguration";
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + "DescribeDeliveryStream")
.body("{ \"DeliveryStreamName\": \"" + STREAM_NAME + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("DeliveryStreamDescription.VersionId", equalTo("2"))
.body(conversionPath + ".Enabled", equalTo(false))
.body(conversionPath + ".SchemaConfiguration.DatabaseName", equalTo("analytics"))
.body(conversionPath + ".OutputFormatConfiguration.Serializer.ParquetSerDe", notNullValue());
}
/**
* The legacy shape does not model the member, and AWS's JSON protocol ignores a
* member a shape does not model, so the request succeeds with it disregarded
* rather than stored. The SDKs cannot send it here at all.
*/
@Test
@Order(6)
void legacyS3DestinationShapeIgnoresTheConversionMember() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + "CreateDeliveryStream")
.body("""
{
"DeliveryStreamName": "legacy-shape-conversion-stream",
"S3DestinationConfiguration": {
"RoleARN": "%s",
"BucketARN": "%s",
"CompressionFormat": "UNCOMPRESSED",
"DataFormatConversionConfiguration": {
"Enabled": true,
"SchemaConfiguration": { "RoleARN": "%s", "DatabaseName": "db", "TableName": "t" },
"InputFormatConfiguration": { "Deserializer": { "OpenXJsonSerDe": {} } },
"OutputFormatConfiguration": { "Serializer": { "ParquetSerDe": {} } }
}
}
}
""".formatted(ROLE_ARN, BUCKET_ARN, ROLE_ARN))
.when()
.post("/")
.then()
.statusCode(200);
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + "DescribeDeliveryStream")
.body("{ \"DeliveryStreamName\": \"legacy-shape-conversion-stream\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body(DESCRIPTION_PATH + ".DataFormatConversionConfiguration", nullValue());
}
@Test
@Order(4)
void createRejectsCompressedDestinationsWithTheAwsMessage() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + "CreateDeliveryStream")
.body("""
{
"DeliveryStreamName": "rejected-conversion-stream",
"ExtendedS3DestinationConfiguration": {
"RoleARN": "%s",
"BucketARN": "%s",
"CompressionFormat": "GZIP",
"DataFormatConversionConfiguration": {
"Enabled": true,
"SchemaConfiguration": { "RoleARN": "%s", "DatabaseName": "db", "TableName": "t" },
"InputFormatConfiguration": { "Deserializer": { "OpenXJsonSerDe": {} } },
"OutputFormatConfiguration": { "Serializer": { "ParquetSerDe": {} } }
}
}
}
""".formatted(ROLE_ARN, BUCKET_ARN, ROLE_ARN))
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidArgumentException"))
.body("message", equalTo("The S3 destination's compression format must be set to UNCOMPRESSED"
+ " when data format conversion is enabled. To enable compression within the converted"
+ " output format, set the appropriate serialization option in the output format configuration."));
}
@Test
@Order(5)
void createRejectsParquetSerDeBoundsAtTheSmithyLayer() {
given()
.contentType(CONTENT_TYPE)
.header("X-Amz-Target", TARGET_PREFIX + "CreateDeliveryStream")
.body("""
{
"DeliveryStreamName": "rejected-bounds-stream",
"ExtendedS3DestinationConfiguration": {
"RoleARN": "%s",
"BucketARN": "%s",
"DataFormatConversionConfiguration": {
"OutputFormatConfiguration": { "Serializer": { "ParquetSerDe": { "PageSizeBytes": 1 } } }
}
}
}
""".formatted(ROLE_ARN, BUCKET_ARN))
.when()
.post("/")
.then()
.statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("1 validation error detected: Value at"
+ " 'extendedS3DestinationConfiguration.dataFormatConversionConfiguration"
+ ".outputFormatConfiguration.serializer.parquetSerDe.pageSizeBytes'"
+ " failed to satisfy constraint: Member must have value greater than or equal to 65536"));
}
}
@@ -0,0 +1,522 @@
package io.github.hectorvent.floci.services.firehose;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.BufferingHints;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.DataFormatConversionConfiguration;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Deserializer;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.HiveJsonSerDe;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.InputFormatConfiguration;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.OpenXJsonSerDe;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.OrcSerDe;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.OutputFormatConfiguration;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.ParquetSerDe;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.S3Destination;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.SchemaConfiguration;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.Serializer;
import io.github.hectorvent.floci.services.kinesis.KinesisService;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.testing.MutableClock;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Every error message and the precedence between them was captured from real
* AWS (probe 2026-09-07, us-west-2), covering both CreateDeliveryStream and
* UpdateDestination. See okinaka/floci discussion 118 for the probe record.
*/
class FirehoseDataFormatConversionTest {
private static final String COMPRESSION_MESSAGE = "The S3 destination's compression format must be set"
+ " to UNCOMPRESSED when data format conversion is enabled. To enable compression within the"
+ " converted output format, set the appropriate serialization option in the output format configuration.";
private static final String BUFFER_MESSAGE =
"BufferingHints.SizeInMBs must be at least 64 when data format conversion is enabled.";
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/firehose-role";
private static final String DESTINATION_ID = "destinationId-000000000001";
private FirehoseService service;
@BeforeEach
void setUp() {
StorageFactory storageFactory = mock(StorageFactory.class);
Map<String, AccountAwareStorageBackend<?>> backends = new HashMap<>();
when(storageFactory.create(anyString(), anyString(), any()))
.thenAnswer(invocation -> backends.computeIfAbsent(
invocation.getArgument(0) + "/" + invocation.getArgument(1),
k -> AccountAwareStorageBackend.inMemory("000000000000")));
EmulatorConfig.FirehoseServiceConfig firehoseCfg = mock(EmulatorConfig.FirehoseServiceConfig.class);
when(firehoseCfg.enabled()).thenReturn(true);
when(firehoseCfg.tickIntervalSeconds()).thenReturn(10L);
when(firehoseCfg.flushRecordCount()).thenReturn(0);
EmulatorConfig.ServicesConfig servicesCfg = mock(EmulatorConfig.ServicesConfig.class);
when(servicesCfg.firehose()).thenReturn(firehoseCfg);
EmulatorConfig config = mock(EmulatorConfig.class);
when(config.services()).thenReturn(servicesCfg);
RegionResolver regionResolver = mock(RegionResolver.class);
when(regionResolver.getDefaultRegion()).thenReturn("us-east-1");
when(regionResolver.getAccountId()).thenReturn("000000000000");
service = new FirehoseService(storageFactory, Mockito.mock(S3Service.class),
Mockito.mock(KinesisService.class), regionResolver, new MutableClock(), config);
}
private static SchemaConfiguration schema() {
SchemaConfiguration schema = new SchemaConfiguration();
schema.setRoleArn(ROLE_ARN);
schema.setDatabaseName("db");
schema.setTableName("table");
schema.setRegion("us-east-1");
return schema;
}
private static InputFormatConfiguration openXInput() {
Deserializer deserializer = new Deserializer();
deserializer.setOpenXJsonSerDe(new OpenXJsonSerDe());
InputFormatConfiguration input = new InputFormatConfiguration();
input.setDeserializer(deserializer);
return input;
}
private static OutputFormatConfiguration parquetOutput() {
Serializer serializer = new Serializer();
serializer.setParquetSerDe(new ParquetSerDe());
OutputFormatConfiguration output = new OutputFormatConfiguration();
output.setSerializer(serializer);
return output;
}
private static DataFormatConversionConfiguration fullConversion() {
DataFormatConversionConfiguration conversion = new DataFormatConversionConfiguration();
conversion.setEnabled(true);
conversion.setSchemaConfiguration(schema());
conversion.setInputFormatConfiguration(openXInput());
conversion.setOutputFormatConfiguration(parquetOutput());
return conversion;
}
private static S3Destination destination(Consumer<S3Destination> customizer) {
S3Destination s3 = new S3Destination();
s3.setRoleArn(ROLE_ARN);
s3.setBucketArn("arn:aws:s3:::results");
BufferingHints hints = new BufferingHints();
hints.setSizeInMBs(64);
hints.setIntervalInSeconds(60);
s3.setBufferingHints(hints);
s3.setCompressionFormat("UNCOMPRESSED");
s3.setDataFormatConversionConfiguration(fullConversion());
customizer.accept(s3);
return s3;
}
private AwsException assertCreateRejected(Consumer<S3Destination> customizer) {
AwsException error = assertThrows(AwsException.class,
() -> service.createDeliveryStream("stream", destination(customizer)));
assertEquals("InvalidArgumentException", error.getErrorCode());
assertEquals(400, error.getHttpStatus());
return error;
}
private static BufferingHints hints(int sizeInMBs) {
BufferingHints hints = new BufferingHints();
hints.setSizeInMBs(sizeInMBs);
hints.setIntervalInSeconds(60);
return hints;
}
// ── create: message and precedence matrix ────────────────────────────────
@Test
void createAcceptsAFullyValidConversionConfiguration() {
assertDoesNotThrow(() -> service.createDeliveryStream("stream", destination(s3 -> {})));
}
@Test
void compressionCheckComesBeforeEveryOtherConversionCheck() {
AwsException error = assertCreateRejected(s3 -> {
s3.setCompressionFormat("GZIP");
s3.setBufferingHints(hints(5));
s3.getDataFormatConversionConfiguration().setSchemaConfiguration(null);
});
assertEquals(COMPRESSION_MESSAGE, error.getMessage());
}
@Test
void bufferSizeCheckComesBeforeTheMissingMemberChecks() {
AwsException error = assertCreateRejected(s3 -> {
s3.setBufferingHints(hints(5));
s3.getDataFormatConversionConfiguration().setSchemaConfiguration(null);
});
assertEquals(BUFFER_MESSAGE, error.getMessage());
}
@Test
void bufferSizeBelow64IsRejectedOnlyWhenExplicit() {
assertEquals(BUFFER_MESSAGE,
assertCreateRejected(s3 -> s3.setBufferingHints(hints(63))).getMessage());
// Probe: a destination with no BufferingHints at all passes the floor check.
assertDoesNotThrow(() -> service.createDeliveryStream("no-hints",
destination(s3 -> s3.setBufferingHints(null))));
}
/** Probed: AWS stores 128 MiB, not the ordinary 5 MiB, when a converting stream omits hints. */
@Test
void omittedHintsGetTheConversionSizeDefault() {
service.createDeliveryStream("converting", destination(s3 -> s3.setBufferingHints(null)));
BufferingHints stored = service.describeDeliveryStream("converting")
.s3Destination().getBufferingHints();
assertEquals(128, stored.getSizeInMBs());
assertEquals(300, stored.getIntervalInSeconds());
}
@Test
void omittedHintsKeepTheOrdinaryDefaultWithoutConversion() {
service.createDeliveryStream("plain", destination(s3 -> {
s3.setBufferingHints(null);
s3.setDataFormatConversionConfiguration(null);
}));
BufferingHints stored = service.describeDeliveryStream("plain")
.s3Destination().getBufferingHints();
assertEquals(5, stored.getSizeInMBs());
assertEquals(300, stored.getIntervalInSeconds());
}
/**
* Regression: storing 5 MiB for a converting stream made every later update fail
* the floor check, since the merged state then carried an explicit 5.
*/
@Test
void anUnrelatedUpdateSucceedsOnAStreamCreatedWithoutHints() {
service.createDeliveryStream("converting", destination(s3 -> s3.setBufferingHints(null)));
assertDoesNotThrow(() -> service.updateDestination("converting", currentVersion("converting"),
DESTINATION_ID, update(u -> u.setPrefix("changed/"))));
S3Destination stored = service.describeDeliveryStream("converting").s3Destination();
assertEquals("changed/", stored.getPrefix());
assertEquals(128, stored.getBufferingHints().getSizeInMBs());
}
@Test
void missingMembersAreReportedInInputOutputSchemaOrder() {
DataFormatConversionConfiguration onlyEnabled = new DataFormatConversionConfiguration();
onlyEnabled.setEnabled(true);
assertEquals("InputFormatConfiguration must not be null",
assertCreateRejected(s3 -> s3.setDataFormatConversionConfiguration(onlyEnabled)).getMessage());
assertEquals("OutputFormatConfiguration must not be null",
assertCreateRejected(s3 -> {
s3.getDataFormatConversionConfiguration().setOutputFormatConfiguration(null);
s3.getDataFormatConversionConfiguration().setSchemaConfiguration(null);
}).getMessage());
assertEquals("SchemaConfiguration must not be null",
assertCreateRejected(s3 -> s3.getDataFormatConversionConfiguration().setSchemaConfiguration(null))
.getMessage());
}
/** An empty Deserializer or Serializer object reports the same error as an absent one. */
@Test
void emptyDeserializerAndSerializerReportTheNullMessage() {
assertEquals("Deserializer must not be null",
assertCreateRejected(s3 -> s3.getDataFormatConversionConfiguration()
.getInputFormatConfiguration().setDeserializer(new Deserializer())).getMessage());
assertEquals("Serializer must not be null",
assertCreateRejected(s3 -> s3.getDataFormatConversionConfiguration()
.getOutputFormatConfiguration().setSerializer(new Serializer())).getMessage());
}
@Test
void specifyingBothSerdesOfAUnionIsRejected() {
assertEquals("More than one deserializer specified. Only one may be chosen.",
assertCreateRejected(s3 -> s3.getDataFormatConversionConfiguration()
.getInputFormatConfiguration().getDeserializer().setHiveJsonSerDe(new HiveJsonSerDe()))
.getMessage());
assertEquals("More than one serializer specified. Only one may be chosen.",
assertCreateRejected(s3 -> s3.getDataFormatConversionConfiguration()
.getOutputFormatConfiguration().getSerializer().setOrcSerDe(new OrcSerDe()))
.getMessage());
}
/** Floci deviation: real AWS accepts OrcSerDe, but DuckDB cannot write ORC. */
@Test
void orcSerDeIsRejectedExplicitly() {
AwsException error = assertCreateRejected(s3 -> {
Serializer serializer = new Serializer();
serializer.setOrcSerDe(new OrcSerDe());
s3.getDataFormatConversionConfiguration().getOutputFormatConfiguration().setSerializer(serializer);
});
assertEquals("OrcSerDe is not supported. Floci supports only ParquetSerDe for data format conversion.",
error.getMessage());
}
@Test
void schemaMembersAreRequiredWithTheAwsCasedMessages() {
assertEquals("SchemaConfiguration.RoleArn must not be null or empty",
assertCreateRejected(s3 -> s3.getDataFormatConversionConfiguration()
.getSchemaConfiguration().setRoleArn(null)).getMessage());
assertEquals("SchemaConfiguration.DatabaseName must not be null or empty",
assertCreateRejected(s3 -> s3.getDataFormatConversionConfiguration()
.getSchemaConfiguration().setDatabaseName("")).getMessage());
assertEquals("SchemaConfiguration.TableName must not be null or empty",
assertCreateRejected(s3 -> s3.getDataFormatConversionConfiguration()
.getSchemaConfiguration().setTableName(null)).getMessage());
}
@Test
void omittedEnabledIsTreatedAsEnabled() {
AwsException error = assertCreateRejected(s3 -> {
s3.getDataFormatConversionConfiguration().setEnabled(null);
s3.getDataFormatConversionConfiguration().setSchemaConfiguration(null);
});
assertEquals("SchemaConfiguration must not be null", error.getMessage());
}
@Test
void disabledConversionSkipsEveryCheckButIsStored() {
service.createDeliveryStream("disabled", destination(s3 -> {
s3.setCompressionFormat("GZIP");
s3.setBufferingHints(hints(5));
s3.getDataFormatConversionConfiguration().setEnabled(false);
}));
DataFormatConversionConfiguration stored = service.describeDeliveryStream("disabled")
.s3Destination().getDataFormatConversionConfiguration();
assertEquals(false, stored.getEnabled());
assertNotNull(stored.getSchemaConfiguration());
}
// ── describe: null-honest echo ───────────────────────────────────────────
@Test
void describeEchoesTheConfigurationWithoutMaterializingDefaults() {
service.createDeliveryStream("stream", destination(s3 -> {}));
S3Destination described = service.describeDeliveryStream("stream").s3Destination();
DataFormatConversionConfiguration conversion = described.getDataFormatConversionConfiguration();
assertEquals(true, conversion.getEnabled());
assertNull(conversion.getSchemaConfiguration().getCatalogId());
assertNull(conversion.getSchemaConfiguration().getVersionId());
ParquetSerDe parquet = conversion.getOutputFormatConfiguration().getSerializer().getParquetSerDe();
assertNotNull(parquet);
assertNull(parquet.getCompression());
assertNull(parquet.getBlockSizeBytes());
}
/**
* A disabled ORC configuration is stored rather than rejected, so Describe has to
* echo its members: modeling OrcSerDe as a bare marker used to drop them silently.
*/
@Test
void disabledOrcConfigurationKeepsItsSerDeMembers() {
OrcSerDe orc = new OrcSerDe();
orc.setStripeSizeBytes(67108864L);
orc.setCompression("SNAPPY");
orc.setFormatVersion("V0_12");
service.createDeliveryStream("orc", destination(s3 -> {
Serializer serializer = new Serializer();
serializer.setOrcSerDe(orc);
s3.getDataFormatConversionConfiguration().getOutputFormatConfiguration()
.setSerializer(serializer);
s3.getDataFormatConversionConfiguration().setEnabled(false);
}));
OrcSerDe stored = service.describeDeliveryStream("orc").s3Destination()
.getDataFormatConversionConfiguration().getOutputFormatConfiguration()
.getSerializer().getOrcSerDe();
assertEquals(67108864L, stored.getStripeSizeBytes());
assertEquals("SNAPPY", stored.getCompression());
assertEquals("V0_12", stored.getFormatVersion());
assertNull(stored.getRowIndexStride());
}
/**
* Every member AWS defines on a destination is PascalCase, so a camelCase key is
* proof that a helper leaked into the wire shape: an {@code is...} accessor with
* no backing field of that name becomes a Jackson property unless it is ignored.
*/
@Test
void destinationRendersOnlyAwsDefinedMembers() throws Exception {
service.createDeliveryStream("stream", destination(s3 -> {}));
DeliveryStreamDescription.Destination destination =
service.describeDeliveryStream("stream").getDestinations().get(0);
com.fasterxml.jackson.databind.ObjectMapper mapper =
new com.fasterxml.jackson.databind.ObjectMapper();
for (Object rendered : List.of(destination.getExtendedS3DestinationDescription(),
destination.getS3DestinationDescription())) {
com.fasterxml.jackson.databind.JsonNode json = mapper.valueToTree(rendered);
json.fieldNames().forEachRemaining(name -> assertTrue(Character.isUpperCase(name.charAt(0)),
"unexpected non-AWS member rendered: " + name + " in " + json));
}
}
/** The plain S3DestinationDescription mirror has no conversion member in AWS's model. */
@Test
void conversionIsExtendedOnlyAndAbsentFromTheStandardView() {
service.createDeliveryStream("stream", destination(s3 -> {}));
DeliveryStreamDescription.Destination dest =
service.describeDeliveryStream("stream").getDestinations().get(0);
assertNotNull(dest.getExtendedS3DestinationDescription().getDataFormatConversionConfiguration());
assertNull(dest.getS3DestinationDescription().getDataFormatConversionConfiguration());
}
// ── update: validation on the merged state, member-wise merge ────────────
private String currentVersion(String name) {
return service.describeDeliveryStream(name).getVersionId();
}
private static S3Destination update(Consumer<S3Destination> customizer) {
S3Destination update = new S3Destination();
customizer.accept(update);
return update;
}
@Test
void updateAppliesTheSameChecksAgainstTheMergedState() {
service.createDeliveryStream("stream", destination(s3 -> {}));
AwsException gzip = assertThrows(AwsException.class, () -> service.updateDestination("stream",
currentVersion("stream"), DESTINATION_ID, update(u -> u.setCompressionFormat("GZIP"))));
assertEquals(COMPRESSION_MESSAGE, gzip.getMessage());
AwsException buffer = assertThrows(AwsException.class, () -> service.updateDestination("stream",
currentVersion("stream"), DESTINATION_ID, update(u -> u.setBufferingHints(hints(5)))));
assertEquals(BUFFER_MESSAGE, buffer.getMessage());
}
/** Probed: AWS rejects this too, since a plain stream stores the 5 MiB default. */
@Test
void enablingConversionOnAPlainStreamIsRejectedForItsStoredBufferSize() {
service.createDeliveryStream("plain", destination(s3 -> {
s3.setBufferingHints(null);
s3.setDataFormatConversionConfiguration(null);
}));
AwsException error = assertThrows(AwsException.class, () -> service.updateDestination("plain",
currentVersion("plain"), DESTINATION_ID,
update(u -> u.setDataFormatConversionConfiguration(fullConversion()))));
assertEquals(BUFFER_MESSAGE, error.getMessage());
}
@Test
void disablingWithOnlyEnabledPreservesTheStoredMembers() {
service.createDeliveryStream("stream", destination(s3 -> {}));
String versionBefore = currentVersion("stream");
DataFormatConversionConfiguration disable = new DataFormatConversionConfiguration();
disable.setEnabled(false);
service.updateDestination("stream", versionBefore, DESTINATION_ID,
update(u -> u.setDataFormatConversionConfiguration(disable)));
DataFormatConversionConfiguration stored = service.describeDeliveryStream("stream")
.s3Destination().getDataFormatConversionConfiguration();
assertEquals(false, stored.getEnabled());
assertEquals("db", stored.getSchemaConfiguration().getDatabaseName());
assertNotNull(stored.getInputFormatConfiguration().getDeserializer().getOpenXJsonSerDe());
assertNotNull(stored.getOutputFormatConfiguration().getSerializer().getParquetSerDe());
assertFalse(versionBefore.equals(currentVersion("stream")));
}
@Test
void reenablingAloneIsRejectedWhileGzipIsInEffectAndLeavesTheStoreUntouched() {
service.createDeliveryStream("stream", destination(s3 -> {}));
DataFormatConversionConfiguration disable = new DataFormatConversionConfiguration();
disable.setEnabled(false);
service.updateDestination("stream", currentVersion("stream"), DESTINATION_ID,
update(u -> u.setDataFormatConversionConfiguration(disable)));
service.updateDestination("stream", currentVersion("stream"), DESTINATION_ID,
update(u -> u.setCompressionFormat("GZIP")));
String versionBefore = currentVersion("stream");
DataFormatConversionConfiguration reenable = new DataFormatConversionConfiguration();
reenable.setEnabled(true);
AwsException error = assertThrows(AwsException.class, () -> service.updateDestination("stream",
versionBefore, DESTINATION_ID, update(u -> u.setDataFormatConversionConfiguration(reenable))));
assertEquals(COMPRESSION_MESSAGE, error.getMessage());
S3Destination stored = service.describeDeliveryStream("stream").s3Destination();
assertEquals(versionBefore, currentVersion("stream"));
assertEquals("GZIP", stored.getCompressionFormat());
assertEquals(false, stored.getDataFormatConversionConfiguration().getEnabled());
}
/** Probed: SchemaConfiguration merges a member at a time, like its parent. */
@Test
void updatingOneSchemaMemberKeepsTheOtherStoredOnes() {
service.createDeliveryStream("stream", destination(s3 -> {}));
SchemaConfiguration schemaUpdate = new SchemaConfiguration();
schemaUpdate.setTableName("other_table");
DataFormatConversionConfiguration conversionUpdate = new DataFormatConversionConfiguration();
conversionUpdate.setSchemaConfiguration(schemaUpdate);
service.updateDestination("stream", currentVersion("stream"), DESTINATION_ID,
update(u -> u.setDataFormatConversionConfiguration(conversionUpdate)));
SchemaConfiguration stored = service.describeDeliveryStream("stream").s3Destination()
.getDataFormatConversionConfiguration().getSchemaConfiguration();
assertEquals("other_table", stored.getTableName());
assertEquals("db", stored.getDatabaseName());
assertEquals(ROLE_ARN, stored.getRoleArn());
assertEquals("us-east-1", stored.getRegion());
}
@Test
void reenablingTogetherWithUncompressedSucceedsOnTheStoredSchema() {
service.createDeliveryStream("stream", destination(s3 -> {}));
DataFormatConversionConfiguration disable = new DataFormatConversionConfiguration();
disable.setEnabled(false);
service.updateDestination("stream", currentVersion("stream"), DESTINATION_ID,
update(u -> u.setDataFormatConversionConfiguration(disable)));
service.updateDestination("stream", currentVersion("stream"), DESTINATION_ID,
update(u -> u.setCompressionFormat("GZIP")));
DataFormatConversionConfiguration reenable = new DataFormatConversionConfiguration();
reenable.setEnabled(true);
service.updateDestination("stream", currentVersion("stream"), DESTINATION_ID, update(u -> {
u.setCompressionFormat("UNCOMPRESSED");
u.setDataFormatConversionConfiguration(reenable);
}));
S3Destination stored = service.describeDeliveryStream("stream").s3Destination();
assertTrue(stored.isDataFormatConversionEnabled());
assertEquals("UNCOMPRESSED", stored.getCompressionFormat());
assertEquals("db", stored.getDataFormatConversionConfiguration()
.getSchemaConfiguration().getDatabaseName());
}
@Test
void updateOntoAStreamWithoutADestinationValidatesTheUpdateItself() {
service.createDeliveryStream("bare", (S3Destination) null, List.of());
AwsException error = assertThrows(AwsException.class, () -> service.updateDestination("bare",
currentVersion("bare"), DESTINATION_ID, destination(s3 -> s3.setBufferingHints(hints(5)))));
assertEquals(BUFFER_MESSAGE, error.getMessage());
}
}
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.firehose;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.S3Destination;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -108,4 +109,517 @@ class S3DestinationValidatorTest {
new S3Destination(), "s3DestinationConfiguration"));
}
private static final String PARQUET_PATH = "extendedS3DestinationConfiguration"
+ ".dataFormatConversionConfiguration.outputFormatConfiguration.serializer.parquetSerDe";
private static S3Destination withParquetSerDe(DeliveryStreamDescription.ParquetSerDe parquet) {
DeliveryStreamDescription.Serializer serializer = new DeliveryStreamDescription.Serializer();
serializer.setParquetSerDe(parquet);
DeliveryStreamDescription.OutputFormatConfiguration output =
new DeliveryStreamDescription.OutputFormatConfiguration();
output.setSerializer(serializer);
DeliveryStreamDescription.DataFormatConversionConfiguration conversion =
new DeliveryStreamDescription.DataFormatConversionConfiguration();
conversion.setOutputFormatConfiguration(output);
S3Destination config = new S3Destination();
config.setDataFormatConversionConfiguration(conversion);
return config;
}
@Test
void wireShapeAcceptsParquetSerDeAtItsExactBounds() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setBlockSizeBytes(67108864L);
parquet.setPageSizeBytes(65536L);
parquet.setCompression("SNAPPY");
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withParquetSerDe(parquet), "extendedS3DestinationConfiguration"));
}
/** Both bounds violated at once join into one message, as probed against real AWS. */
@Test
void wireShapeJoinsBothParquetBoundViolationsIntoOneError() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setBlockSizeBytes(1L);
parquet.setPageSizeBytes(1L);
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withParquetSerDe(parquet), "extendedS3DestinationConfiguration"));
assertEquals("ValidationException", error.getErrorCode());
assertEquals("2 validation errors detected: "
+ "Value at '" + PARQUET_PATH + ".blockSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 67108864; "
+ "Value at '" + PARQUET_PATH + ".pageSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 65536", error.getMessage());
}
@Test
void wireShapeRejectsNegativeMaxPaddingBytes() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setMaxPaddingBytes(-1L);
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withParquetSerDe(parquet), "extendedS3DestinationConfiguration"));
assertEquals("1 validation error detected: Value at '" + PARQUET_PATH + ".maxPaddingBytes' "
+ "failed to satisfy constraint: Member must have value greater than or equal to 0",
error.getMessage());
parquet.setMaxPaddingBytes(0L);
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withParquetSerDe(parquet), "extendedS3DestinationConfiguration"));
}
@Test
void wireShapeRejectsWriterVersionOutsideTheEnum() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setWriterVersion("V3");
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withParquetSerDe(parquet), "extendedS3DestinationConfiguration"));
assertEquals("1 validation error detected: Value at '" + PARQUET_PATH + ".writerVersion' "
+ "failed to satisfy constraint: Member must satisfy enum value set: [V1, V2]",
error.getMessage());
}
/** The order AWS prints is neither declaration order nor alphabetical; it was probed. */
@Test
void allFiveParquetViolationsAreReportedInTheOrderAwsUses() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setMaxPaddingBytes(-1L);
parquet.setBlockSizeBytes(1L);
parquet.setPageSizeBytes(1L);
parquet.setCompression("ZSTD");
parquet.setWriterVersion("V3");
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withParquetSerDe(parquet), "extendedS3DestinationConfiguration"));
assertEquals("5 validation errors detected: "
+ "Value at '" + PARQUET_PATH + ".maxPaddingBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 0; "
+ "Value at '" + PARQUET_PATH + ".blockSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 67108864; "
+ "Value at '" + PARQUET_PATH + ".pageSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 65536; "
+ "Value at '" + PARQUET_PATH + ".compression' failed to satisfy constraint: "
+ "Member must satisfy enum value set: [SNAPPY, GZIP, UNCOMPRESSED]; "
+ "Value at '" + PARQUET_PATH + ".writerVersion' failed to satisfy constraint: "
+ "Member must satisfy enum value set: [V1, V2]", error.getMessage());
}
private static final String ORC_PATH = "extendedS3DestinationConfiguration"
+ ".dataFormatConversionConfiguration.outputFormatConfiguration.serializer.orcSerDe";
private static S3Destination withOrcSerDe(DeliveryStreamDescription.OrcSerDe orc) {
DeliveryStreamDescription.Serializer serializer = new DeliveryStreamDescription.Serializer();
serializer.setOrcSerDe(orc);
DeliveryStreamDescription.OutputFormatConfiguration output =
new DeliveryStreamDescription.OutputFormatConfiguration();
output.setSerializer(serializer);
DeliveryStreamDescription.DataFormatConversionConfiguration conversion =
new DeliveryStreamDescription.DataFormatConversionConfiguration();
conversion.setOutputFormatConfiguration(output);
S3Destination config = new S3Destination();
config.setDataFormatConversionConfiguration(conversion);
return config;
}
@Test
void wireShapeAcceptsOrcSerDeAtItsExactBounds() {
DeliveryStreamDescription.OrcSerDe orc = new DeliveryStreamDescription.OrcSerDe();
orc.setBlockSizeBytes(67108864L);
orc.setStripeSizeBytes(8388608L);
orc.setRowIndexStride(1000);
orc.setPaddingTolerance(0.0);
orc.setDictionaryKeyThreshold(1.0);
orc.setBloomFilterFalsePositiveProbability(0.0);
orc.setCompression("NONE");
orc.setFormatVersion("V0_12");
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withOrcSerDe(orc), "extendedS3DestinationConfiguration"));
}
/** Order and enum spellings probed with all eight violated in one request. */
@Test
void allEightOrcViolationsAreReportedInTheOrderAwsUses() {
DeliveryStreamDescription.OrcSerDe orc = new DeliveryStreamDescription.OrcSerDe();
orc.setStripeSizeBytes(1L);
orc.setBlockSizeBytes(1L);
orc.setRowIndexStride(1);
orc.setPaddingTolerance(-1.0);
orc.setCompression("ZSTD");
orc.setBloomFilterFalsePositiveProbability(2.0);
orc.setDictionaryKeyThreshold(2.0);
orc.setFormatVersion("V0_10");
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withOrcSerDe(orc), "extendedS3DestinationConfiguration"));
assertEquals("8 validation errors detected: "
+ "Value at '" + ORC_PATH + ".dictionaryKeyThreshold' failed to satisfy constraint: "
+ "Member must have value less than or equal to 1; "
+ "Value at '" + ORC_PATH + ".blockSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 67108864; "
+ "Value at '" + ORC_PATH + ".rowIndexStride' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 1000; "
+ "Value at '" + ORC_PATH + ".paddingTolerance' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 0; "
+ "Value at '" + ORC_PATH + ".stripeSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 8388608; "
+ "Value at '" + ORC_PATH + ".compression' failed to satisfy constraint: "
+ "Member must satisfy enum value set: [ZLIB, SNAPPY, NONE]; "
+ "Value at '" + ORC_PATH + ".formatVersion' failed to satisfy constraint: "
+ "Member must satisfy enum value set: [V0_11, V0_12]; "
+ "Value at '" + ORC_PATH + ".bloomFilterFalsePositiveProbability' failed to satisfy constraint: "
+ "Member must have value less than or equal to 1", error.getMessage());
}
/** PaddingTolerance is bounded on both sides, like the two probabilities. */
@Test
void orcPaddingToleranceRejectsValuesAboveOne() {
DeliveryStreamDescription.OrcSerDe orc = new DeliveryStreamDescription.OrcSerDe();
orc.setPaddingTolerance(999.0);
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withOrcSerDe(orc), "extendedS3DestinationConfiguration"));
assertEquals("1 validation error detected: Value at '" + ORC_PATH + ".paddingTolerance' "
+ "failed to satisfy constraint: Member must have value less than or equal to 1",
error.getMessage());
orc.setPaddingTolerance(1.0);
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withOrcSerDe(orc), "extendedS3DestinationConfiguration"));
}
@Test
void orcProbabilitiesReportTheBoundThatWasCrossed() {
DeliveryStreamDescription.OrcSerDe orc = new DeliveryStreamDescription.OrcSerDe();
orc.setDictionaryKeyThreshold(-1.0);
orc.setBloomFilterFalsePositiveProbability(-1.0);
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withOrcSerDe(orc), "extendedS3DestinationConfiguration"));
assertEquals("2 validation errors detected: "
+ "Value at '" + ORC_PATH + ".dictionaryKeyThreshold' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 0; "
+ "Value at '" + ORC_PATH + ".bloomFilterFalsePositiveProbability' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 0", error.getMessage());
}
/** Probed: a request carrying both serializers reports the Parquet violation first. */
@Test
void parquetViolationsPrecedeOrcOnesWhenBothSerializersAreSet() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setPageSizeBytes(1L);
DeliveryStreamDescription.OrcSerDe orc = new DeliveryStreamDescription.OrcSerDe();
orc.setRowIndexStride(1);
S3Destination config = withParquetSerDe(parquet);
config.getDataFormatConversionConfiguration().getOutputFormatConfiguration()
.getSerializer().setOrcSerDe(orc);
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
config, "extendedS3DestinationConfiguration"));
assertEquals("2 validation errors detected: "
+ "Value at '" + PARQUET_PATH + ".pageSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 65536; "
+ "Value at '" + ORC_PATH + ".rowIndexStride' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 1000", error.getMessage());
}
private static final String MAPPINGS_PATH = "extendedS3DestinationConfiguration"
+ ".dataFormatConversionConfiguration.inputFormatConfiguration.deserializer"
+ ".openXJsonSerDe.columnToJsonKeyMappings";
private static final String LENGTH_RULES = "[Member must have length less than or equal to 1024,"
+ " Member must have length greater than or equal to 1,"
+ " Member must satisfy regular expression pattern: ";
private static S3Destination withColumnMappings(java.util.Map<String, String> mappings) {
DeliveryStreamDescription.OpenXJsonSerDe openX = new DeliveryStreamDescription.OpenXJsonSerDe();
openX.setColumnToJsonKeyMappings(mappings);
DeliveryStreamDescription.Deserializer deserializer = new DeliveryStreamDescription.Deserializer();
deserializer.setOpenXJsonSerDe(openX);
DeliveryStreamDescription.InputFormatConfiguration input =
new DeliveryStreamDescription.InputFormatConfiguration();
input.setDeserializer(deserializer);
DeliveryStreamDescription.DataFormatConversionConfiguration conversion =
new DeliveryStreamDescription.DataFormatConversionConfiguration();
conversion.setInputFormatConfiguration(input);
S3Destination config = new S3Destination();
config.setDataFormatConversionConfiguration(conversion);
return config;
}
@Test
void wireShapeAcceptsWellFormedColumnMappings() {
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("ticker", "sym", "price", "unit price")),
"extendedS3DestinationConfiguration"));
}
/** Probed: keys may hold no whitespace, while values merely may not be blank. */
@Test
void mappingKeysRejectWhitespaceButValuesOnlyRejectBlanks() {
AwsException keyError = assertThrows(AwsException.class,
() -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("has space", "v")),
"extendedS3DestinationConfiguration"));
assertEquals("1 validation error detected: Value at '" + MAPPINGS_PATH + "' failed to satisfy "
+ "constraint: Map keys must satisfy constraint: " + LENGTH_RULES + "^\\S+$]",
keyError.getMessage());
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("ticker", "has space")),
"extendedS3DestinationConfiguration"));
AwsException valueError = assertThrows(AwsException.class,
() -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("ticker", " ")),
"extendedS3DestinationConfiguration"));
assertEquals("1 validation error detected: Value at '" + MAPPINGS_PATH + "' failed to satisfy "
+ "constraint: Map value must satisfy constraint: " + LENGTH_RULES + "^(?!\\s*$).+]",
valueError.getMessage());
}
/** However many entries break the rule, AWS reports keys once and values once. */
@Test
void mappingViolationsAreReportedOncePerAspectWithKeysFirst() {
java.util.Map<String, String> mappings = new java.util.LinkedHashMap<>();
mappings.put("has space", "");
mappings.put("also space", " ");
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withColumnMappings(mappings), "extendedS3DestinationConfiguration"));
assertEquals("2 validation errors detected: "
+ "Value at '" + MAPPINGS_PATH + "' failed to satisfy constraint: "
+ "Map keys must satisfy constraint: " + LENGTH_RULES + "^\\S+$]; "
+ "Value at '" + MAPPINGS_PATH + "' failed to satisfy constraint: "
+ "Map value must satisfy constraint: " + LENGTH_RULES + "^(?!\\s*$).+]",
error.getMessage());
}
/**
* The value rule is the pattern itself, not a String.isBlank() approximation:
* probed against AWS, which accepts an ideographic space here (its own later
* SerDe check is what rejects that, a deviation Floci documents) and rejects any
* value holding a line break, while isBlank() gets both backwards. A no-break
* space is not whitespace to either rule, so a key may hold one.
*/
@Test
void mappingValuesFollowTheDeclaredPatternRatherThanIsBlank() {
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("ticker", " ")),
"extendedS3DestinationConfiguration"));
assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("ticker", "a\nb")),
"extendedS3DestinationConfiguration"));
assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("ticker", "ab\n")),
"extendedS3DestinationConfiguration"));
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("a b", "v")),
"extendedS3DestinationConfiguration"));
assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("a\nb", "v")),
"extendedS3DestinationConfiguration"));
}
@Test
void mappingLengthsAreBoundedAt1024() {
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("k".repeat(1024), "v".repeat(1024))),
"extendedS3DestinationConfiguration"));
assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withColumnMappings(java.util.Map.of("k".repeat(1025), "v")),
"extendedS3DestinationConfiguration"));
}
/** Probed: the deserializer's violations are printed after the serializer's. */
@Test
void serializerViolationsPrecedeDeserializerOnes() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setPageSizeBytes(1L);
S3Destination config = withParquetSerDe(parquet);
DeliveryStreamDescription.OpenXJsonSerDe openX = new DeliveryStreamDescription.OpenXJsonSerDe();
openX.setColumnToJsonKeyMappings(java.util.Map.of("has space", "v"));
DeliveryStreamDescription.Deserializer deserializer = new DeliveryStreamDescription.Deserializer();
deserializer.setOpenXJsonSerDe(openX);
DeliveryStreamDescription.InputFormatConfiguration input =
new DeliveryStreamDescription.InputFormatConfiguration();
input.setDeserializer(deserializer);
config.getDataFormatConversionConfiguration().setInputFormatConfiguration(input);
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
config, "extendedS3DestinationConfiguration"));
assertEquals("2 validation errors detected: "
+ "Value at '" + PARQUET_PATH + ".pageSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 65536; "
+ "Value at '" + MAPPINGS_PATH + "' failed to satisfy constraint: "
+ "Map keys must satisfy constraint: " + LENGTH_RULES + "^\\S+$]", error.getMessage());
}
private static final String SCHEMA_PATH = "extendedS3DestinationConfiguration"
+ ".dataFormatConversionConfiguration.schemaConfiguration";
private static S3Destination withSchema(DeliveryStreamDescription.SchemaConfiguration schema) {
DeliveryStreamDescription.DataFormatConversionConfiguration conversion =
new DeliveryStreamDescription.DataFormatConversionConfiguration();
conversion.setSchemaConfiguration(schema);
S3Destination config = new S3Destination();
config.setDataFormatConversionConfiguration(conversion);
return config;
}
/** Unlike the collection members, each broken schema rule is its own violation. */
@Test
void emptySchemaMemberReportsBothItsLengthAndItsPatternViolation() {
DeliveryStreamDescription.SchemaConfiguration schema =
new DeliveryStreamDescription.SchemaConfiguration();
schema.setCatalogId("");
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withSchema(schema), "extendedS3DestinationConfiguration"));
assertEquals("2 validation errors detected: "
+ "Value at '" + SCHEMA_PATH + ".catalogId' failed to satisfy constraint: "
+ "Member must have length greater than or equal to 1; "
+ "Value at '" + SCHEMA_PATH + ".catalogId' failed to satisfy constraint: "
+ "Member must satisfy regular expression pattern: ^\\S+$", error.getMessage());
}
/**
* Probed: an empty role ARN trips the same length and pattern rules as the other
* members, reported under a path that keeps ARN capitalised. A malformed but
* non-empty one never reaches them on AWS, which answers InvalidParameterValueException
* first; Floci validates no ARNs, so it accepts that case.
*/
@Test
void emptySchemaRoleArnIsReportedUnderTheRoleArnPath() {
DeliveryStreamDescription.SchemaConfiguration schema =
new DeliveryStreamDescription.SchemaConfiguration();
schema.setRoleArn("");
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withSchema(schema), "extendedS3DestinationConfiguration"));
assertEquals("2 validation errors detected: "
+ "Value at '" + SCHEMA_PATH + ".roleARN' failed to satisfy constraint: "
+ "Member must have length greater than or equal to 1; "
+ "Value at '" + SCHEMA_PATH + ".roleARN' failed to satisfy constraint: "
+ "Member must satisfy regular expression pattern: ^\\S+$", error.getMessage());
schema.setRoleArn("arn:aws:iam::000000000000:role/firehose-role");
assertDoesNotThrow(() -> S3DestinationValidator.validateWireShape(
withSchema(schema), "extendedS3DestinationConfiguration"));
}
@Test
void schemaMembersAreReportedInTheOrderAwsUses() {
DeliveryStreamDescription.SchemaConfiguration schema =
new DeliveryStreamDescription.SchemaConfiguration();
schema.setCatalogId("c d");
schema.setDatabaseName("e f");
schema.setTableName("g h");
schema.setRegion("i j");
schema.setVersionId("k l");
schema.setRoleArn("m n");
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withSchema(schema), "extendedS3DestinationConfiguration"));
String pattern = "' failed to satisfy constraint: Member must satisfy regular expression pattern: ^\\S+$";
assertEquals("6 validation errors detected: "
+ "Value at '" + SCHEMA_PATH + ".versionId" + pattern + "; "
+ "Value at '" + SCHEMA_PATH + ".catalogId" + pattern + "; "
+ "Value at '" + SCHEMA_PATH + ".databaseName" + pattern + "; "
+ "Value at '" + SCHEMA_PATH + ".roleARN" + pattern + "; "
+ "Value at '" + SCHEMA_PATH + ".region" + pattern + "; "
+ "Value at '" + SCHEMA_PATH + ".tableName" + pattern, error.getMessage());
}
@Test
void schemaMembersAreBoundedAt1024() {
DeliveryStreamDescription.SchemaConfiguration schema =
new DeliveryStreamDescription.SchemaConfiguration();
schema.setCatalogId("x".repeat(1100));
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withSchema(schema), "extendedS3DestinationConfiguration"));
assertEquals("1 validation error detected: Value at '" + SCHEMA_PATH + ".catalogId' "
+ "failed to satisfy constraint: Member must have length less than or equal to 1024",
error.getMessage());
}
/** Probed: schema violations are printed after the serializer's and deserializer's. */
@Test
void schemaViolationsComeLast() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setPageSizeBytes(1L);
S3Destination config = withParquetSerDe(parquet);
DeliveryStreamDescription.SchemaConfiguration schema =
new DeliveryStreamDescription.SchemaConfiguration();
schema.setTableName("g h");
config.getDataFormatConversionConfiguration().setSchemaConfiguration(schema);
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
config, "extendedS3DestinationConfiguration"));
assertEquals("2 validation errors detected: "
+ "Value at '" + PARQUET_PATH + ".pageSizeBytes' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 65536; "
+ "Value at '" + SCHEMA_PATH + ".tableName' failed to satisfy constraint: "
+ "Member must satisfy regular expression pattern: ^\\S+$", error.getMessage());
}
/** NaN satisfies no comparison, so AWS reports both bounds; each infinity trips one. */
@Test
void nonFiniteProportionsReportTheBoundsAwsReports() {
DeliveryStreamDescription.OrcSerDe nan = new DeliveryStreamDescription.OrcSerDe();
nan.setDictionaryKeyThreshold(Double.NaN);
AwsException nanError = assertThrows(AwsException.class,
() -> S3DestinationValidator.validateWireShape(
withOrcSerDe(nan), "extendedS3DestinationConfiguration"));
assertEquals("2 validation errors detected: "
+ "Value at '" + ORC_PATH + ".dictionaryKeyThreshold' failed to satisfy constraint: "
+ "Member must have value less than or equal to 1; "
+ "Value at '" + ORC_PATH + ".dictionaryKeyThreshold' failed to satisfy constraint: "
+ "Member must have value greater than or equal to 0", nanError.getMessage());
DeliveryStreamDescription.OrcSerDe positiveInfinity = new DeliveryStreamDescription.OrcSerDe();
positiveInfinity.setDictionaryKeyThreshold(Double.POSITIVE_INFINITY);
assertEquals("1 validation error detected: Value at '" + ORC_PATH + ".dictionaryKeyThreshold' "
+ "failed to satisfy constraint: Member must have value less than or equal to 1",
assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withOrcSerDe(positiveInfinity), "extendedS3DestinationConfiguration")).getMessage());
DeliveryStreamDescription.OrcSerDe negativeInfinity = new DeliveryStreamDescription.OrcSerDe();
negativeInfinity.setDictionaryKeyThreshold(Double.NEGATIVE_INFINITY);
assertEquals("1 validation error detected: Value at '" + ORC_PATH + ".dictionaryKeyThreshold' "
+ "failed to satisfy constraint: Member must have value greater than or equal to 0",
assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withOrcSerDe(negativeInfinity), "extendedS3DestinationConfiguration")).getMessage());
}
@Test
void wireShapeRejectsParquetCompressionOutsideTheEnum() {
DeliveryStreamDescription.ParquetSerDe parquet = new DeliveryStreamDescription.ParquetSerDe();
parquet.setCompression("ZSTD");
AwsException error = assertThrows(AwsException.class, () -> S3DestinationValidator.validateWireShape(
withParquetSerDe(parquet), "extendedS3DestinationConfiguration"));
assertEquals("1 validation error detected: Value at '" + PARQUET_PATH + ".compression' "
+ "failed to satisfy constraint: Member must satisfy enum value set: [SNAPPY, GZIP, UNCOMPRESSED]",
error.getMessage());
}
}