anuragmantri commented on code in PR #18919:
URL: https://github.com/apache/iceberg/pull/18919#discussion_r4556738327


##########
aws/src/test/java/org/apache/iceberg/aws/s3/TestS3FileIOClientFactory.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.aws.s3;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.iceberg.TestHelpers;
+import org.apache.iceberg.aws.AwsClientFactory;
+import org.apache.iceberg.aws.AwsProperties;
+import org.apache.iceberg.io.StorageCredential;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.mockito.Mockito;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.services.glue.GlueClient;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3Client;
+
+class TestS3FileIOClientFactory {
+
+  private static final AtomicInteger INITIALIZED = new AtomicInteger();
+  private static final AtomicInteger S3_CREATED = new AtomicInteger();
+
+  @BeforeEach
+  void resetCounts() {
+    INITIALIZED.set(0);
+    S3_CREATED.set(0);
+  }
+
+  private static Map<String, String> properties(Class<?> factoryClass) {
+    String factoryProperty =
+        AwsClientFactory.class.isAssignableFrom(factoryClass)
+            ? AwsProperties.CLIENT_FACTORY
+            : S3FileIOProperties.CLIENT_FACTORY;
+    return ImmutableMap.of(factoryProperty, factoryClass.getName());
+  }
+
+  @ParameterizedTest
+  @ValueSource(classes = {CountingS3FileIOClientFactory.class, 
CountingAwsClientFactory.class})
+  void rootClientsUseFactoryFromInitialize(Class<?> factoryClass) {
+    try (S3FileIO fileIO = new S3FileIO()) {
+      fileIO.initialize(properties(factoryClass));
+      assertThat(fileIO.client()).isNotNull();
+      assertThat(fileIO.asyncClient()).isNotNull();
+      assertThat(INITIALIZED).hasValue(1);
+    }
+  }
+
+  @ParameterizedTest
+  @MethodSource("org.apache.iceberg.TestHelpers#serializers")
+  void deserializedRootClientsUseFactoryFromInitialize(

Review Comment:
   `CountingAwsClientFactory` has no fields, so this doesn't test serializing 
the default factories. Could you add a round trip test with no client factory 
and `AwsClientProperties.CLIENT_REGION` set, then check `client()` and 
`asyncClient()` on the result? 



##########
aws/src/test/java/org/apache/iceberg/aws/s3/TestS3FileIOClientFactory.java:
##########
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.aws.s3;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.iceberg.TestHelpers;
+import org.apache.iceberg.aws.AwsClientFactory;
+import org.apache.iceberg.aws.AwsProperties;
+import org.apache.iceberg.io.StorageCredential;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.provider.ValueSource;
+import org.mockito.Mockito;
+import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
+import software.amazon.awssdk.services.glue.GlueClient;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3Client;
+
+class TestS3FileIOClientFactory {
+
+  private static final AtomicInteger INITIALIZED = new AtomicInteger();
+  private static final AtomicInteger S3_CREATED = new AtomicInteger();
+
+  @BeforeEach
+  void resetCounts() {
+    INITIALIZED.set(0);
+    S3_CREATED.set(0);
+  }
+
+  private static Map<String, String> properties(Class<?> factoryClass) {
+    String factoryProperty =
+        AwsClientFactory.class.isAssignableFrom(factoryClass)
+            ? AwsProperties.CLIENT_FACTORY
+            : S3FileIOProperties.CLIENT_FACTORY;
+    return ImmutableMap.of(factoryProperty, factoryClass.getName());
+  }
+
+  @ParameterizedTest
+  @ValueSource(classes = {CountingS3FileIOClientFactory.class, 
CountingAwsClientFactory.class})
+  void rootClientsUseFactoryFromInitialize(Class<?> factoryClass) {
+    try (S3FileIO fileIO = new S3FileIO()) {
+      fileIO.initialize(properties(factoryClass));
+      assertThat(fileIO.client()).isNotNull();
+      assertThat(fileIO.asyncClient()).isNotNull();
+      assertThat(INITIALIZED).hasValue(1);
+    }
+  }
+
+  @ParameterizedTest
+  @MethodSource("org.apache.iceberg.TestHelpers#serializers")
+  void deserializedRootClientsUseFactoryFromInitialize(
+      TestHelpers.RoundTripSerializer<S3FileIO> roundTripSerializer) throws 
Exception {
+    try (S3FileIO fileIO = new S3FileIO()) {
+      fileIO.initialize(properties(CountingAwsClientFactory.class));
+      try (S3FileIO deserialized = roundTripSerializer.apply(fileIO)) {
+        assertThat(deserialized.client()).isNotNull();
+        assertThat(deserialized.asyncClient()).isNotNull();
+      }
+    }
+
+    assertThat(INITIALIZED).hasValue(1);
+  }
+
+  @Test
+  void storageCredentialPrefixUsesOneFactoryForBothClients() {
+    String prefix = "s3://bucket/path";
+    try (S3FileIO fileIO = new S3FileIO()) {
+      fileIO.setCredentials(
+          ImmutableList.of(
+              StorageCredential.create(
+                  prefix,
+                  ImmutableMap.of(
+                      S3FileIOProperties.ACCESS_KEY_ID,
+                      "accessKey",
+                      S3FileIOProperties.SECRET_ACCESS_KEY,
+                      "secretKey"))));
+      fileIO.initialize(properties(CountingAwsClientFactory.class));
+      assertThat(fileIO.client(prefix + "/file")).isNotNull();
+      assertThat(fileIO.asyncClient(prefix + "/file")).isNotNull();
+      assertThat(INITIALIZED).hasValue(2);
+    }
+  }
+
+  @Test
+  void preloadCreatesRootClientFromFactoryFromInitialize() {

Review Comment:
   This seems very similar to  `rootClientsUseFactoryFromInitialize`? 
`S3_CREATED` is 1 with or without this change, so without the fix this test 
fails on `INITIALIZED`, same as this one. If I'm not missing anything we can 
probably drop this?



-- 
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]

Reply via email to