Skip to content

Commit edf352c

Browse files
committed
Revert "Make execution attributes immutable and fix other PR comments"
This reverts commit ad9a6d3.
1 parent b32b022 commit edf352c

File tree

9 files changed

+25
-143
lines changed

9 files changed

+25
-143
lines changed

core/aws-core/src/main/java/software/amazon/awssdk/awscore/client/handler/AwsClientHandlerUtils.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@
4040
import software.amazon.awssdk.core.client.config.SdkClientOption;
4141
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
4242
import software.amazon.awssdk.core.http.ExecutionContext;
43-
import software.amazon.awssdk.core.interceptor.*;
43+
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
44+
import software.amazon.awssdk.core.interceptor.ExecutionInterceptorChain;
45+
import software.amazon.awssdk.core.interceptor.InterceptorContext;
46+
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
47+
import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute;
4448
import software.amazon.awssdk.core.metrics.CoreMetric;
4549
import software.amazon.awssdk.core.signer.Signer;
4650
import software.amazon.awssdk.http.SdkHttpFullRequest;
@@ -102,7 +106,8 @@ static <InputT extends SdkRequest, OutputT extends SdkResponse> ExecutionContext
102106
executionAttributes = clientOverrideExecutionAttributes.merge(executionAttributes);
103107
}
104108

105-
Optional<? extends RequestOverrideConfiguration> requestOverrideConfiguration = originalRequest.overrideConfiguration();
109+
Optional<RequestOverrideConfiguration> requestOverrideConfiguration =
110+
(Optional<RequestOverrideConfiguration>) originalRequest.overrideConfiguration();
106111
if (requestOverrideConfiguration.isPresent()) {
107112
executionAttributes = requestOverrideConfiguration.get().executionAttributes().merge(executionAttributes);
108113
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/RequestOverrideConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import software.amazon.awssdk.annotations.SdkPublicApi;
3030
import software.amazon.awssdk.core.interceptor.ExecutionAttribute;
3131
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
32-
import software.amazon.awssdk.core.interceptor.UnmodifiableExecutionAttributes;
3332
import software.amazon.awssdk.core.signer.Signer;
3433
import software.amazon.awssdk.metrics.MetricPublisher;
3534
import software.amazon.awssdk.utils.CollectionUtils;
@@ -59,7 +58,7 @@ protected RequestOverrideConfiguration(Builder<?> builder) {
5958
this.apiCallAttemptTimeout = Validate.isPositiveOrNull(builder.apiCallAttemptTimeout(), "apiCallAttemptTimeout");
6059
this.signer = builder.signer();
6160
this.metricPublishers = Collections.unmodifiableList(new ArrayList<>(builder.metricPublishers()));
62-
this.executionAttributes = new UnmodifiableExecutionAttributes(builder.executionAttributes().build());
61+
this.executionAttributes = builder.executionAttributes().build();
6362
}
6463

6564
/**

core/sdk-core/src/main/java/software/amazon/awssdk/core/client/config/ClientOverrideConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import software.amazon.awssdk.core.interceptor.ExecutionAttribute;
2929
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
3030
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
31-
import software.amazon.awssdk.core.interceptor.UnmodifiableExecutionAttributes;
3231
import software.amazon.awssdk.core.retry.RetryMode;
3332
import software.amazon.awssdk.core.retry.RetryPolicy;
3433
import software.amazon.awssdk.core.sync.ResponseTransformer;
@@ -75,7 +74,7 @@ private ClientOverrideConfiguration(Builder builder) {
7574
this.defaultProfileFile = builder.defaultProfileFile();
7675
this.defaultProfileName = builder.defaultProfileName();
7776
this.metricPublishers = Collections.unmodifiableList(new ArrayList<>(builder.metricPublishers()));
78-
this.executionAttributes = new UnmodifiableExecutionAttributes(builder.executionAttributes().build());
77+
this.executionAttributes = builder.executionAttributes().build();
7978
}
8079

8180
@Override

core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/ExecutionAttribute.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
package software.amazon.awssdk.core.interceptor;
1717

1818
import software.amazon.awssdk.annotations.SdkPublicApi;
19-
import software.amazon.awssdk.core.RequestOverrideConfiguration;
20-
21-
import java.util.Objects;
2219

2320
/**
2421
* An attribute attached to a particular execution, stored in {@link ExecutionAttributes}.
@@ -60,32 +57,4 @@ public ExecutionAttribute(String name) {
6057
public String toString() {
6158
return name;
6259
}
63-
64-
/**
65-
* This override considers execution attributes with the same name
66-
* to be the same object for the purpose of attribute merge.
67-
* @return boolean indicating whether the objects are equal or not.
68-
*/
69-
@Override
70-
public boolean equals(Object o) {
71-
if (this == o) {
72-
return true;
73-
}
74-
if (o == null || getClass() != o.getClass()) {
75-
return false;
76-
}
77-
78-
ExecutionAttribute that = (ExecutionAttribute) o;
79-
return that.name.equals(this.name);
80-
}
81-
82-
/**
83-
* This override considers execution attributes with the same name
84-
* to be the same object for the purpose of attribute merge.
85-
* @return hash code
86-
*/
87-
@Override
88-
public int hashCode() {
89-
return Objects.hashCode(name);
90-
}
9160
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/ExecutionAttributes.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
*/
3232
@SdkPublicApi
3333
@NotThreadSafe
34-
public class ExecutionAttributes implements ToCopyableBuilder<ExecutionAttributes.Builder, ExecutionAttributes> {
34+
public final class ExecutionAttributes implements ToCopyableBuilder<ExecutionAttributes.Builder, ExecutionAttributes> {
3535
private final Map<ExecutionAttribute<?>, Object> attributes;
3636

3737
public ExecutionAttributes() {
3838
this.attributes = new HashMap<>();
3939
}
4040

41-
protected ExecutionAttributes(Map<? extends ExecutionAttribute<?>, ?> attributes) {
41+
private ExecutionAttributes(Map<? extends ExecutionAttribute<?>, ?> attributes) {
4242
this.attributes = new HashMap<>(attributes);
4343
}
4444

@@ -66,13 +66,20 @@ public <U> ExecutionAttributes putAttribute(ExecutionAttribute<U> attribute, U v
6666
return this;
6767
}
6868

69+
/**
70+
* Add all execution attributes from the provided collection to the internal collection of attributes.
71+
*/
72+
public <U> ExecutionAttributes putAllAttributes(Map<ExecutionAttribute<?>, ?> executionAttributes) {
73+
this.attributes.putAll(executionAttributes);
74+
return this;
75+
}
76+
6977
/**
7078
* Merge attributes of a lower precedence into the current higher precedence current collection.
7179
*/
72-
public ExecutionAttributes merge(ExecutionAttributes lowerPrecedenceExecutionAttributes) {
73-
Map<ExecutionAttribute<?>, Object> copiedAttributes = new HashMap<>(this.attributes);
74-
lowerPrecedenceExecutionAttributes.getAttributes().forEach(copiedAttributes::putIfAbsent);
75-
return new ExecutionAttributes(copiedAttributes);
80+
public <U> ExecutionAttributes merge(ExecutionAttributes lowerPrecedenceExecutionAttributes) {
81+
lowerPrecedenceExecutionAttributes.getAttributes().forEach(this.attributes::putIfAbsent);
82+
return this;
7683
}
7784

7885
/**
@@ -103,7 +110,7 @@ public static final class Builder implements CopyableBuilder<ExecutionAttributes
103110
private Builder() {
104111
}
105112

106-
113+
@SuppressWarnings("unchecked") // Cast is safe due to implementation of {@link #put}
107114
public <T> T get(ExecutionAttribute<T> key) {
108115
Validate.notNull(key, "Key to retrieve must not be null.");
109116
return (T) executionAttributes.get(key);

core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/UnmodifiableExecutionAttributes.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

core/sdk-core/src/test/java/software/amazon/awssdk/core/RequestOverrideConfigurationTest.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20-
import static org.junit.Assert.fail;
2120
import static org.mockito.Mockito.mock;
2221

2322
import java.util.ArrayList;
@@ -27,7 +26,6 @@
2726
import java.util.List;
2827
import java.util.Map;
2928
import org.junit.Test;
30-
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
3129
import software.amazon.awssdk.core.interceptor.ExecutionAttribute;
3230
import software.amazon.awssdk.metrics.MetricPublisher;
3331
import software.amazon.awssdk.utils.ImmutableMap;
@@ -185,25 +183,6 @@ public void executionAttributes_createsCopy() {
185183
assertThat(overrideConfig.executionAttributes().getAttribute(testAttribute)).isEqualTo(expectedValue);
186184
}
187185

188-
@Test
189-
public void executionAttributes_isImmutable() {
190-
Map<ExecutionAttribute<?>, Object> executionAttributes = new HashMap<>();
191-
192-
ExecutionAttribute testAttribute = new ExecutionAttribute("TestAttribute");
193-
String expectedValue = "Value1";
194-
executionAttributes.put(testAttribute, expectedValue);
195-
196-
SdkRequestOverrideConfiguration overrideConfig = SdkRequestOverrideConfiguration.builder()
197-
.executionAttributes(executionAttributes)
198-
.build();
199-
try {
200-
overrideConfig.executionAttributes().putAttribute(testAttribute, 2);
201-
fail("Expected unsupported operation exception");
202-
} catch(Exception ex) {
203-
assertThat(ex instanceof UnsupportedOperationException).isTrue();
204-
}
205-
}
206-
207186
@Test
208187
public void executionAttributes_maintainsAllAdded() {
209188
Map<ExecutionAttribute, Object> executionAttributeObjectMap = new HashMap<>();

core/sdk-core/src/test/java/software/amazon/awssdk/core/client/config/ClientOverrideConfigurationTest.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
package software.amazon.awssdk.core.client.config;
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
19-
import static org.junit.Assert.*;
19+
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertTrue;
2021
import static org.mockito.Mockito.mock;
2122

2223
import java.util.ArrayList;
@@ -197,26 +198,6 @@ public void executionAttributes_createsCopy() {
197198
assertThat(overrideConfig.executionAttributes().getAttribute(testAttribute)).isEqualTo(expectedValue);
198199
}
199200

200-
@Test
201-
public void executionAttributes_isImmutable() {
202-
Map<ExecutionAttribute<?>, Object> executionAttributes = new HashMap<>();
203-
204-
ExecutionAttribute testAttribute = new ExecutionAttribute("TestAttribute");
205-
String expectedValue = "Value1";
206-
executionAttributes.put(testAttribute, expectedValue);
207-
208-
ClientOverrideConfiguration overrideConfig = ClientOverrideConfiguration.builder()
209-
.executionAttributes(executionAttributes)
210-
.build();
211-
212-
try {
213-
overrideConfig.executionAttributes().putAttribute(testAttribute, 2);
214-
fail("Expected unsupported operation exception");
215-
} catch(Exception ex) {
216-
assertThat(ex instanceof UnsupportedOperationException).isTrue();
217-
}
218-
}
219-
220201
@Test
221202
public void executionAttributes_maintainsAllAdded() {
222203
Map<ExecutionAttribute, Object> executionAttributeObjectMap = new HashMap<>();

test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/ExecutionAttributesTest.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -149,29 +149,4 @@ public void asyncClient_requestOverrideExecutionAttributesHavePrecedence() {
149149
async.close();
150150
}
151151
}
152-
153-
@Test
154-
public void testExecutionAttributesMerge() {
155-
ExecutionAttributes lowerPrecedence = new ExecutionAttributes();
156-
for (int i = 0; i < 3; i++) {
157-
lowerPrecedence.putAttribute(getAttribute(i), 1);
158-
}
159-
160-
ExecutionAttributes higherPrecendence = new ExecutionAttributes();
161-
for (int i = 2; i < 4; i++) {
162-
higherPrecendence.putAttribute(getAttribute(i), 2);
163-
}
164-
165-
ExecutionAttributes expectedAttributes = new ExecutionAttributes();
166-
for (int i = 0; i < 4; i++) {
167-
expectedAttributes.putAttribute(getAttribute(i), i >= 2 ? 2 : 1);
168-
}
169-
170-
ExecutionAttributes mergedAttributes = higherPrecendence.merge(lowerPrecedence);
171-
assertThat(mergedAttributes.getAttributes()).isEqualTo(expectedAttributes.getAttributes());
172-
}
173-
174-
private ExecutionAttribute getAttribute(int i) {
175-
return new ExecutionAttribute<>("TestAttribute" + i);
176-
}
177152
}

0 commit comments

Comments
 (0)