echauchot commented on a change in pull request #16894:
URL: https://github.com/apache/beam/pull/16894#discussion_r813885700
##########
File path:
sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/common/ClientConfiguration.java
##########
@@ -47,18 +49,28 @@
* uses a backoff strategy with equal jitter for computing the delay before
the next retry.
*/
@AutoValue
+@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
+@JsonDeserialize(builder = ClientConfiguration.Builder.class)
Review comment:
I see, you serialize/deserialize `ClientConfiguration` using std Json
serializer by annoting the Builder raher than using a custom serializer. I like
this approach, I did something similar in MertricsPusher sinks.
##########
File path:
sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/common/ClientConfiguration.java
##########
@@ -47,18 +49,28 @@
* uses a backoff strategy with equal jitter for computing the delay before
the next retry.
*/
@AutoValue
+@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
+@JsonDeserialize(builder = ClientConfiguration.Builder.class)
public abstract class ClientConfiguration implements Serializable {
/**
* Optional {@link AwsCredentialsProvider}. If set, this overwrites the
default in {@link
* AwsOptions#getAwsCredentialsProvider()}.
*/
- public abstract @Nullable @Pure AwsCredentialsProvider credentialsProvider();
+ @JsonProperty
+ @Memoized
Review comment:
good to cache the AwsCredentialsProvider even if it avoids only calling
a getter 1+ and a comparison
##########
File path:
sdks/java/io/amazon-web-services2/src/main/java/org/apache/beam/sdk/io/aws2/common/ClientConfiguration.java
##########
@@ -47,18 +49,28 @@
* uses a backoff strategy with equal jitter for computing the delay before
the next retry.
*/
@AutoValue
+@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
+@JsonDeserialize(builder = ClientConfiguration.Builder.class)
public abstract class ClientConfiguration implements Serializable {
/**
* Optional {@link AwsCredentialsProvider}. If set, this overwrites the
default in {@link
* AwsOptions#getAwsCredentialsProvider()}.
*/
- public abstract @Nullable @Pure AwsCredentialsProvider credentialsProvider();
+ @JsonProperty
+ @Memoized
+ public @Nullable @Pure AwsCredentialsProvider credentialsProvider() {
+ return credentialsProviderAsJson() != null
+ ? deserializeAwsCredentialsProvider(credentialsProviderAsJson())
+ : null;
+ }
/**
* Optional {@link Region}. If set, this overwrites the default in {@link
* AwsOptions#getAwsRegion()}.
*/
+ @JsonProperty
+ @Memoized
Review comment:
ditto
##########
File path:
sdks/java/io/amazon-web-services2/src/test/java/org/apache/beam/sdk/io/aws2/s3/SSECustomerKeyTest.java
##########
@@ -54,4 +55,18 @@ public void buildWithArgs(String key, String algorithm,
String md5, String encod
assertEquals(algorithm, sseCustomerKey.getAlgorithm());
assertEquals(encodedMD5, sseCustomerKey.getMD5());
}
+
+ @Test
+ public void testJsonSerializeDeserialize() {
+ // default key created by S3Options.SSECustomerKeyFactory
+ SSECustomerKey emptyKey = SSECustomerKey.builder().build();
+
assertThat(jsonSerializeDeserialize(emptyKey)).isEqualToComparingFieldByField(emptyKey);
Review comment:
I know you just moved the test method, but why is this needed to use
`isEqualToComparingFieldByField` rather than `isEqualTo` in that case ?
##########
File path:
sdks/java/io/amazon-web-services2/src/test/java/org/apache/beam/sdk/io/aws2/common/HttpClientConfigurationTest.java
##########
@@ -0,0 +1,49 @@
+/*
+ * 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.beam.sdk.io.aws2.common;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.beam.sdk.io.aws2.options.SerializationTestUtil;
+import org.junit.Test;
+
+public class HttpClientConfigurationTest {
+ @Test
+ public void testJsonSerialization() {
+ HttpClientConfiguration expected =
HttpClientConfiguration.builder().build();
+ assertThat(serializeAndDeserialize(expected)).isEqualTo(expected);
+
+ expected =
+ HttpClientConfiguration.builder()
+ .connectionAcquisitionTimeout(100)
+ .connectionMaxIdleTime(200)
+ .connectionTimeout(300)
+ .connectionTimeToLive(400)
+ .socketTimeout(500)
+ .readTimeout(600)
+ .writeTimeout(700)
+ .maxConnections(10)
+ .build();
+
Review comment:
you did not do any progressive testing this time because too many
properties ? :smile:
But fair enough
##########
File path:
sdks/java/io/amazon-web-services2/src/test/java/org/apache/beam/sdk/io/aws2/options/AwsModuleTest.java
##########
@@ -151,33 +149,6 @@ public void
testProxyConfigurationSerializationDeserialization() throws Exceptio
assertEquals("password", deserializedProxyConfiguration.password());
}
- @Test
Review comment:
Agree, better to move them to dedicated test files
##########
File path:
sdks/java/io/amazon-web-services2/src/test/java/org/apache/beam/sdk/io/aws2/common/ClientConfigurationTest.java
##########
@@ -50,4 +52,28 @@ public void testSerialization() {
assertThat(deserializedConfig).isEqualTo(config);
}
+
+ @Test
+ public void testJsonSerialization() {
Review comment:
PS: I like this progressive tested, unset conf obj, then 1 property,
then 2, etc...
##########
File path:
sdks/java/io/amazon-web-services2/src/test/java/org/apache/beam/sdk/io/aws2/common/ClientConfigurationTest.java
##########
@@ -50,4 +52,28 @@ public void testSerialization() {
assertThat(deserializedConfig).isEqualTo(config);
}
+
+ @Test
+ public void testJsonSerialization() {
Review comment:
I think you missed to test with `retry(RetryConfiguration retry)` er
`regionId` set on config.
--
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]