File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed
main/java/org/testcontainers/mysql
test/java/org/testcontainers/mysql Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .testcontainers .mysql ;
2+
3+ import io .asyncer .r2dbc .mysql .MySqlConnectionFactoryProvider ;
4+ import io .r2dbc .spi .ConnectionFactoryOptions ;
5+ import org .testcontainers .r2dbc .R2DBCDatabaseContainer ;
6+
7+ public class MySQLR2DBCDatabaseContainer implements R2DBCDatabaseContainer {
8+
9+ private final MySQLContainer container ;
10+
11+ public MySQLR2DBCDatabaseContainer (MySQLContainer container ) {
12+ this .container = container ;
13+ }
14+
15+ public static ConnectionFactoryOptions getOptions (MySQLContainer container ) {
16+ ConnectionFactoryOptions options = ConnectionFactoryOptions
17+ .builder ()
18+ .option (ConnectionFactoryOptions .DRIVER , MySqlConnectionFactoryProvider .MYSQL_DRIVER )
19+ .build ();
20+
21+ return new MySQLR2DBCDatabaseContainer (container ).configure (options );
22+ }
23+
24+ @ Override
25+ public ConnectionFactoryOptions configure (ConnectionFactoryOptions options ) {
26+ return options
27+ .mutate ()
28+ .option (ConnectionFactoryOptions .HOST , container .getHost ())
29+ .option (ConnectionFactoryOptions .PORT , container .getMappedPort (MySQLContainer .MYSQL_PORT ))
30+ .option (ConnectionFactoryOptions .DATABASE , container .getDatabaseName ())
31+ .option (ConnectionFactoryOptions .USER , container .getUsername ())
32+ .option (ConnectionFactoryOptions .PASSWORD , container .getPassword ())
33+ .build ();
34+ }
35+
36+ @ Override
37+ public void start () {
38+ this .container .start ();
39+ }
40+
41+ @ Override
42+ public void stop () {
43+ this .container .stop ();
44+ }
45+ }
Original file line number Diff line number Diff line change 1+ package org .testcontainers .mysql ;
2+
3+ import io .r2dbc .spi .ConnectionFactoryOptions ;
4+ import org .testcontainers .MySQLTestImages ;
5+ import org .testcontainers .r2dbc .AbstractR2DBCDatabaseContainerTest ;
6+
7+ public class MySQLR2DBCDatabaseContainerTest extends AbstractR2DBCDatabaseContainerTest <MySQLContainer > {
8+
9+ @ Override
10+ protected ConnectionFactoryOptions getOptions (MySQLContainer container ) {
11+ return MySQLR2DBCDatabaseContainer .getOptions (container );
12+ }
13+
14+ @ Override
15+ protected String createR2DBCUrl () {
16+ return "r2dbc:tc:mysql:///db?TC_IMAGE_TAG=" + MySQLTestImages .MYSQL_80_IMAGE .getVersionPart ();
17+ }
18+
19+ @ Override
20+ protected MySQLContainer createContainer () {
21+ return new MySQLContainer (MySQLTestImages .MYSQL_80_IMAGE );
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments