Skip to content

Commit f442261

Browse files
committed
Upgrade to R2DBC MSSQL 1.0.0.RC1.
Enable tests for SQL Server. See #1292
1 parent 6958157 commit f442261

File tree

6 files changed

+95
-9
lines changed

6 files changed

+95
-9
lines changed

ci/accept-third-party-license.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44
echo "mcr.microsoft.com/mssql/server:2019-CU16-ubuntu-20.04"
55
echo "ibmcom/db2:11.5.7.0a"
66
} > spring-data-jdbc/src/test/resources/container-license-acceptance.txt
7+
8+
{
9+
echo "mcr.microsoft.com/mssql/server:2022-latest"
10+
echo "ibmcom/db2:11.5.7.0a"
11+
} > spring-data-r2dbc/src/test/resources/container-license-acceptance.txt

spring-data-r2dbc/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<postgresql.version>42.4.0</postgresql.version>
3030
<r2dbc-postgresql.version>1.0.0.RC1</r2dbc-postgresql.version>
3131
<r2dbc-h2.version>1.0.0.RC1</r2dbc-h2.version>
32+
<r2dbc-mssql.version>1.0.0.RC1</r2dbc-mssql.version>
3233
<oracle-r2dbc.version>1.0.0</oracle-r2dbc.version>
3334
<r2dbc-spi.version>1.0.0.RELEASE</r2dbc-spi.version>
3435
<reactive-streams.version>1.0.4</reactive-streams.version>
@@ -213,6 +214,13 @@
213214
<scope>test</scope>
214215
</dependency>
215216

217+
<dependency>
218+
<groupId>io.r2dbc</groupId>
219+
<artifactId>r2dbc-mssql</artifactId>
220+
<version>${r2dbc-mssql.version}</version>
221+
<scope>test</scope>
222+
</dependency>
223+
216224
<dependency>
217225
<groupId>com.oracle.database.r2dbc</groupId>
218226
<artifactId>oracle-r2dbc</artifactId>
@@ -253,6 +261,18 @@
253261
</exclusions>
254262
</dependency>
255263

264+
<dependency>
265+
<groupId>org.testcontainers</groupId>
266+
<artifactId>mssqlserver</artifactId>
267+
<scope>test</scope>
268+
<exclusions>
269+
<exclusion>
270+
<groupId>org.slf4j</groupId>
271+
<artifactId>jcl-over-slf4j</artifactId>
272+
</exclusion>
273+
</exclusions>
274+
</dependency>
275+
256276
<dependency>
257277
<groupId>org.testcontainers</groupId>
258278
<artifactId>oracle-xe</artifactId>

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/SqlServerR2dbcRepositoryIntegrationTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import javax.sql.DataSource;
2323

