Upgrade to Spring Boot 3.3

This commit is contained in:
Mark Paluch
2024-03-07 16:09:08 +01:00
parent f7ccf12c73
commit 069c49b57f
10 changed files with 84 additions and 39 deletions

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.data.benchmark</groupId> <groupId>org.springframework.data.benchmark</groupId>
<artifactId>spring-data-benchmark-parent</artifactId> <artifactId>spring-data-benchmark-parent</artifactId>
<version>2.5.0-SNAPSHOT</version> <version>3.3.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>spring-data-benchmark-commons</artifactId> <artifactId>spring-data-benchmark-commons</artifactId>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.data.benchmark</groupId> <groupId>org.springframework.data.benchmark</groupId>
<artifactId>spring-data-benchmark-parent</artifactId> <artifactId>spring-data-benchmark-parent</artifactId>
<version>2.5.0-SNAPSHOT</version> <version>3.3.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>spring-data-benchmark-mongodb</artifactId> <artifactId>spring-data-benchmark-mongodb</artifactId>
@@ -34,6 +34,7 @@
<dependency> <dependency>
<groupId>de.flapdoodle.embed</groupId> <groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId> <artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>4.12.2</version>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
@@ -15,7 +15,8 @@
<parent> <parent>
<groupId>org.springframework.data.build</groupId> <groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId> <artifactId>spring-data-parent</artifactId>
<version>2.5.0-SNAPSHOT</version> <version>3.3.0-SNAPSHOT</version>
<relativePath/>
</parent> </parent>
<modules> <modules>
@@ -27,7 +28,7 @@
</modules> </modules>
<properties> <properties>
<jmh.version>1.19</jmh.version> <jmh.version>1.37</jmh.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@@ -36,7 +37,15 @@
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId> <artifactId>spring-boot-dependencies</artifactId>
<version>2.5.0-SNAPSHOT</version> <version>3.3.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-bom</artifactId>
<version>2024.0.0-SNAPSHOT</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
@@ -50,19 +59,19 @@
<dependency> <dependency>
<groupId>com.github.mp911de.microbenchmark-runner</groupId> <groupId>com.github.mp911de.microbenchmark-runner</groupId>
<artifactId>microbenchmark-runner-junit4</artifactId> <artifactId>microbenchmark-runner-junit4</artifactId>
<version>0.2.0.RELEASE</version> <version>0.4.0.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.mp911de.microbenchmark-runner</groupId> <groupId>com.github.mp911de.microbenchmark-runner</groupId>
<artifactId>microbenchmark-runner-extras</artifactId> <artifactId>microbenchmark-runner-extras</artifactId>
<version>0.2.0.RELEASE</version> <version>0.4.0.RELEASE</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.minidev</groupId> <groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId> <artifactId>json-smart</artifactId>
<version>2.4.4</version> <version>2.5.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -107,10 +116,10 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.10.1</version>
<configuration> <configuration>
<source>1.8</source> <source>17</source>
<target>1.8</target> <target>17</target>
<parameters>true</parameters> <parameters>true</parameters>
</configuration> </configuration>
</plugin> </plugin>
@@ -129,8 +138,10 @@
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<testSourceDirectory>${project.build.sourceDirectory}</testSourceDirectory> <testSourceDirectory>${project.build.sourceDirectory}
<testClassesDirectory>${project.build.outputDirectory}</testClassesDirectory> </testSourceDirectory>
<testClassesDirectory>${project.build.outputDirectory}
</testClassesDirectory>
<excludes> <excludes>
<exclude>**/AbstractMicrobenchmark.java</exclude> <exclude>**/AbstractMicrobenchmark.java</exclude>
<exclude>**/*$*.class</exclude> <exclude>**/*$*.class</exclude>
@@ -140,7 +151,9 @@
<include>**/*Benchmark*</include> <include>**/*Benchmark*</include>
</includes> </includes>
<systemPropertyVariables> <systemPropertyVariables>
<benchmarkReportDir>${project.build.directory}/reports/performance</benchmarkReportDir> <benchmarkReportDir>
${project.build.directory}/reports/performance
</benchmarkReportDir>
<project.version>${project.version}</project.version> <project.version>${project.version}</project.version>
<git.dirty>${git.dirty}</git.dirty> <git.dirty>${git.dirty}</git.dirty>
<git.commit.id>${git.commit.id}</git.commit.id> <git.commit.id>${git.commit.id}</git.commit.id>
@@ -153,9 +166,15 @@
<repositories> <repositories>
<repository> <repository>
<id>spring-libs-snapshot</id> <id>spring-snapshot</id>
<url>https://repo.spring.io/libs-snapshot</url> <url>https://repo.spring.io/snapshot</url>
</repository> </repository>
<repository>
<id>spring-milestone</id>
<url>https://repo.spring.io/milestone</url>
</repository>
<repository> <repository>
<id>jitpack.io</id> <id>jitpack.io</id>
<url>https://jitpack.io</url> <url>https://jitpack.io</url>

