Skip to content

Commit

Permalink
Add GraalVM Reachability Metadata and corresponding nativeTest for Fi…
Browse files Browse the repository at this point in the history
…rebird (#34307)

* Add GraalVM Reachability Metadata and corresponding nativeTest for Firebird

* Fix the connection leak problem caused by improper configuration of unit test lifecycle
  • Loading branch information
linghengqian authored Jan 21, 2025
1 parent 7ef227a commit 98a94fc
Show file tree
Hide file tree
Showing 40 changed files with 1,683 additions and 982 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

1. Metadata: Add support for partition tables in PostgreSQL [#34346](https://github.com/apache/shardingsphere/pull/34346)
1. SQL Binder: Support select aggregation function sql bind in projection and having - [#34379](https://github.com/apache/shardingsphere/pull/34379)
1. Proxy Native: Add GraalVM Reachability Metadata and corresponding nativeTest for Firebird - [#34307](https://github.com/apache/shardingsphere/pull/34307)

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"},
"interfaces":["org.apache.hive.service.rpc.thrift.TCLIService$Iface"]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.initializer.BootstrapInitializer"},
"interfaces":["org.apache.seata.config.Configuration"]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager"},
"interfaces":["org.apache.seata.config.Configuration"]
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,16 @@
"name":"org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerDropTableStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdDeleteStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdDeleteStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdDropTableStatement"},
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdDropTableStatement",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"javax.security.auth.login.Configuration"},
"name":"sun.security.provider.ConfigFile",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"pattern":"\\QMETA-INF/services/javax.xml.parsers.SAXParserFactory\\E"
}]},
"bundles":[{
"name":"com.sun.org.apache.xml.internal.serializer.XMLEntities",
"locales":["en"]
}, {
"name":"com.microsoft.sqlserver.jdbc.SQLServerResource",
"locales":["en"]
}, {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
[
{
"condition":{"typeReachable":"org.firebirdsql.encodings.EncodingFactory"},
"name":"org.firebirdsql.encodings.DefaultEncodingSet"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"name":"org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"name":"org.firebirdsql.gds.impl.jni.NativeGDSFactoryPlugin"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"name":"org.firebirdsql.gds.impl.oo.OOGDSFactoryPlugin"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"name":"org.firebirdsql.gds.impl.wire.WireGDSFactoryPlugin"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.legacy.LegacyAuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp224AuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp256AuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp384AuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp512AuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"name":"org.firebirdsql.gds.ng.wire.auth.srp.SrpAuthenticationPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.version13.V13WireOperations"},
"name":"org.firebirdsql.gds.ng.wire.crypt.arc4.Arc4EncryptionPluginSpi",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.version13.V13WireOperations"},
"name":"org.firebirdsql.gds.ng.wire.crypt.chacha.ChaChaEncryptionPluginSpi"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version10.Version10Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version11.Version11Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version12.Version12Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version13.Version13Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version15.Version15Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version16.Version16Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"name":"org.firebirdsql.gds.ng.wire.version18.Version18Descriptor"
},
{
"condition":{"typeReachable":"org.firebirdsql.jaybird.props.internal.UnregisteredDpbDefiner"},
"name":"org.firebirdsql.jaybird.fb.constants.DpbItems",
"allPublicFields":true
},
{
"condition":{"typeReachable":"org.firebirdsql.jaybird.props.internal.UnregisteredDpbDefiner"},
"name":"org.firebirdsql.jaybird.fb.constants.SpbItems",
"allPublicFields":true
},
{
"condition":{"typeReachable":"org.firebirdsql.jaybird.xca.FBManagedConnection"},
"name":"org.firebirdsql.jaybird.xca.FBManagedConnection",
"fields":[{"name":"connectionHandle"}, {"name":"unnotifiedWarnings"}]
},
{
"condition":{"typeReachable":"org.firebirdsql.jaybird.xca.FBManagedConnectionFactory"},
"name":"org.firebirdsql.jdbc.FBConnection",
"methods":[{"name":"<init>","parameterTypes":["org.firebirdsql.jaybird.xca.FBManagedConnection"] }]
},
{
"condition":{"typeReachable":"org.firebirdsql.jdbc.FBConnection"},
"name":"org.firebirdsql.jdbc.FBConnection",
"fields":[{"name":"savepointCounter"}]
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"resources":{
"includes":[{
"condition":{"typeReachable":"org.firebirdsql.encodings.EncodingFactory"},
"pattern":"\\QMETA-INF/services/org.firebirdsql.encodings.EncodingSet\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
"pattern":"\\QMETA-INF/services/org.firebirdsql.gds.impl.GDSFactoryPlugin\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
"pattern":"\\QMETA-INF/services/org.firebirdsql.gds.ng.wire.ProtocolDescriptor\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
"pattern":"\\QMETA-INF/services/org.firebirdsql.gds.ng.wire.auth.AuthenticationPluginSpi\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.jaybird.props.internal.ConnectionPropertyRegistry"},
"pattern":"\\QMETA-INF/services/org.firebirdsql.jaybird.props.spi.ConnectionPropertyDefinerSpi\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.gds.MessageLoader"},
"pattern":"\\Qisc_error_msg.properties\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.gds.MessageLoader"},
"pattern":"\\Qisc_error_sqlstates.properties\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
"pattern":"\\Qorg/firebirdsql/jaybird/version.properties\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
"pattern":"\\Qorg/firebirdsql/jaybird/version_zh.properties\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
"pattern":"\\Qorg/firebirdsql/jaybird/version_zh_CN.properties\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
"pattern":"\\Qorg/firebirdsql/jaybird/version_zh_Hans.properties\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
"pattern":"\\Qorg/firebirdsql/jaybird/version_zh_Hans_CN.properties\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.gds.MessageLoader"},
"pattern":"\\Qorg/firebirdsql/jaybird_error_msg.properties\\E"
}, {
"condition":{"typeReachable":"org.firebirdsql.gds.MessageLoader"},
"pattern":"\\Qorg/firebirdsql/jaybird_error_sqlstates.properties\\E"
}]},
"bundles":[{
"name":"org.firebirdsql.jaybird.version",
"locales":["zh-CN", "en"]
}]
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public boolean containsProviderType(final String providerType) {
public void close() {
dataSourceMap.clear();
SeataTransactionHolder.clear();
RmNettyRemotingClient.getInstance().destroy();
TmNettyRemotingClient.getInstance().destroy();
RmNettyRemotingClient.getInstance().destroy();
ConfigurationFactory.reload();
}

Expand Down
5 changes: 5 additions & 0 deletions test/native/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.firebirdsql.jdbc</groupId>
<artifactId>jaybird</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,15 @@ public void cleanEnvironment() throws SQLException {
orderItemRepository.dropTableInMySQL();
addressRepository.dropTableInMySQL();
}

/**
* Clean environment in Firebird.
*
* @throws SQLException An exception that provides information on a database access error or other errors.
*/
public void cleanEnvironmentInFirebird() throws SQLException {
orderRepository.dropTableInFirebird();
orderItemRepository.dropTableInFirebird();
addressRepository.dropTableInFirebird();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
import lombok.Getter;
import org.apache.curator.test.InstanceSpec;
import org.apache.shardingsphere.proxy.Bootstrap;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.awaitility.Awaitility;

import java.io.IOException;
import java.sql.SQLException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

/**
* This class is designed to start ShardingSphere Proxy directly in the current process,
Expand All @@ -36,7 +37,7 @@
@Getter
public final class ProxyTestingServer {

private final int proxyPort = InstanceSpec.getRandomPort();
private final int proxyPort;

private final CompletableFuture<Void> completableFuture;

Expand All @@ -46,6 +47,7 @@ public final class ProxyTestingServer {
* @param configAbsolutePath The absolute path to the directory where {@code global.yaml} is located.
*/
public ProxyTestingServer(final String configAbsolutePath) {
proxyPort = InstanceSpec.getRandomPort();
completableFuture = CompletableFuture.runAsync(() -> {
try {
Bootstrap.main(new String[]{String.valueOf(proxyPort), configAbsolutePath, "0.0.0.0", "false"});
Expand All @@ -56,10 +58,10 @@ public ProxyTestingServer(final String configAbsolutePath) {
}

/**
* Force close ShardingSphere Proxy. See {@link org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy#close}.
* Force close ShardingSphere Proxy.
*/
public void close() {
ProxyContext.getInstance().getContextManager().close();
completableFuture.cancel(false);
Awaitility.await().atMost(1L, TimeUnit.MINUTES).until(completableFuture::isDone);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ public void createTableInSQLServer() throws SQLException {
}
}

/**
* create table t_address in Firebird.
* Cannot use `create table if not exists` for Docker Image `ghcr.io/fdcastel/firebird:5.0.1`,
* see <a href="https://github.com/FirebirdSQL/firebird/issues/8062">FirebirdSQL/firebird#8062</a>.
*
* @throws SQLException SQL exception
*/
public void createTableInFirebird() throws SQLException {
String sql = "CREATE TABLE t_address (address_id BIGINT NOT NULL PRIMARY KEY, address_name VARCHAR(100) NOT NULL)";
try (
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
statement.executeUpdate(sql);
}
}

/**
* drop table t_address in MySQL.
*
Expand All @@ -84,6 +100,22 @@ public void dropTableInMySQL() throws SQLException {
}
}

/**
* drop table in Firebird.
* Docker Image `ghcr.io/fdcastel/firebird:5.0.1` does not work with `DROP TABLE IF EXISTS`.
* See <a href="https://github.com/FirebirdSQL/firebird/issues/4203">FirebirdSQL/firebird#4203</a> .
*
* @throws SQLException SQL exception
*/
public void dropTableInFirebird() throws SQLException {
String sql = "DROP TABLE t_address";
try (
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
statement.executeUpdate(sql);
}
}

/**
* truncate table t_address.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ public void createTableInSQLServer() throws SQLException {
}
}

/**
* create table in Firebird.
* Cannot use `create table if not exists` for Docker Image `ghcr.io/fdcastel/firebird:5.0.1`,
* see <a href="https://github.com/FirebirdSQL/firebird/issues/8062">FirebirdSQL/firebird#8062</a>.
*
* @throws SQLException SQL exception
*/
public void createTableInFirebird() throws SQLException {
String sql = "CREATE TABLE t_order_item \n"
+ "(order_item_id BIGINT generated by default as identity PRIMARY KEY,\n"
+ "order_id BIGINT NOT NULL,\n"
+ "user_id INT NOT NULL,\n"
+ "phone VARCHAR(50),\n"
+ "status VARCHAR(50)\n"
+ ")";
try (
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
statement.executeUpdate(sql);
}
}

/**
* drop table in MySQL.
*
Expand All @@ -116,6 +138,22 @@ public void dropTableInMySQL() throws SQLException {
}
}

/**
* drop table in Firebird.
* Docker Image `ghcr.io/fdcastel/firebird:5.0.1` does not work with `DROP TABLE IF EXISTS`.
* See <a href="https://github.com/FirebirdSQL/firebird/issues/4203">FirebirdSQL/firebird#4203</a> .
*
* @throws SQLException SQL exception
*/
public void dropTableInFirebird() throws SQLException {
String sql = "DROP TABLE t_order_item";
try (
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement()) {
statement.executeUpdate(sql);
}
}

/**
* truncate table.
*
Expand Down
Loading

0 comments on commit 98a94fc

Please sign in to comment.