24-
import org.junit.Ignore;
2524
import org.junit.jupiter.api.Disabled;
2625
import org.junit.jupiter.api.extension.ExtendWith;
2726
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -45,7 +44,6 @@
4544
*/
4645
@ExtendWith(SpringExtension.class)
4746
@ContextConfiguration
48-
@Disabled("Requires 1.0 driver")
4947
public class SqlServerR2dbcRepositoryIntegrationTests extends AbstractR2dbcRepositoryIntegrationTests {
5048

5149
@RegisterExtension public static final ExternalDatabase database = SqlServerTestSupport.database();
@@ -82,7 +80,7 @@ protected Class<? extends LegoSetRepository> getRepositoryInterfaceType() {
8280
return SqlServerLegoSetRepository.class;
8381
}
8482

85-
@Ignore("SQL server locks a SELECT COUNT so we cannot proceed.")
83+
@Disabled("SQL server locks a SELECT COUNT so we cannot proceed.")
8684
@Override
8785
public void shouldInsertItemsTransactional() {}
8886

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/SqlServerR2dbcRepositoryWithMixedCaseNamesIntegrationTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import javax.sql.DataSource;
2323

24-
import org.junit.jupiter.api.Disabled;
2524
import org.junit.jupiter.api.extension.ExtendWith;
2625
import org.junit.jupiter.api.extension.RegisterExtension;
2726

@@ -48,7 +47,6 @@
4847
*/
4948
@ExtendWith(SpringExtension.class)
5049
@ContextConfiguration
51-
@Disabled("Requires 1.0 driver")
5250
public class SqlServerR2dbcRepositoryWithMixedCaseNamesIntegrationTests
5351
extends AbstractR2dbcRepositoryWithMixedCaseNamesIntegrationTests {
5452

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/PostgresTestSupport.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ public class PostgresTestSupport {
6363
+ ");";
6464

6565
public static final String DROP_TABLE_LEGOSET_WITH_MIXED_CASE_NAMES = "DROP TABLE \"LegoSet\"";
66+
6667
/**
67-
* Returns a database either hosted locally at {@code postgres:@localhost:5432/postgres} or running inside Docker.
68+
* Returns a database either hosted locally at {@code jdbc:postgres//localhost:5432/postgres} or running inside
69+
* Docker.
6870
*
6971
* @return information about the database. Guaranteed to be not {@literal null}.
7072
*/

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/testing/SqlServerTestSupport.java

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717

1818
import io.r2dbc.spi.ConnectionFactory;
1919

20+
import java.util.function.Supplier;
21+
import java.util.stream.Stream;
22+
2023
import javax.sql.DataSource;
2124

2225
import org.springframework.data.r2dbc.testing.ExternalDatabase.ProvidedDatabase;
2326

27+
import org.testcontainers.containers.MSSQLServerContainer;
28+
2429
import com.microsoft.sqlserver.jdbc.SQLServerDataSource;
2530

2631
/**
@@ -31,6 +36,9 @@
3136
* @author Jens Schauder
3237
*/
3338
public class SqlServerTestSupport {
39+
40+
private static ExternalDatabase testContainerDatabase;
41+
3442
public static String CREATE_TABLE_LEGOSET = "CREATE TABLE legoset (\n" //
3543
+ " id integer PRIMARY KEY,\n" //
3644
+ " version integer NULL,\n" //
@@ -59,14 +67,37 @@ public class SqlServerTestSupport {
5967
public static final String DROP_TABLE_LEGOSET_WITH_MIXED_CASE_NAMES = "DROP TABLE LegoSet";
6068

6169
/**
62-
* Returns a locally provided database at {@code sqlserver:@localhost:1433/master}.
70+
* Returns a database either hosted locally at {@code jdbc:sqlserver://localhost:1433;database=master;} or running
71+
* inside Docker.
6372
*/
6473
public static ExternalDatabase database() {
65-
return local();
74+
75+
if (Boolean.getBoolean("spring.data.r2dbc.test.preferLocalDatabase")) {
76+
77+
return getFirstWorkingDatabase( //
78+
SqlServerTestSupport::local, //
79+
SqlServerTestSupport::testContainer //
80+
);
81+
} else {
82+
83+
return getFirstWorkingDatabase( //
84+
SqlServerTestSupport::testContainer, //
85+
SqlServerTestSupport::local //
86+
);
87+
}
88+
}
89+
90+
@SafeVarargs
91+
private static ExternalDatabase getFirstWorkingDatabase(Supplier<ExternalDatabase>... suppliers) {
92+
93+
return Stream.of(suppliers).map(Supplier::get) //
94+
.filter(ExternalDatabase::checkValidity) //
95+
.findFirst() //
96+
.orElse(ExternalDatabase.unavailable());
6697
}
6798

6899
/**
69-
* Returns a locally provided database at {@code sqlserver:@localhost:1433/master}.
100+
* Returns a locally provided database at {@code jdbc:sqlserver://localhost:1433;database=master}.
70101
*/
71102
private static ExternalDatabase local() {
72103

@@ -76,9 +107,41 @@ private static ExternalDatabase local() {
76107
.database("master") //
77108
.username("sa") //
78109
.password("A_Str0ng_Required_Password") //
110+
.jdbcUrl("jdbc:sqlserver://localhost:1433;database=master;encrypt=false")
79111
.build();
80112
}
81113

114+
/**
115+
* Returns a database provided via Testcontainers.
116+
*/
117+
@SuppressWarnings("rawtypes")
118+
private static ExternalDatabase testContainer() {
119+
120+
if (testContainerDatabase == null) {
121+
122+
try {
123+
MSSQLServerContainer<?> container = new MSSQLServerContainer("mcr.microsoft.com/mssql/server:2022-latest") {
124+
@Override
125+
public String getDatabaseName() {
126+
return "master";
127+
}
128+
};
129+
container.withReuse(true);
130+
container.withUrlParam("encrypt", "false");
131+
container.start();
132+
133+
testContainerDatabase = ProvidedDatabase.builder(container).database(container.getDatabaseName()).build();
134+
135+
} catch (IllegalStateException ise) {
136+
// docker not available.
137+
testContainerDatabase = ExternalDatabase.unavailable();
138+
}
139+
140+
}
141+
142+
return testContainerDatabase;
143+
}
144+
82145
/**
83146
* Creates a new {@link ConnectionFactory} configured from the {@link ExternalDatabase}.
84147
*/

0 commit comments

Comments
 (0)