Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : upgrade to spring boot 3.4.0-RC1 #886

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions catalog-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.5</version>
<version>3.4.0-RC1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example.catalogservice</groupId>
Expand All @@ -20,8 +20,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>21</java.version>
<spring-cloud.version>2023.0.3</spring-cloud.version>
<springdoc-openapi.version>2.6.0</springdoc-openapi.version>
<spring-cloud.version>2024.0.0-RC1</spring-cloud.version>
<springdoc-openapi.version>2.7.0-RC1</springdoc-openapi.version>

<org.mapstruct.version>1.6.3</org.mapstruct.version>

Expand Down Expand Up @@ -90,11 +90,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>provided</scope>
</dependency>

<!-- To fix Spring Cloud LoadBalancer is currently working with the default
cache.
Expand Down Expand Up @@ -229,11 +224,13 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.12.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<version>4.12.0</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -507,7 +504,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.24.0</version>
<style>AOSP</style>
</googleJavaFormat>
<licenseHeader> <!-- specify either content or file, but not both -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,17 @@ Licensed under MIT License Copyright (c) 2023-2024 Raja Kolli.

package com.example.catalogservice;

import com.example.catalogservice.common.ContainersConfig;
import com.example.catalogservice.common.SQLContainerConfig;
import com.example.catalogservice.utils.AppConstants;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class TestCatalogServiceApplication {

@Bean
@ServiceConnection(name = "openzipkin/zipkin")
GenericContainer<?> zipkinContainer() {
return new GenericContainer<>(DockerImageName.parse("openzipkin/zipkin:latest"))
.withExposedPorts(9411)
.withReuse(true);
}

@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSqlContainer() {
return new PostgreSQLContainer<>("postgres:17-alpine").withReuse(true);
}

@Bean
@ServiceConnection
KafkaContainer kafkaContainer(DynamicPropertyRegistry dynamicPropertyRegistry) {
KafkaContainer kafkaContainer =
new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("7.6.2"))
.withKraft()
.withReuse(true);
dynamicPropertyRegistry.add(
"spring.cloud.stream.kafka.binder.brokers", kafkaContainer::getBootstrapServers);
return kafkaContainer;
}

public static void main(String[] args) {
System.setProperty("spring.profiles.active", "test");
SpringApplication.from(CatalogServiceApplication::main)
.with(TestCatalogServiceApplication.class)
.with(ContainersConfig.class, SQLContainerConfig.class)
.withAdditionalProfiles(AppConstants.PROFILE_TEST)
.run(args);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
<p>
Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
Licensed under MIT License Copyright (c) 2021-2024 Raja Kolli.
</p>
***/

Expand All @@ -9,7 +9,6 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
import static com.example.catalogservice.utils.AppConstants.PROFILE_TEST;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import com.example.catalogservice.TestCatalogServiceApplication;
import com.example.catalogservice.config.TestKafkaListenerConfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry;
Expand All @@ -24,7 +23,7 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
@SpringBootTest(
webEnvironment = RANDOM_PORT,
properties = {"spring.cloud.config.enabled=false"},
classes = {TestCatalogServiceApplication.class, TestKafkaListenerConfig.class})
classes = {SQLContainerConfig.class, TestKafkaListenerConfig.class, ContainersConfig.class})
@AutoConfigureWebTestClient
@AutoConfigureObservability(tracing = false)
public abstract class AbstractIntegrationTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/***
<p>
Licensed under MIT License Copyright (c) 2024 Raja Kolli.
</p>
***/

package com.example.catalogservice.common;

import org.springframework.boot.devtools.restart.RestartScope;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistrar;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.kafka.KafkaContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class ContainersConfig {

@Bean
@ServiceConnection
@RestartScope
KafkaContainer kafkaContainer() {
return new KafkaContainer(DockerImageName.parse("apache/kafka-native").withTag("3.8.1"))
.withReuse(true);
}

@Bean
@ServiceConnection(name = "openzipkin/zipkin")
GenericContainer<?> zipkinContainer() {
return new GenericContainer<>(DockerImageName.parse("openzipkin/zipkin:latest"))
.withExposedPorts(9411)
.withReuse(true);
Comment on lines +32 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Pin the Zipkin image version for reproducible builds

Using the latest tag can lead to inconsistent behavior across different environments as the image version may change unexpectedly.

Apply this diff to pin the Zipkin image version:

-                .withExposedPorts(9411)
-                .withReuse(true);
+                .withExposedPorts(9411)
+                .withReuse(true)
+                .withImagePullPolicy(PullPolicy.alwaysLocal());

Also, update the image tag to a specific version:

-DockerImageName.parse("openzipkin/zipkin:latest")
+DockerImageName.parse("openzipkin/zipkin:2.24")  // Use appropriate version

Committable suggestion skipped: line range outside the PR's diff.

}

@Bean
DynamicPropertyRegistrar kafkaProperties(KafkaContainer kafkaContainer) {
return props ->
props.add(
"spring.cloud.stream.kafka.binder.brokers",
kafkaContainer::getBootstrapServers);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/***
<p>
Licensed under MIT License Copyright (c) 2024 Raja Kolli.
</p>
***/

package com.example.catalogservice.common;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class SQLContainerConfig {

@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.1-alpine"))
.withDatabaseName("catalog-service")
.withReuse(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***
<p>
Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
Licensed under MIT License Copyright (c) 2021-2024 Raja Kolli.
</p>
***/

Expand All @@ -25,11 +25,11 @@ Licensed under MIT License Copyright (c) 2021-2023 Raja Kolli.
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;

Expand All @@ -39,7 +39,7 @@ class ProductControllerTest {

@Autowired private WebTestClient webTestClient;

@MockBean private ProductService productService;
@MockitoBean private ProductService productService;

private List<ProductResponse> productResponseList;

Expand Down