From fa3957092af5fbee2eb4109c8ba5f4d0f60f2003 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Mon, 16 Dec 2024 16:30:09 +0000 Subject: [PATCH] feat : upgrade to spring cloud 2024.0.0.0 and localstack to 4.0.3 --- .../producer/docker/docker-compose.yml | 2 +- aws-kinesis-project/producer/pom.xml | 4 +- .../TestKinesisProducerApplication.java | 43 +--------------- .../common/AbstractIntegrationTest.java | 3 +- .../aws/spring/common/ContainerConfig.java | 50 +++++++++++++++++++ 5 files changed, 56 insertions(+), 46 deletions(-) create mode 100644 aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/ContainerConfig.java diff --git a/aws-kinesis-project/producer/docker/docker-compose.yml b/aws-kinesis-project/producer/docker/docker-compose.yml index f9debaf1..29fe58bb 100644 --- a/aws-kinesis-project/producer/docker/docker-compose.yml +++ b/aws-kinesis-project/producer/docker/docker-compose.yml @@ -2,7 +2,7 @@ version: '3.8' services: localstack: - image: localstack/localstack:3.8.1 + image: localstack/localstack:4.0.3 ports: - "4566:4566" environment: diff --git a/aws-kinesis-project/producer/pom.xml b/aws-kinesis-project/producer/pom.xml index 7a1ee9cd..2414159e 100644 --- a/aws-kinesis-project/producer/pom.xml +++ b/aws-kinesis-project/producer/pom.xml @@ -20,7 +20,7 @@ UTF-8 21 - 2023.0.4 + 2024.0.0 2.7.0 ${project.build.directory}/test-results @@ -223,7 +223,7 @@ - 1.22.0 + 1.25.0 diff --git a/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/TestKinesisProducerApplication.java b/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/TestKinesisProducerApplication.java index 0e284903..78d4451a 100644 --- a/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/TestKinesisProducerApplication.java +++ b/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/TestKinesisProducerApplication.java @@ -1,52 +1,13 @@ package com.learning.aws.spring; -import static org.testcontainers.containers.localstack.LocalStackContainer.Service.KINESIS; - +import com.learning.aws.spring.common.ContainerConfig; import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.context.TestConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.DynamicPropertyRegistry; -import org.testcontainers.containers.localstack.LocalStackContainer; -import org.testcontainers.utility.DockerImageName; -import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; -import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; -import software.amazon.awssdk.regions.Region; -import software.amazon.awssdk.services.kinesis.KinesisAsyncClient; -@TestConfiguration(proxyBeanMethods = false) public class TestKinesisProducerApplication { - @Bean - LocalStackContainer localStackContainer(DynamicPropertyRegistry dynamicPropertyRegistry) { - LocalStackContainer localStackContainer = - new LocalStackContainer( - DockerImageName.parse("localstack/localstack").withTag("3.7.2")); - dynamicPropertyRegistry.add("spring.cloud.aws.endpoint", localStackContainer::getEndpoint); - dynamicPropertyRegistry.add( - "spring.cloud.aws.region.static", localStackContainer::getRegion); - dynamicPropertyRegistry.add( - "spring.cloud.aws.access-key", localStackContainer::getAccessKey); - dynamicPropertyRegistry.add( - "spring.cloud.aws.secret-key", localStackContainer::getSecretKey); - return localStackContainer; - } - - @Bean - KinesisAsyncClient amazonKinesis(LocalStackContainer localStackContainer) { - return KinesisAsyncClient.builder() - .endpointOverride(localStackContainer.getEndpointOverride(KINESIS)) - .region(Region.of(localStackContainer.getRegion())) - .credentialsProvider( - StaticCredentialsProvider.create( - AwsBasicCredentials.create( - localStackContainer.getAccessKey(), - localStackContainer.getSecretKey()))) - .build(); - } - public static void main(String[] args) { SpringApplication.from(KinesisProducerApplication::main) - .with(TestKinesisProducerApplication.class) + .with(ContainerConfig.class) .run(args); } } diff --git a/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/AbstractIntegrationTest.java b/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/AbstractIntegrationTest.java index c99e73d7..6297ba0b 100644 --- a/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/AbstractIntegrationTest.java +++ b/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/AbstractIntegrationTest.java @@ -4,7 +4,6 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; import com.fasterxml.jackson.databind.ObjectMapper; -import com.learning.aws.spring.TestKinesisProducerApplication; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -12,7 +11,7 @@ import org.springframework.test.web.servlet.MockMvc; @ActiveProfiles({PROFILE_TEST}) -@SpringBootTest(webEnvironment = RANDOM_PORT, classes = TestKinesisProducerApplication.class) +@SpringBootTest(webEnvironment = RANDOM_PORT, classes = ContainerConfig.class) @AutoConfigureMockMvc public abstract class AbstractIntegrationTest { diff --git a/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/ContainerConfig.java b/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/ContainerConfig.java new file mode 100644 index 00000000..24595268 --- /dev/null +++ b/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/ContainerConfig.java @@ -0,0 +1,50 @@ +package com.learning.aws.spring.common; + +import static org.testcontainers.containers.localstack.LocalStackContainer.Service.KINESIS; + +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.DynamicPropertyRegistrar; +import org.testcontainers.containers.localstack.LocalStackContainer; +import org.testcontainers.utility.DockerImageName; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.kinesis.KinesisAsyncClient; + +@TestConfiguration(proxyBeanMethods = false) +public class ContainerConfig { + + @Bean + LocalStackContainer localStackContainer() { + return new LocalStackContainer( + DockerImageName.parse("localstack/localstack").withTag("4.0.3")); + } + + @Bean + DynamicPropertyRegistrar dynamicPropertyRegistrar(LocalStackContainer localStackContainer) { + return dynamicPropertyRegistry -> { + dynamicPropertyRegistry.add( + "spring.cloud.aws.endpoint", localStackContainer::getEndpoint); + dynamicPropertyRegistry.add( + "spring.cloud.aws.region.static", localStackContainer::getRegion); + dynamicPropertyRegistry.add( + "spring.cloud.aws.access-key", localStackContainer::getAccessKey); + dynamicPropertyRegistry.add( + "spring.cloud.aws.secret-key", localStackContainer::getSecretKey); + }; + } + + @Bean + KinesisAsyncClient amazonKinesis(LocalStackContainer localStackContainer) { + return KinesisAsyncClient.builder() + .endpointOverride(localStackContainer.getEndpointOverride(KINESIS)) + .region(Region.of(localStackContainer.getRegion())) + .credentialsProvider( + StaticCredentialsProvider.create( + AwsBasicCredentials.create( + localStackContainer.getAccessKey(), + localStackContainer.getSecretKey()))) + .build(); + } +}