Automated SQL Server management via Docker

This commit is contained in:
Sanne Grinovero
2019-03-12 11:10:48 +00:00
parent 7753ff60ad
commit 398b5b7752
3 changed files with 156 additions and 2 deletions

View File

@@ -0,0 +1,39 @@
# JPA example with Microsoft SQL Server
## Running the tests
By default, the tests of this module are disabled.
To run the tests in a standard JVM with SQL Server started as a Docker container, you can run the following command:
```
mvn clean install -Ddocker -Dtest-mssql
```
To also test as a native image, add `-Dnative`:
```
mvn clean install -Ddocker -Dtest-mssql -Dnative
```
Alternatively you can connect to your own SQL Server.
Reconfigure the connection URL with `-Dmssqldb.url=jdbc:sqlserver://...`;
you'll probably want to change the authentication password too: `-Dmssqldb.sa-password=NotS0Secret`.
## Limitations
### Active Directory
Authentication to the server via Active Directory is a feature of the official JDBC driver, but this was disabled in Quarkus so to minimize the dependencies.
If you really need this feature, please let us know.
### Localization, Encoding an Character sets
SQL Server by default uses collation `SQL_Latin1_General_CP1_CI_AS` ; attempting to use this in a native-image will result in an error:
java.io.UnsupportedEncodingException: "Codepage Cp1252 is not supported by the Java environment."
The solution is simple: you'll need to make sure your native images contains additional, non-default character sets.
Just set the flag `addAllCharsets` in the `native-image` configuration of your favourite build tool.

View File

@@ -29,6 +29,12 @@
<artifactId>quarkus-integration-test-jpa-mssql</artifactId>
<name>Quarkus - Integration Tests - JPA - MSSQL</name>
<description>Module that contains JPA related tests running in strict mode with the MSSQL database</description>
<properties>
<mssqldb.url>SomeJDBCUrl</mssqldb.url>
<mssqldb.sa-password>SomeJDBCPassword</mssqldb.sa-password>
</properties>
<dependencies>
<!-- Enables the JPA capabilities -->
<dependency>
@@ -70,6 +76,18 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>${project.groupId}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
@@ -85,6 +103,31 @@
</build>
<profiles>
<profile>
<id>test-mssql</id>
<activation>
<property>
<name>test-mssql</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>native-image</id>
<activation>
@@ -141,6 +184,78 @@
</build>
</profile>
<profile>
<id>docker-mssql</id>
<activation>
<property>
<name>docker</name>
</property>
</activation>
<properties>
<mssqldb.url>jdbc:sqlserver://localhost:1433;databaseName=tempdb</mssqldb.url>
<!-- Careful: SQL Server refuses to work with trivial passwords. -->
<mssqldb.sa-password>ActuallyRequired11Complexity</mssqldb.sa-password>
</properties>
<build>
<plugins>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<images>
<image>
<name>microsoft/mssql-server-linux:2017-CU12</name>
<alias>quarkus-test-mssqldb</alias>
<run>
<ports>
<port>1433:1433</port>
</ports>
<env>
<ACCEPT_EULA>Y</ACCEPT_EULA>
<SA_PASSWORD>ActuallyRequired11Complexity</SA_PASSWORD>
</env>
<log>
<prefix>MS SQL Server:</prefix>
<date>default</date>
<color>cyan</color>
</log>
<wait>
<!-- good docs found at: http://dmp.fabric8.io/#build-healthcheck -->
<tcp>
<mode>direct</mode>
<ports>
<port>1433</port>
</ports>
</tcp>
<!-- Unfortunately booting this is slow, needs to set a generous timeout: -->
<time>40000</time>
</wait>
</run>
</image>
</images>
</configuration>
<executions>
<execution>
<id>docker-start</id>
<phase>compile</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>docker-stop</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@@ -1,7 +1,7 @@
quarkus.datasource.url=jdbc:sqlserver://localhost:1433;databaseName=tempdb
quarkus.datasource.url=${mssqldb.url}
quarkus.datasource.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
quarkus.datasource.username=sa
quarkus.datasource.password=ActuallyRequired11Complexity
quarkus.datasource.password=${mssqldb.sa-password}
quarkus.datasource.max-size=8
quarkus.datasource.min-size=2
quarkus.hibernate-orm.dialect=org.hibernate.dialect.SQLServer2012Dialect