Add jdbc-mariadb smoke test

Closes gh-85
This commit is contained in:
Moritz Halbritter
2022-08-10 15:02:48 +02:00
parent e12ffe1f6d
commit 3b80aae769
12 changed files with 154 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ smoke_tests:
- freemarker-webmvc
- hateoas
- jdbc-h2
- jdbc-mariadb
- jdbc-mysql
- jdbc-postgresql
- liquibase

1
jdbc-mariadb/README.adoc Normal file
View File

@@ -0,0 +1 @@
Tests if JDBC with MariaDB is working

18
jdbc-mariadb/build.gradle Normal file
View File

@@ -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")
}

View File

@@ -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'

View File

@@ -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]"));
}
}

View File

@@ -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<Author> {
INSTANCE;
@Override
public Author mapRow(ResultSet rs, int rowNum) throws SQLException {
return new Author(rs.getInt("id"), rs.getString("name"));
}
}
}

View File

@@ -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<Author> 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<String> authors = List.of("mbhave", "snicoll", "wilkinsona");
for (String author : authors) {
this.jdbcTemplate.update("INSERT INTO authors (name) VALUES (?)", author);
}
}
}

View File

@@ -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
}
}

View File

@@ -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

View File

@@ -0,0 +1,5 @@
CREATE TABLE authors
(
id integer PRIMARY KEY AUTO_INCREMENT,
name varchar(50) NOT NULL
);

View File

@@ -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() {
}
}

View File

@@ -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"