diff --git a/ci/smoke-tests.yml b/ci/smoke-tests.yml index 29b36f5f..1d34fd4e 100644 --- a/ci/smoke-tests.yml +++ b/ci/smoke-tests.yml @@ -34,6 +34,7 @@ smoke_tests: - freemarker-webmvc - hateoas - jdbc-h2 + - jdbc-mariadb - jdbc-mysql - jdbc-postgresql - liquibase diff --git a/jdbc-mariadb/README.adoc b/jdbc-mariadb/README.adoc new file mode 100644 index 00000000..deadb682 --- /dev/null +++ b/jdbc-mariadb/README.adoc @@ -0,0 +1 @@ +Tests if JDBC with MariaDB is working diff --git a/jdbc-mariadb/build.gradle b/jdbc-mariadb/build.gradle new file mode 100644 index 00000000..885adaee --- /dev/null +++ b/jdbc-mariadb/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'java' + id 'org.springframework.boot' + id 'org.springframework.aot.smoke-test' + id 'org.graalvm.buildtools.native' +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-jdbc") + implementation(project(":aot-smoke-test-third-party-hints")) + runtimeOnly("org.mariadb.jdbc:mariadb-java-client") + + testImplementation("org.springframework.boot:spring-boot-starter-test") + + aotTestImplementation(project(":aot-smoke-test-support")) + aotTestImplementation("org.awaitility:awaitility:4.2.0") +} diff --git a/jdbc-mariadb/docker-compose.yml b/jdbc-mariadb/docker-compose.yml new file mode 100644 index 00000000..3b9cc43f --- /dev/null +++ b/jdbc-mariadb/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.1' +services: + mariadb: + image: 'mariadb:10.8' + environment: + - 'MARIADB_DATABASE=test' + - 'MARIADB_USER=mariadb' + - 'MARIADB_PASSWORD=password' + - 'MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=true' + ports: + - '3306' diff --git a/jdbc-mariadb/src/aotTest/java/com/example/jdbc/mariadb/JdbcMariaDBApplicationAotTests.java b/jdbc-mariadb/src/aotTest/java/com/example/jdbc/mariadb/JdbcMariaDBApplicationAotTests.java new file mode 100644 index 00000000..143ecaa2 --- /dev/null +++ b/jdbc-mariadb/src/aotTest/java/com/example/jdbc/mariadb/JdbcMariaDBApplicationAotTests.java @@ -0,0 +1,24 @@ +package com.example.jdbc.mariadb; + +import java.time.Duration; + +import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; + +import org.springframework.aot.smoketest.support.assertj.AssertableOutput; +import org.springframework.aot.smoketest.support.junit.AotSmokeTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@AotSmokeTest +class JdbcMariaDBApplicationAotTests { + + @Test + void authorsCanBeQueried(AssertableOutput output) { + Awaitility.await().atMost(Duration.ofSeconds(10)).untilAsserted( + () -> assertThat(output).hasSingleLineContaining("Found author: Author[id=1, name=mbhave]") + .hasSingleLineContaining("Found author: Author[id=2, name=snicoll]") + .hasSingleLineContaining("Found author: Author[id=3, name=wilkinsona]")); + } + +} diff --git a/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/Author.java b/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/Author.java new file mode 100644 index 00000000..b010e5c2 --- /dev/null +++ b/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/Author.java @@ -0,0 +1,19 @@ +package com.example.jdbc.mariadb; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.springframework.jdbc.core.RowMapper; + +record Author(long id, String name) { + enum Mapper implements RowMapper { + + INSTANCE; + + @Override + public Author mapRow(ResultSet rs, int rowNum) throws SQLException { + return new Author(rs.getInt("id"), rs.getString("name")); + } + + } +} diff --git a/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/CLR.java b/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/CLR.java new file mode 100644 index 00000000..74d2b195 --- /dev/null +++ b/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/CLR.java @@ -0,0 +1,39 @@ +package com.example.jdbc.mariadb; + +import java.util.List; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Component; + +@Component +public class CLR implements CommandLineRunner { + + private final JdbcTemplate jdbcTemplate; + + public CLR(JdbcTemplate jdbcTemplate) { + this.jdbcTemplate = jdbcTemplate; + } + + @Override + public void run(String... args) { + insertAuthors(); + queryAuthors(); + } + + private void queryAuthors() { + List authors = jdbcTemplate.query("SELECT * FROM authors", Author.Mapper.INSTANCE); + for (Author author : authors) { + System.out.printf("Found author: %s%n", author); + } + } + + private void insertAuthors() { + List authors = List.of("mbhave", "snicoll", "wilkinsona"); + + for (String author : authors) { + this.jdbcTemplate.update("INSERT INTO authors (name) VALUES (?)", author); + } + } + +} diff --git a/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/JdbcMariaDBApplication.java b/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/JdbcMariaDBApplication.java new file mode 100644 index 00000000..796c7c37 --- /dev/null +++ b/jdbc-mariadb/src/main/java/com/example/jdbc/mariadb/JdbcMariaDBApplication.java @@ -0,0 +1,17 @@ +package com.example.jdbc.mariadb; + +import org.springframework.aot.smoketest.thirdpartyhints.HikariRuntimeHints; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ImportRuntimeHints; + +@SpringBootApplication +@ImportRuntimeHints(HikariRuntimeHints.class) +public class JdbcMariaDBApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(JdbcMariaDBApplication.class, args); + Thread.currentThread().join(); // To be able to measure memory consumption + } + +} diff --git a/jdbc-mariadb/src/main/resources/application.properties b/jdbc-mariadb/src/main/resources/application.properties new file mode 100644 index 00000000..0b4e06b4 --- /dev/null +++ b/jdbc-mariadb/src/main/resources/application.properties @@ -0,0 +1,4 @@ +spring.sql.init.mode=always +spring.datasource.url=jdbc:mariadb://${MARIADB_HOST:localhost}:${MARIADB_PORT_3306:3306}/test +spring.datasource.username=mariadb +spring.datasource.password=password diff --git a/jdbc-mariadb/src/main/resources/schema.sql b/jdbc-mariadb/src/main/resources/schema.sql new file mode 100644 index 00000000..d3ebac7f --- /dev/null +++ b/jdbc-mariadb/src/main/resources/schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE authors +( + id integer PRIMARY KEY AUTO_INCREMENT, + name varchar(50) NOT NULL +); diff --git a/jdbc-mariadb/src/test/java/com/example/jdbc/mariadb/JdbcMariaDBApplicationTests.java b/jdbc-mariadb/src/test/java/com/example/jdbc/mariadb/JdbcMariaDBApplicationTests.java new file mode 100644 index 00000000..ca9e8a32 --- /dev/null +++ b/jdbc-mariadb/src/test/java/com/example/jdbc/mariadb/JdbcMariaDBApplicationTests.java @@ -0,0 +1,14 @@ +package com.example.jdbc.mariadb; + +import org.junit.jupiter.api.Test; + +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class JdbcMariaDBApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/settings.gradle b/settings.gradle index 0d5f0706..8a892722 100644 --- a/settings.gradle +++ b/settings.gradle @@ -62,6 +62,7 @@ include "freemarker-webflux" include "freemarker-webmvc" include "hateoas" include "jdbc-h2" +include "jdbc-mariadb" include "jdbc-mysql" include "jdbc-postgresql" include "liquibase"