4848import software .amazon .awssdk .regions .Region ;
4949import software .amazon .awssdk .services .protocolrestjson .ProtocolRestJsonAsyncClient ;
5050import software .amazon .awssdk .services .protocolrestjson .ProtocolRestJsonAsyncClientBuilder ;
51+ import software .amazon .awssdk .services .protocolrestjson .ProtocolRestJsonClient ;
52+ import software .amazon .awssdk .services .protocolrestjson .ProtocolRestJsonClientBuilder ;
5153import software .amazon .awssdk .services .protocolrestjson .internal .ServiceVersionInfo ;
5254import software .amazon .awssdk .services .protocolrestjson .model .PaginatedOperationWithResultKeyResponse ;
5355import 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