Skip to content

Commit 9dd1645

Browse files
committed
more cleanups
1 parent 5c69b35 commit 9dd1645

File tree

2 files changed

+32
-43
lines changed

2 files changed

+32
-43
lines changed

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientCoreTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ public abstract class AbstractAws2ClientCoreTest {
6868

6969
protected abstract ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder();
7070

71-
static boolean isSqsAttributeInjectionEnabled() {
71+
protected static boolean isSqsAttributeInjectionEnabled() {
7272
// See io.opentelemetry.instrumentation.awssdk.v2_2.autoconfigure.TracingExecutionInterceptor
7373
return ConfigPropertiesUtil.getBoolean(
7474
"otel.instrumentation.aws-sdk.experimental-use-propagator-for-messaging", false);
7575
}
7676

77-
static final StaticCredentialsProvider CREDENTIALS_PROVIDER =
77+
protected static final StaticCredentialsProvider CREDENTIALS_PROVIDER =
7878
StaticCredentialsProvider.create(
7979
AwsBasicCredentials.create("my-access-key", "my-secret-key"));
8080

81-
static MockWebServerExtension server = new MockWebServerExtension();
81+
protected static MockWebServerExtension server = new MockWebServerExtension();
8282

8383
@BeforeAll
8484
static void setup() {
@@ -95,21 +95,21 @@ void prepTest() {
9595
server.beforeTestExecution(null);
9696
}
9797

98-
void configureSdkClient(SdkClientBuilder<?, ?> builder) {
98+
protected void configureSdkClient(SdkClientBuilder<?, ?> builder) {
9999
builder.overrideConfiguration(createOverrideConfigurationBuilder().build());
100100
}
101101

102-
static ImmutableMap<String, AttributeValue> createTableRequestKey =
102+
private static final ImmutableMap<String, AttributeValue> createTableRequestKey =
103103
ImmutableMap.of(
104104
"anotherKey", AttributeValue.builder().s("value").build(),
105105
"key", AttributeValue.builder().s("value").build());
106106

107-
static ImmutableMap<String, AttributeValue> getItemRequestKey =
107+
private static final ImmutableMap<String, AttributeValue> getItemRequestKey =
108108
ImmutableMap.of(
109109
"keyOne", AttributeValue.builder().s("value").build(),
110110
"keyTwo", AttributeValue.builder().s("differentValue").build());
111111

112-
static ImmutableMap<String, AttributeValue> putItemRequestKey =
112+
private static final ImmutableMap<String, AttributeValue> putItemRequestKey =
113113
ImmutableMap.of(
114114
"key", AttributeValue.builder().s("value").build(),
115115
"attributeOne", AttributeValue.builder().s("one").build(),
@@ -144,7 +144,7 @@ private void executeCall(String operation, Object response)
144144
}));
145145
}
146146

147-
static CreateTableRequest createTableRequest() {
147+
private static CreateTableRequest createTableRequest() {
148148
return CreateTableRequest.builder()
149149
.tableName("sometable")
150150
.globalSecondaryIndexes(
@@ -174,7 +174,7 @@ static CreateTableRequest createTableRequest() {
174174
}
175175

176176
@SuppressWarnings("deprecation") // uses deprecated semconv
177-
static void assertCreateTableRequest(SpanDataAssert span) {
177+
private static void assertCreateTableRequest(SpanDataAssert span) {
178178
span.hasName("DynamoDb.CreateTable")
179179
.hasKind(SpanKind.CLIENT)
180180
.hasNoParent()
@@ -200,7 +200,7 @@ static void assertCreateTableRequest(SpanDataAssert span) {
200200
}
201201

202202
@SuppressWarnings("deprecation") // using deprecated semconv
203-
static void assertQueryRequest(SpanDataAssert span) {
203+
private static void assertQueryRequest(SpanDataAssert span) {
204204
span.hasName("DynamoDb.Query")
205205
.hasKind(SpanKind.CLIENT)
206206
.hasNoParent()
@@ -223,7 +223,7 @@ static void assertQueryRequest(SpanDataAssert span) {
223223
}
224224

225225
@SuppressWarnings("deprecation") // uses deprecated semconv
226-
static void assertDynamoDbRequest(SpanDataAssert span, String operation) {
226+
private static void assertDynamoDbRequest(SpanDataAssert span, String operation) {
227227
span.hasName("DynamoDb." + operation)
228228
.hasKind(SpanKind.CLIENT)
229229
.hasNoParent()

instrumentation/aws-sdk/aws-sdk-2.2/testing/src/main/java/io/opentelemetry/instrumentation/awssdk/v2_2/AbstractAws2ClientTest.java

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
import io.opentelemetry.testing.internal.armeria.common.MediaType;
3636
import io.opentelemetry.testing.internal.armeria.common.ResponseHeaders;
3737
import io.opentelemetry.testing.internal.armeria.testing.junit5.server.mock.RecordedRequest;
38+
import java.lang.reflect.InvocationTargetException;
3839
import java.lang.reflect.Method;
3940
import java.net.URI;
4041
import java.nio.charset.StandardCharsets;
4142
import java.time.Duration;
4243
import java.util.ArrayList;
4344
import java.util.List;
4445
import java.util.concurrent.Callable;
46+
import java.util.concurrent.ExecutionException;
4547
import java.util.concurrent.Future;
4648
import java.util.function.Function;
4749
import java.util.stream.Stream;
@@ -96,7 +98,7 @@ private static void assumeSupportedConfig(String operation) {
9698
// Force localhost instead of relying on mock server because using ip is yet another corner case
9799
// of the virtual bucket changes introduced by aws sdk v2.18.0. When using IP, there is no way to
98100
// prefix the hostname with the bucket name as label.
99-
URI clientUri = URI.create("http://localhost:" + server.httpPort());
101+
private final URI clientUri = URI.create("http://localhost:" + server.httpPort());
100102

101103
private static final String ec2BodyContent =
102104
"<AllocateAddressResponse xmlns=\"http://ec2.amazonaws.com/doc/2016-11-15/\">"
@@ -110,26 +112,6 @@ private static void assumeSupportedConfig(String operation) {
110112
+ " <ResponseMetadata><RequestId>0ac9cda2-bbf4-11d3-f92b-31fa5e8dbc99</RequestId></ResponseMetadata>"
111113
+ "</DeleteOptionGroupResponse>";
112114

113-
S3ClientBuilder s3ClientBuilder() throws Exception {
114-
S3ClientBuilder builder = S3Client.builder();
115-
if (Boolean.getBoolean("testLatestDeps")) {
116-
Method forcePathStyleMethod =
117-
S3ClientBuilder.class.getMethod("forcePathStyle", Boolean.class);
118-
forcePathStyleMethod.invoke(builder, true);
119-
}
120-
return builder;
121-
}
122-
123-
S3AsyncClientBuilder s3AsyncClientBuilder() throws Exception {
124-
S3AsyncClientBuilder builder = S3AsyncClient.builder();
125-
if (Boolean.getBoolean("testLatestDeps")) {
126-
Method forcePathStyleMethod =
127-
S3AsyncClientBuilder.class.getMethod("forcePathStyle", Boolean.class);
128-
forcePathStyleMethod.invoke(builder, true);
129-
}
130-
return builder;
131-
}
132-
133115
@SuppressWarnings("deprecation") // uses deprecated semconv
134116
private void clientAssertions(
135117
String service, String operation, String method, Object response, String requestId) {
@@ -259,7 +241,12 @@ private static Stream<Arguments> provideS3Arguments() {
259241
@MethodSource("provideS3Arguments")
260242
void testS3SendOperationRequestWithBuilder(
261243
String operation, String method, Function<S3Client, Object> call) throws Exception {
262-
S3ClientBuilder builder = s3ClientBuilder();
244+
S3ClientBuilder builder = S3Client.builder();
245+
if (Boolean.getBoolean("testLatestDeps")) {
246+
Method forcePathStyleMethod =
247+
S3ClientBuilder.class.getMethod("forcePathStyle", Boolean.class);
248+
forcePathStyleMethod.invoke(builder, true);
249+
}
263250
configureSdkClient(builder);
264251
S3Client client =
265252
builder
@@ -287,8 +274,17 @@ void testS3AsyncSendOperationRequestWithBuilder(
287274
Function<S3Client, Object> call,
288275
Function<S3AsyncClient, Future<?>> asyncCall,
289276
String body)
290-
throws Exception {
291-
S3AsyncClientBuilder builder = s3AsyncClientBuilder();
277+
throws NoSuchMethodException,
278+
InvocationTargetException,
279+
IllegalAccessException,
280+
ExecutionException,
281+
InterruptedException {
282+
S3AsyncClientBuilder builder = S3AsyncClient.builder();
283+
if (Boolean.getBoolean("testLatestDeps")) {
284+
Method forcePathStyleMethod =
285+
S3AsyncClientBuilder.class.getMethod("forcePathStyle", Boolean.class);
286+
forcePathStyleMethod.invoke(builder, true);
287+
}
292288
configureSdkClient(builder);
293289
S3AsyncClient client =
294290
builder
@@ -519,14 +515,7 @@ void testEc2SendOperationRequestWithBuilder() throws Exception {
519515
.credentialsProvider(CREDENTIALS_PROVIDER)
520516
.build();
521517

522-
String content =
523-
"<AllocateAddressResponse xmlns=\"http://ec2.amazonaws.com/doc/2016-11-15/\">"
524-
+ " <requestId>59dbff89-35bd-4eac-99ed-be587EXAMPLE</requestId>"
525-
+ " <publicIp>192.0.2.1</publicIp>"
526-
+ " <domain>standard</domain>"
527-
+ "</AllocateAddressResponse>";
528-
529-
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, content));
518+
server.enqueue(HttpResponse.of(HttpStatus.OK, MediaType.PLAIN_TEXT_UTF_8, ec2BodyContent));
530519
Object response = client.allocateAddress();
531520

532521
assertThat(response.getClass().getSimpleName())

0 commit comments

Comments
 (0)