Skip to content

Commit e15e6b1

Browse files
committed
#163 - Add tests for R2DBC MySQL.
1 parent 6cd08ac commit e15e6b1

9 files changed

+305
-22
lines changed

pom.xml

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
35

46
<modelVersion>4.0.0</modelVersion>
57

@@ -30,6 +32,7 @@
3032
<postgresql.version>42.2.5</postgresql.version>
3133
<mysql.version>5.1.47</mysql.version>
3234
<jasync.version>0.9.52</jasync.version>
35+
<r2dbc-mysql.version>0.2.0.M2</r2dbc-mysql.version>
3336
<mssql-jdbc.version>7.1.2.jre8-preview</mssql-jdbc.version>
3437
<r2dbc-releasetrain.version>Arabba-M8</r2dbc-releasetrain.version>
3538
<reactive-streams.version>1.0.1</reactive-streams.version>
@@ -171,6 +174,8 @@
171174
<scope>test</scope>
172175
</dependency>
173176

177+
<!-- JDBC Drivers -->
178+
174179
<dependency>
175180
<groupId>org.postgresql</groupId>
176181
<artifactId>postgresql</artifactId>
@@ -192,6 +197,8 @@
192197
<scope>test</scope>
193198
</dependency>
194199

200+
<!-- R2DBC Drivers -->
201+
195202
<dependency>
196203
<groupId>io.r2dbc</groupId>
197204
<artifactId>r2dbc-postgresql</artifactId>
@@ -218,12 +225,14 @@
218225
</dependency>
219226

220227
<dependency>
221-
<groupId>de.schauderhaft.degraph</groupId>
222-
<artifactId>degraph-check</artifactId>
223-
<version>${degraph-check.version}</version>
228+
<groupId>com.github.mirromutth</groupId>
229+
<artifactId>r2dbc-mysql</artifactId>
230+
<version>${r2dbc-mysql.version}</version>
224231
<scope>test</scope>
225232
</dependency>
226233

234+
<!-- Testcontainers -->
235+
227236
<dependency>
228237
<groupId>org.testcontainers</groupId>
229238
<artifactId>mysql</artifactId>
@@ -242,6 +251,13 @@
242251
<scope>test</scope>
243252
</dependency>
244253

254+
<dependency>
255+
<groupId>de.schauderhaft.degraph</groupId>
256+
<artifactId>degraph-check</artifactId>
257+
<version>${degraph-check.version}</version>
258+
<scope>test</scope>
259+
</dependency>
260+
245261
<dependency>
246262
<groupId>io.mockk</groupId>
247263
<artifactId>mockk</artifactId>
@@ -421,6 +437,10 @@
421437
<id>jcenter</id>
422438
<url>https://jcenter.bintray.com/</url>
423439
</repository>
440+
<repository>
441+
<id>jitpack.io</id>
442+
<url>https://jitpack.io</url>
443+
</repository>
424444
</repositories>
425445

