Skip to content

Commit

Permalink
Fixed s3 sink config validation (#5063)
Browse files Browse the repository at this point in the history
* Fixed s3 sink config validation

Signed-off-by: Krishna Kondaka <[email protected]>

* Added test cases

Signed-off-by: Krishna Kondaka <[email protected]>

---------

Signed-off-by: Krishna Kondaka <[email protected]>
Co-authored-by: Krishna Kondaka <[email protected]>
  • Loading branch information
kkondaka and Krishna Kondaka authored Oct 15, 2024
1 parent 842c066 commit 47fdbda
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
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());
}
}
}

0 comments on commit 47fdbda

Please sign in to comment.