Skip to content

Commit 6f723b6

Browse files
committed
Add gzip sync test
1 parent 576252a commit 6f723b6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import software.amazon.awssdk.regions.Region;
4949
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClient;
5050
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonAsyncClientBuilder;
51+
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClient;
52+
import software.amazon.awssdk.services.protocolrestjson.ProtocolRestJsonClientBuilder;
5153
import software.amazon.awssdk.services.protocolrestjson.internal.ServiceVersionInfo;
5254
import software.amazon.awssdk.services.protocolrestjson.model.PaginatedOperationWithResultKeyResponse;
5355
import software.amazon.awssdk.services.protocolrestjson.paginators.PaginatedOperationWithResultKeyPublisher;
@@ -162,7 +164,7 @@ void when_paginatedOperationIsCalled_correctMetricIsAdded() throws Exception {
162164
}
163165

164166
@Test
165-
void when_compressedOperationIsCalled_metricIsRecordedAndAddedToUserAgentString() throws Exception {
167+
void when_asyncCompressedOperationIsCalled_metricIsRecordedAndAddedToUserAgentString() throws Exception {
166168
ProtocolRestJsonAsyncClientBuilder clientBuilder = asyncClientBuilderForProtocolRestJson();
167169

168170
assertThatThrownBy(() -> clientBuilder.build().putOperationWithRequestCompression(r -> r.body(SdkBytes.fromUtf8String(
@@ -176,6 +178,21 @@ void when_compressedOperationIsCalled_metricIsRecordedAndAddedToUserAgentString(
176178
assertThat(userAgent).matches(METRIC_SEARCH_PATTERN.apply(BusinessMetricFeatureId.GZIP_REQUEST_COMPRESSION.value()));
177179
}
178180

181+
@Test
182+
void when_syncCompressedOperationIsCalled_metricIsRecordedAndAddedToUserAgentString() throws Exception {
183+
ProtocolRestJsonClientBuilder clientBuilder = syncClientBuilderForProtocolRestJson();
184+
185+
assertThatThrownBy(() -> clientBuilder.build().putOperationWithRequestCompression(r -> r.body(SdkBytes.fromUtf8String(
186+
"whoo")).overrideConfiguration(o -> o.compressionConfiguration(c -> c.minimumCompressionThresholdInBytes(1)))))
187+
.hasMessageContaining("stop");
188+
189+
String userAgent = assertAndGetUserAgentString();
190+
BusinessMetricCollection attribute = interceptor.executionAttributes().getAttribute(SdkInternalExecutionAttribute.BUSINESS_METRICS);
191+
assertThat(attribute).isNotNull();
192+
assertThat(attribute.recordedMetrics()).contains(BusinessMetricFeatureId.GZIP_REQUEST_COMPRESSION.value());
193+
assertThat(userAgent).matches(METRIC_SEARCH_PATTERN.apply(BusinessMetricFeatureId.GZIP_REQUEST_COMPRESSION.value()));
194+
}
195+
179196
private String assertAndGetUserAgentString() {
180197
Map<String, List<String>> headers = interceptor.context.httpRequest().headers();
181198
assertThat(headers).containsKey(USER_AGENT_HEADER_NAME);
@@ -196,6 +213,13 @@ private ProtocolRestJsonAsyncClientBuilder asyncClientBuilderForProtocolRestJson
196213
.overrideConfiguration(c -> c.addExecutionInterceptor(interceptor));
197214
}
198215

216+
private ProtocolRestJsonClientBuilder syncClientBuilderForProtocolRestJson() {
217+
return ProtocolRestJsonClient.builder()
218+
.region(Region.US_WEST_2)
219+
.credentialsProvider(CREDENTIALS_PROVIDER)
220+
.overrideConfiguration(c -> c.addExecutionInterceptor(interceptor));
221+
}
222+
199223
public static class CapturingInterceptor implements ExecutionInterceptor {
200224
private Context.BeforeTransmission context;
201225
private ExecutionAttributes executionAttributes;

0 commit comments

Comments
 (0)