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..01f1e6b3
--- /dev/null
+++ b/aws-kinesis-project/producer/src/test/java/com/learning/aws/spring/common/ContainerConfig.java
@@ -0,0 +1,63 @@
+package com.learning.aws.spring.common;
+
+import static org.testcontainers.containers.localstack.LocalStackContainer.Service.KINESIS;
+
+import java.time.Duration;
+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.core.client.config.ClientOverrideConfiguration;
+import software.amazon.awssdk.core.retry.RetryPolicy;
+import software.amazon.awssdk.regions.Region;
+import software.amazon.awssdk.services.kinesis.KinesisAsyncClient;
+
+/**
+ * Test configuration for AWS services using LocalStack. This class centralizes the LocalStack
+ * container configuration and provides necessary beans for AWS integration testing.
+ */
+@TestConfiguration(proxyBeanMethods = false)
+public class ContainerConfig {
+
+ @Bean
+ LocalStackContainer localStackContainer() {
+ return new LocalStackContainer(
+ DockerImageName.parse("localstack/localstack").withTag("4.0.3"))
+ .withServices(KINESIS);
+ }
+
+ @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())))
+ .overrideConfiguration(
+ ClientOverrideConfiguration.builder()
+ .apiCallTimeout(Duration.ofSeconds(10))
+ .retryPolicy(RetryPolicy.builder().numRetries(3).build())
+ .build())
+ .build();
+ }
+}