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_metricIsRecordedButNotAddedToUserAgentString () throws Exception {
167+ void when_asyncCompressedOperationIsCalled_metricIsRecordedAndAddedToUserAgentString () throws Exception {
166168 ProtocolRestJsonAsyncClientBuilder clientBuilder = asyncClientBuilderForProtocolRestJson ();
167169
168170 assertThatThrownBy (() -> clientBuilder .build ().putOperationWithRequestCompression (r -> r .body (SdkBytes .fromUtf8String (
@@ -173,7 +175,22 @@ void when_compressedOperationIsCalled_metricIsRecordedButNotAddedToUserAgentStri
173175 BusinessMetricCollection attribute = interceptor .executionAttributes ().getAttribute (SdkInternalExecutionAttribute .BUSINESS_METRICS );
174176 assertThat (attribute ).isNotNull ();
175177 assertThat (attribute .recordedMetrics ()).contains (BusinessMetricFeatureId .GZIP_REQUEST_COMPRESSION .value ());
176- assertThat (userAgent ).doesNotMatch (METRIC_SEARCH_PATTERN .apply (BusinessMetricFeatureId .GZIP_REQUEST_COMPRESSION .value ()));
178+ assertThat (userAgent ).matches (METRIC_SEARCH_PATTERN .apply (BusinessMetricFeatureId .GZIP_REQUEST_COMPRESSION .value ()));
179+ }
180+
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 ()));
177194 }
178195
179196 private String assertAndGetUserAgentString () {
@@ -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