diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParser.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParser.java index dc372d2c3..676935062 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParser.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParser.java @@ -40,7 +40,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { builder.addConstructorArgReference( getCustomClientOrDefaultClientBeanName(element, parserContext, - "amazon-sns", "com.amazonaws.services.sns.AmazonSNSClient")); + "amazon-sns", "software.amazon.awssdk.services.sns.SnsClient")); } } diff --git a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParser.java b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParser.java index 7bd1a71d0..483864923 100644 --- a/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParser.java +++ b/spring-cloud-aws-messaging/src/main/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParser.java @@ -35,7 +35,7 @@ public class NotificationMessagingTemplateBeanDefinitionParser private static final String DEFAULT_DESTINATION_ATTRIBUTE = "default-destination"; - private static final String SNS_CLIENT_CLASS_NAME = "com.amazonaws.services.sns.AmazonSNSClient"; + private static final String SNS_CLIENT_CLASS_NAME = "software.amazon.awssdk.services.sns.SnsClient"; @Override protected Class getBeanClass(Element element) { diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfigurationTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfigurationTest.java index 023d931f9..8f6c0e26d 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfigurationTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/annotation/SnsConfigurationTest.java @@ -21,6 +21,9 @@ import org.junit.Before; import org.junit.Test; import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; +import software.amazon.awssdk.awscore.client.config.AwsClientOption; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.regions.ServiceMetadata; import software.amazon.awssdk.services.sns.SnsClient; @@ -90,7 +93,8 @@ public void enableSns_withProvidedCredentials_shouldBeUsedToCreateClient() SnsClient amazonSns = this.webApplicationContext.getBean(SnsClient.class); // Assert - assertThat(ReflectionTestUtils.getField(amazonSns, "awsCredentialsProvider")) + SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(amazonSns, "clientConfiguration"); + assertThat(clientConfiguration.option(AwsClientOption.CREDENTIALS_PROVIDER)) .isEqualTo(SnsConfigurationWithCredentials.AWS_CREDENTIALS_PROVIDER); } @@ -124,9 +128,9 @@ public void enableSns_withRegionProvided_shouldBeUsedToCreateClient() SnsClient amazonSns = this.webApplicationContext.getBean(SnsClient.class); // Assert - assertThat(ReflectionTestUtils.getField(amazonSns, "endpoint").toString()) - .isEqualTo("https://" - + ServiceMetadata.of("sns").endpointFor(Region.EU_WEST_1)); + SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(amazonSns, "clientConfiguration"); + assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT).toString()) + .isEqualTo("https://" + ServiceMetadata.of("sns").endpointFor(Region.EU_WEST_1)); } private NotificationStatusHandlerMethodArgumentResolver getNotificationStatusHandlerMethodArgumentResolver( diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest.java index bee2194e5..b45c563e1 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest.java @@ -19,6 +19,8 @@ import java.net.URI; import org.junit.Test; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.regions.ServiceMetadata; import software.amazon.awssdk.services.sns.SnsClient; @@ -63,10 +65,9 @@ public void parseInternal_customRegion_configuresHandlerMethodArgumentResolverWi SnsClient snsClient = context.getBean(SnsClient.class); // Assert - assertThat(ReflectionTestUtils.getField(snsClient, "endpoint")).isEqualTo(new URI( - "https", - ServiceMetadata.of("sns").endpointFor(Region.EU_WEST_1).toString(), null, - null)); + SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(snsClient, "clientConfiguration"); + assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT)).isEqualTo( + new URI("https", ServiceMetadata.of("sns").endpointFor(Region.EU_WEST_1).toString(), null, null)); } // @checkstyle:off @@ -82,10 +83,9 @@ public void parseInternal_customRegionProvider_configuresHandlerMethodArgumentRe SnsClient snsClient = context.getBean(SnsClient.class); // Assert - assertThat(ReflectionTestUtils.getField(snsClient, "endpoint")).isEqualTo(new URI( - "https", - ServiceMetadata.of("sns").endpointFor(Region.US_WEST_2).toString(), null, - null)); + SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(snsClient, "clientConfiguration"); + assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT)).isEqualTo( + new URI("https", ServiceMetadata.of("sns").endpointFor(Region.US_WEST_2).toString(), null, null)); } @Test diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest.java index 7a2150909..924b0615e 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/NotificationMessagingTemplateBeanDefinitionParserTest.java @@ -19,6 +19,8 @@ import java.util.List; import org.junit.Test; +import software.amazon.awssdk.core.client.config.SdkClientConfiguration; +import software.amazon.awssdk.core.client.config.SdkClientOption; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.regions.ServiceMetadata; import software.amazon.awssdk.services.sns.SnsClient; @@ -151,9 +153,9 @@ public void parseInternal_withCustomRegion_shouldConfigureDefaultClientWithCusto // Assert SnsClient amazonSns = registry.getBean(SnsClient.class); - assertThat(ReflectionTestUtils.getField(amazonSns, "endpoint").toString()) - .isEqualTo("https://" - + ServiceMetadata.of("sns").endpointFor(Region.EU_WEST_1)); + SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(amazonSns, "clientConfiguration"); + assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT).toString()) + .isEqualTo("https://" + ServiceMetadata.of("sns").endpointFor(Region.EU_WEST_1)); } @Test @@ -169,9 +171,9 @@ public void parseInternal_withCustomRegionProvider_shouldConfigureDefaultClientW // Assert SnsClient amazonSns = registry.getBean(SnsClient.class); - assertThat(ReflectionTestUtils.getField(amazonSns, "endpoint").toString()) - .isEqualTo("https://" - + ServiceMetadata.of("sns").endpointFor(Region.CN_NORTH_1)); + SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(amazonSns, "clientConfiguration"); + assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT).toString()) + .isEqualTo("https://" + ServiceMetadata.of("sns").endpointFor(Region.CN_NORTH_1)); } } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest.java index d819eb585..2ce6b8e1b 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/QueueMessagingTemplateBeanDefinitionParserTest.java @@ -177,7 +177,7 @@ public void parseInternal_withCustomRegion_shouldConfigureDefaultClientWithCusto SqsAsyncClient amazonSqs = registry.getBean(SqsAsyncClient.class); SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(amazonSqs, "clientConfiguration"); assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT).toString()) - .isEqualTo(ServiceMetadata.of("sqs").endpointFor(Region.SA_EAST_1)); + .isEqualTo("https://" + ServiceMetadata.of("sqs").endpointFor(Region.SA_EAST_1)); } @Test @@ -195,7 +195,7 @@ public void parseInternal_withCustomRegionProvider_shouldConfigureDefaultClientW SqsAsyncClient amazonSqs = registry.getBean(SqsAsyncClient.class); SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(amazonSqs, "clientConfiguration"); assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT).toString()) - .isEqualTo(ServiceMetadata.of("sqs").endpointFor(Region.AP_SOUTHEAST_2)); + .isEqualTo("https://" + ServiceMetadata.of("sqs").endpointFor(Region.AP_SOUTHEAST_2)); } @Test diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest.java index a813fa89d..d0843ead2 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/config/xml/SqsAsyncClientBeanDefinitionParserTest.java @@ -16,9 +16,11 @@ package org.springframework.cloud.aws.messaging.config.xml; +import java.util.concurrent.Executor; import java.util.concurrent.ThreadPoolExecutor; import org.junit.Test; +import software.amazon.awssdk.core.client.config.SdkAdvancedAsyncClientOption; import software.amazon.awssdk.core.client.config.SdkClientConfiguration; import software.amazon.awssdk.core.client.config.SdkClientOption; import software.amazon.awssdk.regions.Region; @@ -49,9 +51,10 @@ public void parseInternal_minimalConfiguration_createsBufferedClientWithoutExpli // Assert SqsAsyncClient asyncClient = beanFactory.getBean("customClient", SqsAsyncClient.class); assertThat(asyncClient).isNotNull(); - ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) ReflectionTestUtils.getField(asyncClient, - "executorService"); - assertThat(threadPoolExecutor.getCorePoolSize()).isEqualTo(50); + SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(asyncClient, "clientConfiguration"); + ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) clientConfiguration.option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR); + // //TODO SDK2 migration: default value is now 8, s. SdkDefaultClientBuilder.resolveAsyncFutureCompletionExecutor() Check of it used to be 50 + assertThat(threadPoolExecutor.getCorePoolSize()).isEqualTo(8); } @@ -87,9 +90,10 @@ public void parseInternal_withCustomTasExecutor_createsBufferedClientWithCustomT // Assert SqsAsyncClient asyncClient = beanFactory.getBean("customClient", SqsAsyncClient.class); assertThat(asyncClient).isNotNull(); - ShutdownSuppressingExecutorServiceAdapter executor = (ShutdownSuppressingExecutorServiceAdapter) ReflectionTestUtils - .getField(asyncClient, "executorService"); - assertThat(ReflectionTestUtils.getField(executor, "taskExecutor")) + SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(asyncClient, "clientConfiguration"); + Executor executor = clientConfiguration.option(SdkAdvancedAsyncClientOption.FUTURE_COMPLETION_EXECUTOR); + ShutdownSuppressingExecutorServiceAdapter customExecutor = (ShutdownSuppressingExecutorServiceAdapter) ReflectionTestUtils.getField(executor, "executor"); + assertThat(ReflectionTestUtils.getField(customExecutor, "taskExecutor")) .isSameAs(beanFactory.getBean("myThreadPoolTaskExecutor")); } @@ -108,7 +112,7 @@ public void parseInternal_withCustomRegion_shouldConfigureDefaultClientWithCusto SqsAsyncClient amazonSqs = registry.getBean(SqsAsyncClient.class); SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(amazonSqs, "clientConfiguration"); assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT).toString()) - .isEqualTo(ServiceMetadata.of("sqs").endpointFor(Region.EU_WEST_1)); + .isEqualTo("https://" + ServiceMetadata.of("sqs").endpointFor(Region.EU_WEST_1)); } @Test @@ -126,7 +130,7 @@ public void parseInternal_withCustomRegionProvider_shouldConfigureDefaultClientW SqsAsyncClient amazonSqs = registry.getBean(SqsAsyncClient.class); SdkClientConfiguration clientConfiguration = (SdkClientConfiguration) ReflectionTestUtils.getField(amazonSqs, "clientConfiguration"); assertThat(clientConfiguration.option(SdkClientOption.ENDPOINT).toString()) - .isEqualTo(ServiceMetadata.of("sqs").endpointFor(Region.AP_SOUTHEAST_2)); + .isEqualTo("https://" + ServiceMetadata.of("sqs").endpointFor(Region.AP_SOUTHEAST_2)); } } diff --git a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/TopicMessageChannelTest.java b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/TopicMessageChannelTest.java index eadfc34f6..287c215ae 100644 --- a/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/TopicMessageChannelTest.java +++ b/spring-cloud-aws-messaging/src/test/java/org/springframework/cloud/aws/messaging/core/TopicMessageChannelTest.java @@ -223,7 +223,7 @@ public void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttri // Assert assertThat(sent).isTrue(); assertThat(publishRequestArgumentCaptor.getValue().messageAttributes() - .get(headerName).binaryValue()).isEqualTo(headerValue); + .get(headerName).binaryValue().asByteBuffer()).isEqualTo(headerValue); assertThat(publishRequestArgumentCaptor.getValue().messageAttributes() .get(headerName).dataType()).isEqualTo(MessageAttributeDataTypes.BINARY); } diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-amazon-sqs.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-amazon-sqs.xml index 75781d2d4..6b63e20ec 100644 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-amazon-sqs.xml +++ b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/AnnotationDrivenQueueListenerBeanDefinitionParserTest-custom-amazon-sqs.xml @@ -26,7 +26,7 @@ http://www.springframework.org/schema/cloud/aws/context http://www.springframework.org/schema/cloud/aws/context/spring-cloud-aws-context.xsd"> - + diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customSnsClient.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customSnsClient.xml index fec426a05..8ce397f24 100644 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customSnsClient.xml +++ b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/config/xml/NotificationArgumentResolverBeanDefinitionParserTest-customSnsClient.xml @@ -33,5 +33,5 @@ - + diff --git a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest-context.xml b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest-context.xml index 24c32e153..0a03ae358 100644 --- a/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest-context.xml +++ b/spring-cloud-aws-messaging/src/test/resources/org/springframework/cloud/aws/messaging/endpoint/ComplexNotificationEndpointControllerTest-context.xml @@ -36,7 +36,7 @@ amazon-sns="amazonSns"/> - + - +