RussellSpitzer commented on code in PR #7066:
URL: https://github.com/apache/iceberg/pull/7066#discussion_r1143755441
##########
aws/src/test/java/org/apache/iceberg/aws/TestAwsClientFactories.java:
##########
@@ -132,6 +139,119 @@ public void
testLakeFormationAwsClientFactorySerializable() throws IOException {
.isInstanceOf(LakeFormationAwsClientFactory.class);
}
+ @Test
+ public void testDefaultAwsClientFactoryWithCredentialsProvider() {
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(AwsProperties.CLIENT_REGION, Region.AWS_GLOBAL.toString());
+ properties.put(
+ AwsProperties.CLIENT_CREDENTIALS_PROVIDER,
+ SystemPropertyCredentialsProvider.class.getName());
+
+ AwsClientFactory defaultAwsClientFactory =
AwsClientFactories.from(properties);
+ assertAwsClientFactory(defaultAwsClientFactory);
+ }
+
+ private void assertAwsClientFactory(AwsClientFactory
defaultAwsClientFactory) {
+ Assertions.assertThat(defaultAwsClientFactory)
+ .isInstanceOf(AwsClientFactories.DefaultAwsClientFactory.class);
+ try (S3Client s3Client = defaultAwsClientFactory.s3()) {
+ Assertions.assertThat(s3Client).isNotNull();
+ URL url =
+ s3Client
+ .utilities()
+
.getUrl(GetUrlRequest.builder().bucket("test-bucket").key("test-key").build());
+ Assertions.assertThat(url)
+ .isNotNull()
+ .hasToString("https://test-bucket.s3.amazonaws.com/test-key");
+ }
+ }
+
+ @Test
+ public void
+
testDefaultAwsClientFactoryWithCredentialsProviderAndCreateMethodWithCustomProperties()
{
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(AwsProperties.CLIENT_REGION, Region.AWS_GLOBAL.toString());
+ properties.put(
+ AwsProperties.CLIENT_CREDENTIALS_PROVIDER,
CustomCredentialsProvider.class.getName());
+ properties.put(AwsProperties.CLIENT_CREDENTIALS_PROVIDER + ".param1",
"value1");
+
+ AwsClientFactory defaultAwsClientFactory =
AwsClientFactories.from(properties);
+ assertAwsClientFactory(defaultAwsClientFactory);
+ }
+
+ @Test
+ public void testDefaultAwsClientFactoryWithInvalidCredentialsProvider() {
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(AwsProperties.CLIENT_REGION, Region.AWS_GLOBAL.toString());
+ properties.put(AwsProperties.CLIENT_CREDENTIALS_PROVIDER,
"invalidClassName");
+ Assertions.assertThatThrownBy(() ->
AwsClientFactories.from(properties).s3().close())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining(
+ "Cannot load class invalidClassName, it does not exist in the
classpath");
+ }
+
+ @Test
+ public void
testDefaultAwsClientFactoryWithInvalidCredentialsProviderWithValidClass() {
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(AwsProperties.CLIENT_REGION, Region.AWS_GLOBAL.toString());
+ properties.put(
+ AwsProperties.CLIENT_CREDENTIALS_PROVIDER,
+
InvalidNoInterfaceDynamicallyLoadedCredentialsProvider.class.getName());
+ Assertions.assertThatThrownBy(() ->
AwsClientFactories.from(properties).s3().close())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining(
+ "Cannot initialize
org.apache.iceberg.aws.TestAwsClientFactories$InvalidNoInterfaceDynamicallyLoadedCredentialsProvider,
it does not implement
software.amazon.awssdk.auth.credentials.AwsCredentialsProvider");
+ }
+
+ @Test
+ public void
testDefaultAwsClientFactoryCredentialsProviderWithNoCreateMethod() {
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(AwsProperties.CLIENT_REGION, Region.AWS_GLOBAL.toString());
+ properties.put(
+ AwsProperties.CLIENT_CREDENTIALS_PROVIDER,
+ CustomCredentialsProviderWithNoCreateMethod.class.getName());
+ Assertions.assertThatThrownBy(() ->
AwsClientFactories.from(properties).s3().close())
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessageContaining(
+ "Cannot create an instance of
org.apache.iceberg.aws.TestAwsClientFactories$CustomCredentialsProviderWithNoCreateMethod,
it does not contain a static 'create' or 'create(Map<String, String>)'
method");
+ }
+
+ // publicly visible for testing to be dynamically loaded
+ public static class InvalidNoInterfaceDynamicallyLoadedCredentialsProvider {
Review Comment:
I would probably call this public static class NoInterface { }, although you
probably don't need a custom class here since you can just pass a
java.lang.Object if you wanted. Either way I'd try to shorten the name a bit so
that the test is a bit easier to read.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]