Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.10] Fixed s3 sink config validation #5067

Merged
merged 1 commit into from
Oct 15, 2024
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 @@ -50,9 +50,9 @@ public class S3SinkConfig {
private ObjectMetadataConfig objectMetadataConfig;

@AssertTrue(message = "Only one of object_metadata and predefined_object_metadata can be used.")
private boolean isValidMetadataConfig() {
return (objectMetadataConfig != null && predefinedObjectMetadata == null) ||
(objectMetadataConfig == null && predefinedObjectMetadata != null);
boolean isValidMetadataConfig() {
// One of them or both should be null
return (objectMetadataConfig == null || predefinedObjectMetadata == null);
}

@AssertTrue(message = "You may not use both bucket and bucket_selector together in one S3 sink.")
Expand Down Expand Up @@ -151,8 +151,8 @@ public ObjectKeyOptions getObjectKeyOptions() {
return objectKeyOptions;
}

public ObjectMetadataConfig getObjectMetadataConfig() {
return objectMetadataConfig;
public Object getObjectMetadataConfig() {
return objectMetadataConfig != null ? objectMetadataConfig : predefinedObjectMetadata;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,39 @@ void get_bucket_name_with_s3_prefix_test() throws NoSuchFieldException, IllegalA
assertThat(objectUnderTest.getBucketName(), equalTo(bucketName));
}

@Test
void test_default_metadata_config() throws NoSuchFieldException, IllegalAccessException {
final String bucketName = UUID.randomUUID().toString();
final String bucketNameWithPrefix = S3_PREFIX + bucketName;
final S3SinkConfig objectUnderTest = new S3SinkConfig();
assertThat(objectUnderTest.isValidMetadataConfig(), equalTo(true));
assertThat(objectUnderTest.getObjectMetadataConfig(), equalTo(null));
}

@Test
void test_object_metadata_config() throws NoSuchFieldException, IllegalAccessException {
final String bucketName = UUID.randomUUID().toString();
final String bucketNameWithPrefix = S3_PREFIX + bucketName;
final S3SinkConfig objectUnderTest = new S3SinkConfig();

ObjectMetadataConfig objectMetadataConfig = new ObjectMetadataConfig();
ReflectivelySetField.setField(S3SinkConfig.class, objectUnderTest, "objectMetadataConfig", objectMetadataConfig);
assertThat(objectUnderTest.isValidMetadataConfig(), equalTo(true));
assertThat(objectUnderTest.getObjectMetadataConfig(), equalTo(objectMetadataConfig));
}

@Test
void test_predefined_metadata_config() throws NoSuchFieldException, IllegalAccessException {
final String bucketName = UUID.randomUUID().toString();
final String bucketNameWithPrefix = S3_PREFIX + bucketName;
final S3SinkConfig objectUnderTest = new S3SinkConfig();

PredefinedObjectMetadata objectMetadataConfig = new PredefinedObjectMetadata();
ReflectivelySetField.setField(S3SinkConfig.class, objectUnderTest, "predefinedObjectMetadata", objectMetadataConfig);
assertThat(objectUnderTest.isValidMetadataConfig(), equalTo(true));
assertThat(objectUnderTest.getObjectMetadataConfig(), equalTo(objectMetadataConfig));
}

@Test
void get_object_key_test() {
assertThat("Object key is not an instance of ObjectKeyOptions",
Expand All @@ -81,4 +114,4 @@ void get_json_codec_test() {
void get_client_option_test() {
assertNull(new S3SinkConfig().getClientOptions());
}
}
}
Loading