#125 - Polishing.

Upgrade to latest R2DBC versions. Reformat code.
This commit is contained in:
Mark Paluch
2019-10-01 10:24:08 +02:00
parent 5b2670ef6f
commit 03ad99540a
3 changed files with 37 additions and 41 deletions

View File

@@ -35,7 +35,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.0.M5</version>
<version>2.2.0.BUILD-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@@ -49,7 +49,13 @@
<dependency>
<groupId>com.github.mp911de.microbenchmark-runner</groupId>
<artifactId>microbenchmark-runner-junit4</artifactId>
<version>0.1.0.RELEASE</version>
<version>0.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>com.github.mp911de.microbenchmark-runner</groupId>
<artifactId>microbenchmark-runner-extras</artifactId>
<version>0.2.0.RELEASE</version>
</dependency>
</dependencies>

View File

@@ -13,7 +13,7 @@
<artifactId>spring-data-benchmark-relational</artifactId>
<name>Spring Data Benchmarks - Relational Microbenchmarks</name>
<properties>
<spring-boot-data-r2dbc.version>0.1.0.BUILD-SNAPSHOT</spring-boot-data-r2dbc.version>
</properties>
@@ -34,44 +34,44 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- R2DBC -->
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
<version>${spring-boot-data-r2dbc.version}</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-h2</artifactId>
<version>0.8.0.M8</version>
<version>0.8.0.RC1</version>
</dependency>
<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<version>0.8.0.M8</version>
<version>0.8.0.RC1</version>
</dependency>
<!-- Mocking -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>com.mockrunner</groupId>
<artifactId>mockrunner-jdbc</artifactId>

View File

@@ -15,62 +15,62 @@
*/
package org.springframework.data.microbenchmark.r2dbc;
import io.r2dbc.spi.Row;
import java.util.function.Function;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.infra.Blackhole;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.microbenchmark.common.AbstractMicrobenchmark;
import org.springframework.data.r2dbc.core.DatabaseClient;
import io.r2dbc.spi.Row;
/**
* Benchmark for R2DBC and Spring Data R2DBC
*
*
* @author Oliver Drotbohm
*/
public class R2dbcBenchmark extends AbstractMicrobenchmark {
private static final String FIND_ALL_SQL = "SELECT id, title, pages FROM Book";
private static final String BY_TITLE_SQL = FIND_ALL_SQL + " where title = :title";
@Param({ /* "postgres", */ "h2-in-memory" /*, "h2" */ })
String profile;
@Param({ /* "postgres", */ "h2-in-memory" /*, "h2" */ }) String profile;
private DatabaseClient operations;
private Function<Row, Book> mapper;
private R2dbcBookRepository repository;
@Setup
public void setUp() {
R2dbcFixture fixture = new R2dbcFixture(profile);
ConfigurableApplicationContext context = fixture.getContext();
this.operations = context.getBean(DatabaseClient.class);
this.mapper = row -> new Book(row.get("id", Long.class), row.get("title", String.class), row.get("pages", Integer.class));
this.mapper = row -> new Book(row.get("id", Long.class), row.get("title", String.class),
row.get("pages", Integer.class));
this.repository = context.getBean(R2dbcBookRepository.class);
}
@Benchmark
public void findByTitle(Blackhole sink) {
sink.consume(operations.execute(BY_TITLE_SQL) //
.bind("title", "title0") //
.map(mapper)
.one() //
.map(mapper).one() //
.block());
}
@Benchmark
public void findAll(Blackhole sink) {
sink.consume(operations.execute(FIND_ALL_SQL) //
.map(mapper) //
.all() //
@@ -82,7 +82,7 @@ public class R2dbcBenchmark extends AbstractMicrobenchmark {
public void repositoryFindByTitle(Blackhole sink) {
sink.consume(repository.findByTitle("title0").block());
}
@Benchmark
public void repositoryFindTransactionalByTitle(Blackhole sink) {
sink.consume(repository.findTransactionalByTitle("title0").block());
@@ -92,14 +92,4 @@ public class R2dbcBenchmark extends AbstractMicrobenchmark {
public void repositoryFindAll(Blackhole sink) {
sink.consume(repository.findAll().collectList().block());
}
public static void main(String[] args) {
new R2dbcFixture("postgres") //
.getContext() //
.getBean(R2dbcBookRepository.class) //
.findAll() //
.collectList() //
.block();
}
}