Skip to content

Commit 5ba3130

Browse files
committed
[#1654] Upgrade MariaDB docker image to 10.11.3
1 parent 2e55840 commit 5ba3130

File tree

5 files changed

+214
-4
lines changed

5 files changed

+214
-4
lines changed

hibernate-reactive-core/src/test/java/org/hibernate/reactive/containers/MariaDatabase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MariaDatabase extends MySQLDatabase {
2121
* TIP: To reuse the same containers across multiple runs, set `testcontainers.reuse.enable=true` in a file located
2222
* at `$HOME/.testcontainers.properties` (create the file if it does not exist).
2323
*/
24-
public static final MariaDBContainer<?> maria = new MariaDBContainer<>( imageName( "mariadb", "10.11.2" ) )
24+
public static final MariaDBContainer<?> maria = new MariaDBContainer<>( imageName( "mariadb", "10.11.3" ) )
2525
.withUsername( DatabaseConfiguration.USERNAME )
2626
.withPassword( DatabaseConfiguration.PASSWORD )
2727
.withDatabaseName( DatabaseConfiguration.DB_NAME )

mytest.java

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
///usr/bin/env jbang "$0" "$@" ; exit $?
2+
/* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
* Copyright: Red Hat Inc. and Hibernate Authors
6+
*/
7+
8+
//DEPS io.vertx:vertx-mysql-client:${vertx.version:4.4.2}
9+
//DEPS io.vertx:vertx-unit:${vertx.version:4.4.2}
10+
//DEPS org.hibernate.reactive:hibernate-reactive-core:${hibernate-reactive.version:2.0.0.Final}
11+
//DEPS org.assertj:assertj-core:3.24.2
12+
//DEPS junit:junit:4.13.2
13+
//DEPS org.testcontainers:mariadb:1.18.3
14+
//DEPS org.slf4j:slf4j-simple:2.0.7
15+
16+
//// Testcontainer needs the JDBC drivers to start the container
17+
//// Hibernate Reactive doesn't need it
18+
//DEPS org.mariadb.jdbc:mariadb-java-client:3.1.4
19+
20+
import jakarta.persistence.Entity;
21+
import jakarta.persistence.Id;
22+
23+
import org.hibernate.boot.registry.StandardServiceRegistry;
24+
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
25+
import org.hibernate.cfg.Configuration;
26+
import org.hibernate.reactive.mutiny.Mutiny;
27+
import org.hibernate.reactive.provider.ReactiveServiceRegistryBuilder;
28+
import org.hibernate.reactive.provider.Settings;
29+
30+
import org.junit.After;
31+
import org.junit.Before;
32+
import org.junit.BeforeClass;
33+
import org.junit.ClassRule;
34+
import org.junit.Test;
35+
import org.junit.runner.JUnitCore;
36+
import org.junit.runner.Result;
37+
import org.junit.runner.RunWith;
38+
import org.junit.runner.notification.Failure;
39+
40+
import io.vertx.ext.unit.Async;
41+
import io.vertx.ext.unit.TestContext;
42+
import io.vertx.ext.unit.junit.VertxUnitRunner;
43+
import org.testcontainers.containers.MariaDBContainer;
44+
import org.testcontainers.utility.DockerImageName;
45+
46+
import static org.assertj.core.api.Assertions.assertThat;
47+
48+
//DESCRIPTION An example of a JUnit test class for Hibernate Reactive using
49+
//DESCRIPTION [Vert.x Unit](https://vertx.io/docs/vertx-unit/java),
50+
//DESCRIPTION [Testcontainers](https://www.testcontainers.org)
51+
//DESCRIPTION and [MySQL](https://www.mysql.com/)
52+
//DESCRIPTION that you can run using [JBang](JBang).
53+
//DESCRIPTION
54+
//DESCRIPTION Before running the tests, Testcontainers will start the selected
55+
//DESCRIPTION Docker image with the required database created.
56+
//DESCRIPTION
57+
//DESCRIPTION Usage example:
58+
//DESCRIPTION 1. Use as jbang template `jbang init -t mariadb-reproducer@hibernate/hibernate-reactive mytest.java`
59+
//DESCRIPTION 2. Run the test with JBang: `jbang mytest.java`
60+
//DESCRIPTION 3. (Optional) Edit the file (with IntelliJ IDEA for example):
61+
//DESCRIPTION jbang edit --live --open=idea mytest.java
62+
@RunWith(VertxUnitRunner.class)
63+
public class mytest {
64+
65+
public static DockerImageName imageName(String registry, String image, String version) {
66+
return DockerImageName
67+
.parse( registry + "/" + image + ":" + version )
68+
.asCompatibleSubstituteFor( image );
69+
}
70+
71+
@ClassRule
72+
public final static MariaDBContainer<?> database = new MariaDBContainer<>( imageName( "docker.io", "mariadb", "10.11.3" ) );
73+
74+
private Mutiny.SessionFactory sessionFactory;
75+
76+
@BeforeClass
77+
public static void startContainer() {
78+
database.start();
79+
}
80+
81+
/**
82+
* The {@link Configuration} for the {@link Mutiny.SessionFactory}.
83+
*/
84+
private Configuration createConfiguration() {
85+
Configuration configuration = new Configuration();
86+
87+
// JDBC url
88+
configuration.setProperty( Settings.URL, database.getJdbcUrl() );
89+
90+
// Credentials
91+
configuration.setProperty( Settings.USER, database.getUsername() );
92+
configuration.setProperty( Settings.PASS, database.getPassword() );
93+
94+
// Schema generation. Supported values are create, drop, create-drop, drop-create, none
95+
configuration.setProperty( Settings.HBM2DDL_AUTO, "create" );
96+
97+
// Register new entity classes here
98+
configuration.addAnnotatedClass( MyEntity.class );
99+
100+
// (Optional) Log the SQL queries
101+
configuration.setProperty( Settings.SHOW_SQL, "true" );
102+
configuration.setProperty( Settings.HIGHLIGHT_SQL, "true" );
103+
configuration.setProperty( Settings.FORMAT_SQL, "true" );
104+
return configuration;
105+
}
106+
107+
/*
108+
* Create a new factory and a new schema before each test (see
109+
* property `hibernate.hbm2ddl.auto`).
110+
* This way each test will start with a clean database.
111+
*
112+
* The drawback is that, in a real case scenario with multiple tests,
113+
* it can slow down the whole test suite considerably. If that happens,
114+
* it's possible to make the session factory static and, if necessary,
115+
* delete the content of the tables manually (without dropping them).
116+
*/
117+
@Before
118+
public void createSessionFactory() {
119+
Configuration configuration = createConfiguration();
120+
StandardServiceRegistryBuilder builder = new ReactiveServiceRegistryBuilder()
121+
.applySettings( configuration.getProperties() );
122+
StandardServiceRegistry registry = builder.build();
123+
124+
sessionFactory = configuration.buildSessionFactory( registry )
125+
.unwrap( Mutiny.SessionFactory.class );
126+
}
127+
128+
@Test
129+
public void testInsertAndSelect(TestContext context) {
130+
// the test will wait until async.complete or context.fail are called
131+
Async async = context.async();
132+
133+
MyEntity entity = new MyEntity( "first entity", 1 );
134+
sessionFactory
135+
// insert the entity in the database
136+
.withTransaction( (session, tx) -> session.persist( entity ) )
137+
.chain( () -> sessionFactory
138+
.withSession( session -> session
139+
// look for the entity by id
140+
.find( MyEntity.class, entity.getId() )
141+
// assert that the returned entity is the right one
142+
.invoke( foundEntity -> assertThat( foundEntity.getName() ).isEqualTo( entity.getName() ) ) ) )
143+
.subscribe()
144+
.with( res -> async.complete(), context::fail );
145+
}
146+
147+
@After
148+
public void closeFactory() {
149+
if ( sessionFactory != null ) {
150+
sessionFactory.close();
151+
}
152+
}
153+
154+
/**
155+
* Example of a class representing an entity.
156+
* <p>
157+
* If you create new entities, be sure to add them in .
158+
* For example:
159+
* <pre>
160+
* configuration.addAnnotatedClass( MyOtherEntity.class );
161+
* </pre>
162+
*/
163+
@Entity(name = "MyEntity")
164+
public static class MyEntity {
165+
@Id
166+
public Integer id;
167+
168+
public String name;
169+
170+
public MyEntity() {
171+
}
172+
173+
public MyEntity(String name, Integer id) {
174+
this.name = name;
175+
this.id = id;
176+
}
177+
178+
public Integer getId() {
179+
return id;
180+
}
181+
182+
public String getName() {
183+
return name;
184+
}
185+
186+
@Override
187+
public String toString() {
188+
return "MyEntity"
189+
+ "\n\t id = " + id
190+
+ "\n\t name = " + name;
191+
}
192+
}
193+
194+
// This main class is only for JBang so that it can run the tests with `jbang mytest.java`
195+
public static void main(String[] args) {
196+
System.out.println( "Starting the test suite with MariaDB");
197+
198+
Result result = JUnitCore.runClasses( mytest.class );
199+
200+
for ( Failure failure : result.getFailures() ) {
201+
System.out.println();
202+
System.err.println( "Test " + failure.getTestHeader() + " FAILED!" );
203+
System.err.println( "\t" + failure.getTrace() );
204+
}
205+
206+
System.out.println();
207+
System.out.print("Tests result summary: ");
208+
System.out.println( result.wasSuccessful() ? "SUCCESS" : "FAILURE" );
209+
}
210+
}

podman.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ and schema to run the tests:
6666
```
6767
podman run --rm --name HibernateTestingMariaDB \
6868
-e MYSQL_ROOT_PASSWORD=hreact -e MYSQL_DATABASE=hreact -e MYSQL_USER=hreact -e MYSQL_PASSWORD=hreact \
69-
-p 3306:3306 docker.io/mariadb:10.11.2
69+
-p 3306:3306 docker.io/mariadb:10.11.3
7070
```
7171

7272
When the database has started, you can run the tests on MariaDB with:

tooling/jbang/MariaDBReactiveTest.java.qute

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public class {baseName} {
6969
}
7070

7171
@ClassRule
72-
public final static MariaDBContainer<?> database = new MariaDBContainer<>( imageName( "docker.io", "mariadb", "10.11.2" ) );
72+
public final static MariaDBContainer<?> database = new MariaDBContainer<>( imageName( "docker.io", "mariadb", "10.11.3" ) );
7373

7474
private Mutiny.SessionFactory sessionFactory;
7575

tooling/jbang/ReactiveTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ enum Database {
231231
POSTGRESQL( () -> new PostgreSQLContainer( "postgres:15.2" ) ),
232232
MYSQL( () -> new MySQLContainer( "mysql:8.0.33" ) ),
233233
DB2( () -> new Db2Container( "docker.io/ibmcom/db2:11.5.8.0" ).acceptLicense() ),
234-
MARIADB( () -> new MariaDBContainer( "mariadb:10.11.2" ) ),
234+
MARIADB( () -> new MariaDBContainer( "mariadb:10.11.3" ) ),
235235
COCKROACHDB( () -> new CockroachContainer( "cockroachdb/cockroach:v22.2.10" ) );
236236

237237
private final Supplier<JdbcDatabaseContainer<?>> containerSupplier;

0 commit comments

Comments
 (0)