Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GraalVM Reachability Metadata and corresponding nativeTest for MS SQL Server integration #29404

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

linghengqian
Copy link
Member

@linghengqian linghengqian commented Dec 14, 2023

For #29052.

Changes proposed in this pull request:

  • Add GraalVM Reachability Metadata and corresponding nativeTest for MS SQL Server integration.
  • Examples like https://github.com/apache/beam/blob/v2.52.0/it/jdbc/src/main/java/org/apache/beam/it/jdbc/MSSQLResourceManager.java show that ASF allows the EULA for MS SQL Server's Docker Image during testing. Therefore, I think there is no problem in using the corresponding Docker Image in unit testing.
  • Modifications to SQLServerConnectionPropertiesParser are unavoidable and cannot be avoided by implementing a new ConnectionPropertiesParser. Because in TcSQLServerDatabaseType.getTrunkDatabaseType(), all jdbcUrls with the prefix jdbc:tc:sqlserver: will be routed to SQLServer’s DatabaseType.
  • The reason why jdbcUrl prefixed with jdbc:tc:postgresql: does not need to be done is that PostgreSQLConnectionPropertiesParser uses the public StandardJdbcUrlParser to parse jdbcUrl, and StandardJdbcUrlParser always supports testcontainers and contains corresponding unit tests.
  • Maven modules such as com.microsoft.sqlserver:mssql-jdbc, represented by the JDBC Driver of MS SQL Server,
    will dynamically load different character sets based on the encoding used in the database, which is unpredictable behavior under GraalVM Native Image. I've specified the relevant settings in the documentation.
Failures (1):
  JUnit Jupiter:MSSQLServerTest:assertShardingInLocalTransactions()
    MethodSource [className = 'org.apache.shardingsphere.test.natived.jdbc.databases.MSSQLServerTest', methodName = 'assertShardingInLocalTransactions', methodParameterTypes = '']
    => com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Container startup failed for image mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04
       com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:596)
       com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:582)
       com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
       com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
       org.apache.shardingsphere.infra.datasource.pool.CatalogSwitchableDataSource.getConnection(CatalogSwitchableDataSource.java:46)
       [...]
     Caused by: org.testcontainers.containers.ContainerLaunchException: Container startup failed for image mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04
       org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:362)
       org.testcontainers.containers.GenericContainer.start(GenericContainer.java:333)
       org.testcontainers.jdbc.ContainerDatabaseDriver.connect(ContainerDatabaseDriver.java:134)
       com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:121)
       com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364)
       [...]
     Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
       org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
       org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:347)
       [...]
     Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
       org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:566)
       org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:357)
       org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
       [...]
     Caused by: java.lang.IllegalStateException: Container is started, but cannot be accessed by (JDBC URL: jdbc:sqlserver://localhost:62038;encrypt=false), please check container logs
       org.testcontainers.containers.JdbcDatabaseContainer.waitUntilContainerStarted(JdbcDatabaseContainer.java:176)
       org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:503)
       [...]
     Caused by: java.sql.SQLException: Could not create new connection
       org.testcontainers.containers.JdbcDatabaseContainer.createConnection(JdbcDatabaseContainer.java:262)
       org.testcontainers.containers.JdbcDatabaseContainer.createConnection(JdbcDatabaseContainer.java:218)
       org.testcontainers.containers.JdbcDatabaseContainer.waitUntilContainerStarted(JdbcDatabaseContainer.java:158)
       [...]
     Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: SQL Server collation SQL_Latin1_General_CP1_CI_AS is not supported by this driver. ClientConnectionId:5810036a-9e38-463b-a09a-8db2864d3647
       com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:2374)
       com.microsoft.sqlserver.jdbc.SQLServerConnection.processEnvChange(SQLServerConnection.java:3177)
       com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEnvChange(tdsparser.java:187)
       com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:62)
       com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4214)
       [...]
     Caused by: java.io.UnsupportedEncodingException: SQL Server collation SQL_Latin1_General_CP1_CI_AS is not supported by this driver.
       com.microsoft.sqlserver.jdbc.SQLCollation.encodingFromSortId(SQLCollation.java:506)
       com.microsoft.sqlserver.jdbc.SQLCollation.<init>(SQLCollation.java:63)
       com.microsoft.sqlserver.jdbc.SQLServerConnection.processEnvChange(SQLServerConnection.java:3174)
       [...]
     Caused by: java.io.UnsupportedEncodingException: Codepage Cp1252 is not supported by the Java environment.
       com.microsoft.sqlserver.jdbc.Encoding.checkSupported(SQLCollation.java:572)
       com.microsoft.sqlserver.jdbc.SQLCollation$SortOrder.getEncoding(SQLCollation.java:473)
       com.microsoft.sqlserver.jdbc.SQLCollation.encodingFromSortId(SQLCollation.java:501)
       [...]

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct of this project.
  • I have self-reviewed the commit code.
  • I have (or in comment I request) added corresponding labels for the pull request.
  • I have passed maven check locally : ./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e.
  • I have made corresponding changes to the documentation.
  • I have added corresponding unit tests for my changes.

@linghengqian linghengqian marked this pull request as ready for review December 14, 2023 15:54
@terrymanu terrymanu added this to the 5.4.2 milestone Dec 14, 2023
@terrymanu terrymanu merged commit 6fa3b70 into apache:master Dec 14, 2023
133 checks passed
@linghengqian linghengqian deleted the sql=server branch December 14, 2023 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants