Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.util.Map;
import java.util.Collection;

@Experimental
Expand All @@ -60,16 +59,12 @@ public SqsSink(final PluginSetting pluginSetting,
sinkInitialized = false;
final PluginModel codecConfiguration = sqsSinkConfig.getCodec();
final PluginSetting codecPluginSettings;
if (codecConfiguration != null) {
String codecPluginName = codecConfiguration.getPluginName();
if (!codecPluginName.equals("json") && !codecPluginName.equals("ndjson")) {
throw new RuntimeException(String.format("Codec {} not supported.", codecPluginName));
}
codecPluginSettings = new PluginSetting(codecConfiguration.getPluginName(),
codecConfiguration.getPluginSettings());
} else {
codecPluginSettings = new PluginSetting("ndjson", Map.of());
String codecPluginName = codecConfiguration.getPluginName();
if (!codecPluginName.equals("json") && !codecPluginName.equals("ndjson")) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should allow for other codecs. I think the only time we want to be restrictive on the codec is when the customer is not using batching (ie. max_events_per_batch == 1). In that case, ndjson should be the only permissible codec.

Customers may want to serialize in Ion, XML, or other codecs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear why the codecs are so limited here

throw new RuntimeException(String.format("Codec {} not supported.", codecPluginName));
}
codecPluginSettings = new PluginSetting(codecConfiguration.getPluginName(),
codecConfiguration.getPluginSettings());

AwsConfig awsConfig = sqsSinkConfig.getAwsConfig();
final AwsCredentialsProvider awsCredentialsProvider = (awsConfig != null) ? awsCredentialsSupplier.getProvider(convertToCredentialOptions(awsConfig)) : awsCredentialsSupplier.getProvider(AwsCredentialsOptions.builder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class SqsSinkConfig {
private String queueUrl;

@JsonProperty("codec")
@NotNull
private PluginModel codec;

@JsonProperty("threshold")
Expand Down Expand Up @@ -67,12 +68,5 @@ boolean isValidConfig() {
return (groupId == null && deDupId == null);
}
}

@AssertTrue(message = "ndjson codec (default codec) doesn't support max events per message greater than 1")
boolean isValidCodecConfig() {
if ((codec == null || codec.getPluginName().equals("ndjson")) && thresholdConfig.getMaxEventsPerMessage() > 1)
return false;
return true;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void TestDefaultConfig() {
}

@Test
private void TestCustomConfig() throws Exception {
void TestCustomConfig() throws Exception {
AwsConfig awsConfig = mock(AwsConfig.class);
reflectivelySetField(sqsSinkConfig, "awsConfig", awsConfig);
assertThat(sqsSinkConfig.getAwsConfig(), equalTo(awsConfig));
Expand Down Expand Up @@ -114,21 +114,6 @@ void TestValidFiFoQConfigs() throws Exception {

}

@Test
void TestValidCodecConfig() throws Exception {
reflectivelySetField(sqsSinkConfig, "codec", null);
reflectivelySetField(sqsSinkConfig, "thresholdConfig", sqsThresholdConfig);
when(sqsThresholdConfig.getMaxEventsPerMessage()).thenReturn(2);
assertFalse(sqsSinkConfig.isValidCodecConfig());
when(sqsThresholdConfig.getMaxEventsPerMessage()).thenReturn(1);
assertTrue(sqsSinkConfig.isValidCodecConfig());
PluginModel codec = mock(PluginModel.class);
when(codec.getPluginName()).thenReturn("ndjson");
reflectivelySetField(sqsSinkConfig, "codec", codec);
when(sqsThresholdConfig.getMaxEventsPerMessage()).thenReturn(2);
assertFalse(sqsSinkConfig.isValidCodecConfig());
}

private void reflectivelySetField(final SqsSinkConfig sqsSinkConfig, final String fieldName, final Object value) throws NoSuchFieldException, IllegalAccessException {
final Field field = SqsSinkConfig.class.getDeclaredField(fieldName);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,6 @@ void TestForDefaultCodec() {
}
}

@Test
void TestForNullCodec() {
when(sqsSinkConfig.getCodec()).thenReturn(null);
try(MockedStatic<SqsClientFactory> mockedStatic = mockStatic(SqsClientFactory.class)) {
mockedStatic.when(() -> SqsClientFactory.createSqsClient(any(Region.class),
any(AwsCredentialsProvider.class)))
.thenReturn(sqsClient);

SqsSink sqsSink = createObjectUnderTest();
sqsSink.doInitialize();
assertTrue(sqsSink.isReady());
}
}

@Test
void TestSinkOutputWithEvents() {
try(MockedStatic<SqsClientFactory> mockedStatic = mockStatic(SqsClientFactory.class)) {
Expand Down
Loading