singhpk234 commented on a change in pull request #4239:
URL: https://github.com/apache/iceberg/pull/4239#discussion_r816438790



##########
File path: aws/src/test/java/org/apache/iceberg/aws/TestAwsClientFactories.java
##########
@@ -79,8 +83,33 @@ public void testS3FileIoCredentialsVerification() {
     properties.put(AwsProperties.S3FILEIO_SECRET_ACCESS_KEY, "secret");
     AssertHelpers.assertThrows("Should fail if only secret access key is set",
         ValidationException.class,
-        "S3 client access key ID and secret access key must be set at the same 
time",
-        () -> AwsClientFactories.from(properties));
+            "S3 client access key ID and secret access key must be set at the 
same time",
+            () -> AwsClientFactories.from(properties));

Review comment:
       [nit] is the change intentional ? 

##########
File path: aws/src/main/java/org/apache/iceberg/aws/BaseAwsClientFactory.java
##########
@@ -0,0 +1,65 @@
+/*
+ * 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;
+
+import java.util.Map;
+import org.apache.iceberg.TableProperties;
+import org.apache.iceberg.exceptions.ValidationException;
+import org.apache.iceberg.util.PropertyUtil;
+import software.amazon.awssdk.http.SdkHttpClient;
+import software.amazon.awssdk.http.apache.ApacheHttpClient;
+import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
+
+abstract class BaseAwsClientFactory implements AwsClientFactory {
+  private String httpClientConfig;
+
+  /**
+   * Set http client config from properties map
+   *
+   * @param properties catalog properties
+   */
+  protected void setHttpClientConfig(Map<String, String> properties) {
+    httpClientConfig = PropertyUtil.propertyAsString(
+        properties, TableProperties.HTTP_CLIENT_TYPE, 
TableProperties.HTTP_CLIENT_TYPE_DEFAULT);
+
+    ValidationException.check(
+        (httpClientConfig.equalsIgnoreCase(TableProperties.URL_HTTP_CLIENT) ||
+            
httpClientConfig.equalsIgnoreCase(TableProperties.APACHE_HTTP_CLIENT)),
+        "HTTP client can be either url or apache");
+  }
+
+  /**
+   * Create a http client builder based on client config
+   */
+  public SdkHttpClient.Builder getHttpClientBuilder() {
+    if 
(getHttpClientConfig().equalsIgnoreCase(TableProperties.APACHE_HTTP_CLIENT)) {
+      return ApacheHttpClient.builder();
+    } else {
+      return UrlConnectionHttpClient.builder();
+    }

Review comment:
       [question] This being a public method should we also check if 
`getHttpClientConfig()` is NotNull it may happen before setting the HTTP config 
i tried to access it ... WDYT ? 

##########
File path: aws/src/test/java/org/apache/iceberg/aws/TestAwsClientFactories.java
##########
@@ -79,8 +83,33 @@ public void testS3FileIoCredentialsVerification() {
     properties.put(AwsProperties.S3FILEIO_SECRET_ACCESS_KEY, "secret");
     AssertHelpers.assertThrows("Should fail if only secret access key is set",
         ValidationException.class,
-        "S3 client access key ID and secret access key must be set at the same 
time",
-        () -> AwsClientFactories.from(properties));
+            "S3 client access key ID and secret access key must be set at the 
same time",
+            () -> AwsClientFactories.from(properties));
+  }
+
+  @Test
+  public void testHttpClientConfig() {
+    Map<String, String> properties = Maps.newHashMap();
+    properties.put(TableProperties.HTTP_CLIENT_TYPE, 
TableProperties.URL_HTTP_CLIENT);
+    AwsClientFactory awsClientFactory = AwsClientFactories.from(properties);
+    Assert.assertEquals(TableProperties.URL_HTTP_CLIENT, 
awsClientFactory.getHttpClientConfig());
+    Assert.assertTrue(awsClientFactory.getHttpClientBuilder() instanceof 
UrlConnectionHttpClient.Builder);
+
+    properties = Maps.newHashMap();
+    properties.put(TableProperties.HTTP_CLIENT_TYPE, 
TableProperties.APACHE_HTTP_CLIENT);
+    awsClientFactory = AwsClientFactories.from(properties);
+    Assert.assertEquals(TableProperties.APACHE_HTTP_CLIENT, 
awsClientFactory.getHttpClientConfig());
+    Assert.assertTrue(awsClientFactory.getHttpClientBuilder() instanceof 
ApacheHttpClient.Builder);

Review comment:
       [minor] To avoid some of this duplication can we create a private func 
for asserting something like below : 
   ```java
     @Test
     public void testHttpClientConfig() {
       assertHttpClient(TableProperties.URL_HTTP_CLIENT, 
UrlConnectionHttpClient.Builder.class);
       assertHttpClient(TableProperties.APACHE_HTTP_CLIENT, 
ApacheHttpClient.Builder.class);
     }
   
     private void assertHttpClient(String httpClient, Class<? extends 
SdkHttpClient.Builder> expectedBuilder) {
       Map<String, String> properties = Maps.newHashMap();
       properties.put(TableProperties.HTTP_CLIENT_TYPE, httpClient);
       AwsClientFactory awsClientFactory = AwsClientFactories.from(properties);
       Assert.assertEquals(httpClient, awsClientFactory.getHttpClientConfig());
       
Assertions.assertThat(awsClientFactory.getHttpClientBuilder()).isInstanceOf(expectedBuilder);
     }
   ```
   
   WDYT ? 




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