View File

@@ -8,7 +8,7 @@
<parent> <parent>
<groupId>org.springframework.data.benchmark</groupId> <groupId>org.springframework.data.benchmark</groupId>
<artifactId>spring-data-benchmark-parent</artifactId> <artifactId>spring-data-benchmark-parent</artifactId>
<version>2.5.0-SNAPSHOT</version> <version>3.3.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>spring-data-benchmark-redis</artifactId> <artifactId>spring-data-benchmark-redis</artifactId>

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.data.benchmark</groupId> <groupId>org.springframework.data.benchmark</groupId>
<artifactId>spring-data-benchmark-parent</artifactId> <artifactId>spring-data-benchmark-parent</artifactId>
<version>2.5.0-SNAPSHOT</version> <version>3.3.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>spring-data-benchmark-relational</artifactId> <artifactId>spring-data-benchmark-relational</artifactId>
@@ -54,7 +54,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.r2dbc</groupId> <groupId>org.postgresql</groupId>
<artifactId>r2dbc-postgresql</artifactId> <artifactId>r2dbc-postgresql</artifactId>
</dependency> </dependency>

View File

@@ -15,6 +15,7 @@
*/ */
package org.springframework.data.microbenchmark.r2dbc; package org.springframework.data.microbenchmark.r2dbc;
import io.r2dbc.spi.Readable;
import io.r2dbc.spi.Row; import io.r2dbc.spi.Row;
import java.util.function.Function; import java.util.function.Function;
@@ -26,7 +27,7 @@ import org.openjdk.jmh.infra.Blackhole;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.microbenchmark.common.AbstractMicrobenchmark; import org.springframework.data.microbenchmark.common.AbstractMicrobenchmark;
import org.springframework.data.r2dbc.core.DatabaseClient; import org.springframework.r2dbc.core.DatabaseClient;
/** /**
* Benchmark for R2DBC and Spring Data R2DBC * Benchmark for R2DBC and Spring Data R2DBC
@@ -41,7 +42,7 @@ public class R2dbcBenchmark extends AbstractMicrobenchmark {
@Param({ /* "postgres", */ "h2-in-memory" /*, "h2" */ }) String profile; @Param({ /* "postgres", */ "h2-in-memory" /*, "h2" */ }) String profile;
private DatabaseClient operations; private DatabaseClient operations;
private Function<Row, Book> mapper; private Function<Readable, Book> mapper;
private R2dbcBookRepository repository; private R2dbcBookRepository repository;
@@ -62,7 +63,7 @@ public class R2dbcBenchmark extends AbstractMicrobenchmark {
@Benchmark @Benchmark
public void findByTitle(Blackhole sink) { public void findByTitle(Blackhole sink) {
sink.consume(operations.execute(BY_TITLE_SQL) // sink.consume(operations.sql(BY_TITLE_SQL) //
.bind("title", "title0") // .bind("title", "title0") //
.map(mapper).one() // .map(mapper).one() //
.block()); .block());
@@ -71,7 +72,7 @@ public class R2dbcBenchmark extends AbstractMicrobenchmark {
@Benchmark @Benchmark
public void findAll(Blackhole sink) { public void findAll(Blackhole sink) {
sink.consume(operations.execute(FIND_ALL_SQL) // sink.consume(operations.sql(FIND_ALL_SQL) //
.map(mapper) // .map(mapper) //
.all() // .all() //
.collectList() // .collectList() //

View File

@@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.data.benchmark</groupId> <groupId>org.springframework.data.benchmark</groupId>
<artifactId>spring-data-benchmark-parent</artifactId> <artifactId>spring-data-benchmark-parent</artifactId>
<version>2.5.0-SNAPSHOT</version> <version>3.3.0-SNAPSHOT</version>
</parent> </parent>
<artifactId>spring-data-benchmark-support</artifactId> <artifactId>spring-data-benchmark-support</artifactId>

View File

@@ -31,8 +31,8 @@ import org.openjdk.jmh.annotations.Warmup;
* @author Mark Paluch * @author Mark Paluch
* @see Microbenchmark * @see Microbenchmark
*/ */
@Warmup(iterations = 10) @Warmup(iterations = 10, time = 2)
@Measurement(iterations = 10) @Measurement(iterations = 10, time = 2)
@Fork(value = 1, jvmArgs = { "-server", "-XX:+HeapDumpOnOutOfMemoryError", "-Xms1024m", "-Xmx1024m", @Fork(value = 1, jvmArgs = { "-server", "-XX:+HeapDumpOnOutOfMemoryError", "-Xms1024m", "-Xmx1024m",
"-XX:MaxDirectMemorySize=1024m", "-noverify" }) "-XX:MaxDirectMemorySize=1024m", "-noverify" })
@State(Scope.Thread) @State(Scope.Thread)

View File

@@ -16,10 +16,13 @@
package org.springframework.data.microbenchmark.common; package org.springframework.data.microbenchmark.common;
import jmh.mbr.core.ResultsWriter; import jmh.mbr.core.ResultsWriter;
import jmh.mbr.core.model.BenchmarkResults;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
@@ -27,7 +30,10 @@ import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.util.Collection; import java.util.Collection;
import lombok.SneakyThrows;
import org.openjdk.jmh.results.RunResult; import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.results.format.ResultFormatFactory;
import org.openjdk.jmh.results.format.ResultFormatType;
import org.openjdk.jmh.runner.format.OutputFormat; import org.openjdk.jmh.runner.format.OutputFormat;
import org.springframework.core.env.StandardEnvironment; import org.springframework.core.env.StandardEnvironment;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@@ -43,17 +49,18 @@ class HttpResultsWriter implements ResultsWriter {
private final String url; private final String url;
@Override
public void write(OutputFormat output, Collection<RunResult> results) {
if (CollectionUtils.isEmpty(results)) { @Override
public void write(OutputFormat output, BenchmarkResults benchmarkResults) {
if (CollectionUtils.isEmpty(benchmarkResults.getRawResults())) {
return; return;
} }
try { try {
doWrite(results); doWrite(benchmarkResults.getRawResults());
} catch (IOException e) { } catch (IOException e) {
output.println("Failed to write results: " + e.toString()); output.println("Failed to write results: " + e);
} }
} }
@@ -79,7 +86,7 @@ class HttpResultsWriter implements ResultsWriter {
connection.addRequestProperty("X-Git-Commit-Id", gitCommitId); connection.addRequestProperty("X-Git-Commit-Id", gitCommitId);
try (OutputStream output = connection.getOutputStream()) { try (OutputStream output = connection.getOutputStream()) {
output.write(ResultsWriter.jsonifyResults(results).getBytes(StandardCharsets.UTF_8)); output.write(jsonifyResults(results).getBytes(StandardCharsets.UTF_8));
} }
if (connection.getResponseCode() >= 400) { if (connection.getResponseCode() >= 400) {
@@ -87,4 +94,20 @@ class HttpResultsWriter implements ResultsWriter {
String.format("Status %d %s", connection.getResponseCode(), connection.getResponseMessage())); String.format("Status %d %s", connection.getResponseCode(), connection.getResponseMessage()));
} }
} }
/**
* Convert {@link RunResult}s to JMH Json representation.
*
* @param results
* @return json string representation of results.
* @see org.openjdk.jmh.results.format.JSONResultFormat
*/
@SneakyThrows
static String jsonifyResults(Collection<RunResult> results) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ResultFormatFactory.getInstance(ResultFormatType.JSON, new PrintStream(baos, true, "UTF-8")).writeOut(results);
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
}
} }

View File

@@ -16,6 +16,7 @@
package org.springframework.data.microbenchmark.common; package org.springframework.data.microbenchmark.common;
import jmh.mbr.core.ResultsWriter; import jmh.mbr.core.ResultsWriter;
import jmh.mbr.core.model.BenchmarkResults;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.minidev.json.JSONArray; import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject; import net.minidev.json.JSONObject;
@@ -52,14 +53,14 @@ class MongoResultsWriter implements ResultsWriter {
private final String uri; private final String uri;
@Override @Override
public void write(OutputFormat output, Collection<RunResult> results) { public void write(OutputFormat output, BenchmarkResults benchmarkResults) {
if (CollectionUtils.isEmpty(results)) { if (CollectionUtils.isEmpty(benchmarkResults.getRawResults())) {
return; return;
} }
try { try {
doWrite(results); doWrite(benchmarkResults.getRawResults());
} catch (ParseException | RuntimeException e) { } catch (ParseException | RuntimeException e) {
output.println("Failed to write results: " + e.toString()); output.println("Failed to write results: " + e.toString());
} }
@@ -81,7 +82,7 @@ class MongoResultsWriter implements ResultsWriter {
String dbName = StringUtils.hasText(uri.getDatabase()) ? uri.getDatabase() : "spring-data-mongodb-benchmarks"; String dbName = StringUtils.hasText(uri.getDatabase()) ? uri.getDatabase() : "spring-data-mongodb-benchmarks";
MongoDatabase db = client.getDatabase(dbName); MongoDatabase db = client.getDatabase(dbName);
String resultsJson = ResultsWriter.jsonifyResults(results).trim(); String resultsJson = HttpResultsWriter.jsonifyResults(results).trim();
JSONArray array = (JSONArray) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(resultsJson); JSONArray array = (JSONArray) new JSONParser(JSONParser.MODE_PERMISSIVE).parse(resultsJson);
for (Object object : array) { for (Object object : array) {
JSONObject dbo = (JSONObject) object; JSONObject dbo = (JSONObject) object;