@@ -168,6 +168,127 @@ void configurationWithHttpSettings_localVariable_shouldRemoveAndSetOnSdkClient()
168
168
);
169
169
}
170
170
171
+ @ Test
172
+ @ EnabledOnJre ({JRE .JAVA_8 })
173
+ void configurationWithHttpSettings_memberVariable_shouldRemoveAndSetOnSdkClient () {
174
+
175
+ rewriteRun (
176
+ recipeSpec -> recipeSpec .expectedCyclesThatMakeChanges (2 ),
177
+ java (
178
+ "import com.amazonaws.ClientConfiguration;\n "
179
+ + "import com.amazonaws.services.sqs.AmazonSQS;\n "
180
+ + "import com.amazonaws.services.sqs.AmazonSQSClient;\n "
181
+ + "\n "
182
+ + "public class Example {\n "
183
+ + " private ClientConfiguration clientConfiguration = new ClientConfiguration()\n "
184
+ + " .withRequestTimeout(1000)\n "
185
+ + " .withMaxConnections(2000)\n "
186
+ + " .withConnectionTimeout(3000)\n "
187
+ + " .withTcpKeepAlive(true)\n "
188
+ + " .withSocketTimeout(4000)\n "
189
+ + " .withConnectionTTL(5000)\n "
190
+ + " .withConnectionMaxIdleMillis(6000);\n "
191
+ + "\n "
192
+ + " public void test() {\n "
193
+ + " AmazonSQS sqs = AmazonSQSClient.builder()\n "
194
+ + " .withClientConfiguration(clientConfiguration)\n "
195
+ + " .build();\n "
196
+ + " }\n "
197
+ + "}" ,
198
+ "import software.amazon.awssdk.http.apache.ApacheHttpClient;\n "
199
+ + "import software.amazon.awssdk.services.sqs.SqsClient;\n "
200
+ + "import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;\n "
201
+ + "\n "
202
+ + "import java.time.Duration;\n "
203
+ + "\n "
204
+ + "public class Example {\n "
205
+ + " private ClientOverrideConfiguration clientConfiguration =ClientOverrideConfiguration.builder()\n "
206
+ + " .apiCallAttemptTimeout(Duration.ofMillis(1000)).build();\n "
207
+ + "\n "
208
+ + " public void test() {\n "
209
+ + " SqsClient sqs = SqsClient.builder()\n "
210
+ + " .overrideConfiguration(clientConfiguration)\n "
211
+ + " .httpClientBuilder(ApacheHttpClient.builder()\n "
212
+ + " .connectionMaxIdleTime(Duration.ofMillis(6000))\n "
213
+ + " .tcpKeepAlive(true)\n "
214
+ + " .socketTimeout(Duration.ofMillis(4000))\n "
215
+ + " .connectionTimeToLive(Duration.ofMillis(5000))\n "
216
+ + " .connectionTimeout(Duration.ofMillis(3000))\n "
217
+ + " .maxConnections(2000))\n "
218
+ + " .build();\n "
219
+ + " }\n "
220
+ + "}"
221
+ )
222
+ );
223
+ }
224
+
225
+ @ Test
226
+ @ EnabledOnJre ({JRE .JAVA_8 })
227
+ void configurationWithHttpSettings_usedByMultipleSdkClients_shouldRemoveAndSetOnSdkClients () {
228
+
229
+ rewriteRun (
230
+ recipeSpec -> recipeSpec .expectedCyclesThatMakeChanges (2 ),
231
+ java (
232
+ "import com.amazonaws.ClientConfiguration;\n "
233
+ + "import com.amazonaws.services.sqs.AmazonSQS;\n "
234
+ + "import com.amazonaws.services.sqs.AmazonSQSClient;\n "
235
+ + "\n "
236
+ + "public class Example {\n "
237
+ + " private static final ClientConfiguration CONFIGURATION = new ClientConfiguration()\n "
238
+ + " .withRequestTimeout(1000)\n "
239
+ + " .withMaxConnections(2000)\n "
240
+ + " .withConnectionTimeout(3000)\n "
241
+ + " .withTcpKeepAlive(true)\n "
242
+ + " .withSocketTimeout(4000)\n "
243
+ + " .withConnectionTTL(5000)\n "
244
+ + " .withConnectionMaxIdleMillis(6000);\n "
245
+ + " private final AmazonSQS sqsMemberVariable = AmazonSQSClient.builder()\n "
246
+ + " .withClientConfiguration(CONFIGURATION)\n "
247
+ + " .build();\n "
248
+ + "\n "
249
+ + " public void test() {\n "
250
+ + " AmazonSQS sqs = AmazonSQSClient.builder()\n "
251
+ + " .withClientConfiguration(CONFIGURATION)\n "
252
+ + " .build();\n "
253
+ + " }\n "
254
+ + "}" ,
255
+ "import software.amazon.awssdk.http.apache.ApacheHttpClient;\n "
256
+ + "import software.amazon.awssdk.services.sqs.SqsClient;\n "
257
+ + "import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;\n "
258
+ + "\n "
259
+ + "import java.time.Duration;\n "
260
+ + "\n "
261
+ + "public class Example {\n "
262
+ + " private static final ClientOverrideConfiguration CONFIGURATION =ClientOverrideConfiguration.builder()\n "
263
+ + " .apiCallAttemptTimeout(Duration.ofMillis(1000)).build();\n "
264
+ + " private final SqsClient sqsMemberVariable = SqsClient.builder()\n "
265
+ + " .overrideConfiguration(CONFIGURATION)\n "
266
+ + " .httpClientBuilder(ApacheHttpClient.builder()\n "
267
+ + " .connectionMaxIdleTime(Duration.ofMillis(6000))\n "
268
+ + " .tcpKeepAlive(true)\n "
269
+ + " .socketTimeout(Duration.ofMillis(4000))\n "
270
+ + " .connectionTimeToLive(Duration.ofMillis(5000))\n "
271
+ + " .connectionTimeout(Duration.ofMillis(3000))\n "
272
+ + " .maxConnections(2000))\n "
273
+ + " .build();\n "
274
+ + "\n "
275
+ + " public void test() {\n "
276
+ + " SqsClient sqs = SqsClient.builder()\n "
277
+ + " .overrideConfiguration(CONFIGURATION)\n "
278
+ + " .httpClientBuilder(ApacheHttpClient.builder()\n "
279
+ + " .connectionMaxIdleTime(Duration.ofMillis(6000))\n "
280
+ + " .tcpKeepAlive(true)\n "
281
+ + " .socketTimeout(Duration.ofMillis(4000))\n "
282
+ + " .connectionTimeToLive(Duration.ofMillis(5000))\n "
283
+ + " .connectionTimeout(Duration.ofMillis(3000))\n "
284
+ + " .maxConnections(2000))\n "
285
+ + " .build();\n "
286
+ + " }\n "
287
+ + "}"
288
+ )
289
+ );
290
+ }
291
+
171
292
@ Test
172
293
@ EnabledOnJre ({JRE .JAVA_8 })
173
294
void configurationWithHttpSettings_methodReference_shouldRemoveAndSetOnSdkClient () {
0 commit comments