426446
<pluginRepositories>
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.r2dbc.core;
17+
18+
import io.r2dbc.spi.ConnectionFactory;
19+
20+
import javax.sql.DataSource;
21+
22+
import org.junit.ClassRule;
23+
import org.junit.Ignore;
24+
import org.junit.Test;
25+
26+
import org.springframework.data.r2dbc.testing.ExternalDatabase;
27+
import org.springframework.data.r2dbc.testing.MySqlTestSupport;
28+
29+
/**
30+
* Integration tests for {@link DatabaseClient} against MySQL using Jasync MySQL.
31+
*
32+
* @author Mark Paluch
33+
*/
34+
public class JasyncMySqlDatabaseClientIntegrationTests extends AbstractDatabaseClientIntegrationTests {
35+
36+
@ClassRule public static final ExternalDatabase database = MySqlTestSupport.database();
37+
38+
@Override
39+
protected DataSource createDataSource() {
40+
return MySqlTestSupport.createDataSource(database);
41+
}
42+
43+
@Override
44+
protected ConnectionFactory createConnectionFactory() {
45+
return MySqlTestSupport.createJasyncConnectionFactory(database);
46+
}
47+
48+
@Override
49+
protected String getCreateTableStatement() {
50+
return MySqlTestSupport.CREATE_TABLE_LEGOSET;
51+
}
52+
53+
@Override
54+
@Ignore("Jasync currently uses its own exceptions, see jasync-sql/jasync-sql#106")
55+
@Test
56+
public void shouldTranslateDuplicateKeyException() {}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.r2dbc.core;
17+
18+
import io.r2dbc.spi.ConnectionFactory;
19+
import reactor.core.publisher.Mono;
20+
21+
import java.time.Duration;
22+
23+
import javax.sql.DataSource;
24+
25+
import org.junit.ClassRule;
26+
27+
import org.springframework.data.r2dbc.testing.ExternalDatabase;
28+
import org.springframework.data.r2dbc.testing.MySqlTestSupport;
29+
30+
/**
31+
* Transactional integration tests for {@link DatabaseClient} against MySQL using Jasync MySQL.
32+
*
33+
* @author Mark Paluch
34+
*/
35+
public class JasyncMySqlTransactionalDatabaseClientIntegrationTests
36+
extends AbstractTransactionalDatabaseClientIntegrationTests {
37+
38+
@ClassRule public static final ExternalDatabase database = MySqlTestSupport.database();
39+
40+
@Override
41+
protected DataSource createDataSource() {
42+
return MySqlTestSupport.createDataSource(database);
43+
}
44+
45+
@Override
46+
protected ConnectionFactory createConnectionFactory() {
47+
return MySqlTestSupport.createJasyncConnectionFactory(database);
48+
}
49+
50+
@Override
51+
protected String getCreateTableStatement() {
52+
return MySqlTestSupport.CREATE_TABLE_LEGOSET;
53+
}
54+
55+
@Override
56+
protected Mono<Void> prepareForTransaction(DatabaseClient client) {
57+
58+
/*
59+
* We have to execute a sql statement first.
60+
* Otherwise MySql don't have a transaction id.
61+
* And we need to delay emitting the result so that MySql has time to write the transaction id, which is done in
62+
* batches every now and then.
63+
* @see: https://dev.mysql.com/doc/refman/5.7/en/innodb-information-schema-internal-data.html
64+
*/
65+
return client.execute(getInsertIntoLegosetStatement()) //
66+
.bind(0, 42055) //
67+
.bind(1, "SCHAUFELRADBAGGER") //
68+
.bindNull(2, Integer.class) //
69+
.fetch().rowsUpdated() //
70+
.delayElement(Duration.ofMillis(50)) //
71+
.then();
72+
}
73+
74+
@Override
75+
protected String getCurrentTransactionIdStatement() {
76+
return "SELECT tx.trx_id FROM information_schema.innodb_trx tx WHERE tx.trx_mysql_thread_id = connection_id()";
77+
}
78+
}

src/test/java/org/springframework/data/r2dbc/core/MySqlDatabaseClientIntegrationTests.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
import javax.sql.DataSource;
2121

2222
import org.junit.ClassRule;
23-
import org.junit.Ignore;
24-
import org.junit.Test;
25-
import org.springframework.data.r2dbc.core.DatabaseClient;
23+
2624
import org.springframework.data.r2dbc.testing.ExternalDatabase;
2725
import org.springframework.data.r2dbc.testing.MySqlTestSupport;
2826

@@ -49,10 +47,4 @@ protected ConnectionFactory createConnectionFactory() {
4947
protected String getCreateTableStatement() {
5048
return MySqlTestSupport.CREATE_TABLE_LEGOSET;
5149
}
52-
53-
@Override
54-
@Ignore("Jasync currently uses its own exceptions, see jasync-sql/jasync-sql#106")
55-
@Test
56-
public void shouldTranslateDuplicateKeyException() {}
57-
5850
}

src/test/java/org/springframework/data/r2dbc/core/MySqlTransactionalDatabaseClientIntegrationTests.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@
1515
*/
1616
package org.springframework.data.r2dbc.core;
1717

18-
import javax.sql.DataSource;
18+
import io.r2dbc.spi.ConnectionFactory;
19+
import reactor.core.publisher.Mono;
20+
1921
import java.time.Duration;
2022

21-
import io.r2dbc.spi.ConnectionFactory;
23+
import javax.sql.DataSource;
24+
2225
import org.junit.ClassRule;
2326
import org.junit.Ignore;
2427
import org.junit.Test;
2528

2629
import org.springframework.data.r2dbc.testing.ExternalDatabase;
2730
import org.springframework.data.r2dbc.testing.MySqlTestSupport;
28-
import reactor.core.publisher.Mono;
2931

3032
/**
3133
* Transactional integration tests for {@link DatabaseClient} against MySQL.
@@ -71,6 +73,17 @@ protected Mono<Void> prepareForTransaction(DatabaseClient client) {
7173
.then();
7274
}
7375

76+
@Test
77+
@Ignore("https://github.com/mirromutth/r2dbc-mysql/issues/45")
78+
@Override
79+
public void emitTransactionIds() {}
80+
81+
@Test
82+
@Ignore("https://github.com/mirromutth/r2dbc-mysql/issues/45")
83+
public void emitTransactionIdsUsingManagedTransactions() {
84+
super.emitTransactionIdsUsingManagedTransactions();
85+
}
86+
7487
@Override
7588
protected String getCurrentTransactionIdStatement() {
7689
return "SELECT tx.trx_id FROM information_schema.innodb_trx tx WHERE tx.trx_mysql_thread_id = connection_id()";

src/test/java/org/springframework/data/r2dbc/dialect/DialectResolverUnitTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import static org.assertj.core.api.Assertions.*;
44
import static org.mockito.Mockito.*;
55

6+
import io.github.mirromutth.r2dbc.mysql.MySqlConnectionConfiguration;
7+
import io.github.mirromutth.r2dbc.mysql.MySqlConnectionFactory;
68
import io.r2dbc.h2.H2ConnectionConfiguration;
79
import io.r2dbc.h2.H2ConnectionFactory;
810
import io.r2dbc.mssql.MssqlConnectionConfiguration;
@@ -24,6 +26,7 @@
2426

2527
import com.github.jasync.r2dbc.mysql.JasyncConnectionFactory;
2628
import com.github.jasync.sql.db.mysql.pool.MySQLConnectionFactory;
29+
import reactor.core.publisher.Mono;
2730

2831
/**
2932
* Unit tests for {@link DialectResolver}.
@@ -40,11 +43,14 @@ public void shouldResolveDatabaseType() {
4043
MssqlConnectionFactory mssql = new MssqlConnectionFactory(MssqlConnectionConfiguration.builder().host("localhost")
4144
.database("foo").username("bar").password("password").build());
4245
H2ConnectionFactory h2 = new H2ConnectionFactory(H2ConnectionConfiguration.builder().inMemory("mem").build());
43-
JasyncConnectionFactory mysql = new JasyncConnectionFactory(mock(MySQLConnectionFactory.class));
46+
JasyncConnectionFactory jasyncMysql = new JasyncConnectionFactory(mock(MySQLConnectionFactory.class));
47+
MySqlConnectionFactory mysql = MySqlConnectionFactory
48+
.from(MySqlConnectionConfiguration.builder().host("localhost").username("mysql").build());
4449

4550
assertThat(DialectResolver.getDialect(postgres)).isEqualTo(PostgresDialect.INSTANCE);
4651
assertThat(DialectResolver.getDialect(mssql)).isEqualTo(SqlServerDialect.INSTANCE);
4752
assertThat(DialectResolver.getDialect(h2)).isEqualTo(H2Dialect.INSTANCE);
53+
assertThat(DialectResolver.getDialect(jasyncMysql)).isEqualTo(MySqlDialect.INSTANCE);
4854
assertThat(DialectResolver.getDialect(mysql)).isEqualTo(MySqlDialect.INSTANCE);
4955
}
5056

0 commit comments

Comments
 (0)