Skip to content

Commit 98a94fc

Browse files
authored
Add GraalVM Reachability Metadata and corresponding nativeTest for Firebird (#34307)
* Add GraalVM Reachability Metadata and corresponding nativeTest for Firebird * Fix the connection leak problem caused by improper configuration of unit test lifecycle
1 parent 7ef227a commit 98a94fc

File tree

40 files changed

+1683
-982
lines changed

40 files changed

+1683
-982
lines changed

RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

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

1213
### Bug Fixes
1314

infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/proxy-config.json

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource"},
1212
"interfaces":["org.apache.hive.service.rpc.thrift.TCLIService$Iface"]
1313
},
14-
{
15-
"condition":{"typeReachable":"org.apache.shardingsphere.proxy.initializer.BootstrapInitializer"},
16-
"interfaces":["org.apache.seata.config.Configuration"]
17-
},
1814
{
1915
"condition":{"typeReachable":"org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager"},
2016
"interfaces":["org.apache.seata.config.Configuration"]

infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/reflect-config.json

+300-258
Large diffs are not rendered by default.

infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/generated-reachability-metadata/resource-config.json

+392-407
Large diffs are not rendered by default.

infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/reflect-config.json

+10
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,16 @@
357357
"name":"org.apache.shardingsphere.sql.parser.statement.sqlserver.ddl.SQLServerDropTableStatement",
358358
"methods":[{"name":"<init>","parameterTypes":[] }]
359359
},
360+
{
361+
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdDeleteStatement"},
362+
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.dml.FirebirdDeleteStatement",
363+
"methods":[{"name":"<init>","parameterTypes":[] }]
364+
},
365+
{
366+
"condition":{"typeReachable":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdDropTableStatement"},
367+
"name":"org.apache.shardingsphere.sql.parser.statement.firebird.ddl.FirebirdDropTableStatement",
368+
"methods":[{"name":"<init>","parameterTypes":[] }]
369+
},
360370
{
361371
"condition":{"typeReachable":"javax.security.auth.login.Configuration"},
362372
"name":"sun.security.provider.ConfigFile",

infra/reachability-metadata/src/main/resources/META-INF/native-image/org.apache.shardingsphere/shardingsphere-infra-reachability-metadata/resource-config.json

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
"pattern":"\\QMETA-INF/services/javax.xml.parsers.SAXParserFactory\\E"
1515
}]},
1616
"bundles":[{
17+
"name":"com.sun.org.apache.xml.internal.serializer.XMLEntities",
18+
"locales":["en"]
19+
}, {
1720
"name":"com.microsoft.sqlserver.jdbc.SQLServerResource",
1821
"locales":["en"]
1922
}, {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
[
2+
{
3+
"condition":{"typeReachable":"org.firebirdsql.encodings.EncodingFactory"},
4+
"name":"org.firebirdsql.encodings.DefaultEncodingSet"
5+
},
6+
{
7+
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
8+
"name":"org.firebirdsql.gds.impl.jni.EmbeddedGDSFactoryPlugin"
9+
},
10+
{
11+
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
12+
"name":"org.firebirdsql.gds.impl.jni.NativeGDSFactoryPlugin"
13+
},
14+
{
15+
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
16+
"name":"org.firebirdsql.gds.impl.oo.OOGDSFactoryPlugin"
17+
},
18+
{
19+
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
20+
"name":"org.firebirdsql.gds.impl.wire.WireGDSFactoryPlugin"
21+
},
22+
{
23+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
24+
"name":"org.firebirdsql.gds.ng.wire.auth.legacy.LegacyAuthenticationPluginSpi"
25+
},
26+
{
27+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
28+
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp224AuthenticationPluginSpi"
29+
},
30+
{
31+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
32+
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp256AuthenticationPluginSpi"
33+
},
34+
{
35+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
36+
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp384AuthenticationPluginSpi"
37+
},
38+
{
39+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
40+
"name":"org.firebirdsql.gds.ng.wire.auth.srp.Srp512AuthenticationPluginSpi"
41+
},
42+
{
43+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
44+
"name":"org.firebirdsql.gds.ng.wire.auth.srp.SrpAuthenticationPluginSpi"
45+
},
46+
{
47+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.version13.V13WireOperations"},
48+
"name":"org.firebirdsql.gds.ng.wire.crypt.arc4.Arc4EncryptionPluginSpi",
49+
"methods":[{"name":"<init>","parameterTypes":[] }]
50+
},
51+
{
52+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.version13.V13WireOperations"},
53+
"name":"org.firebirdsql.gds.ng.wire.crypt.chacha.ChaChaEncryptionPluginSpi"
54+
},
55+
{
56+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
57+
"name":"org.firebirdsql.gds.ng.wire.version10.Version10Descriptor"
58+
},
59+
{
60+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
61+
"name":"org.firebirdsql.gds.ng.wire.version11.Version11Descriptor"
62+
},
63+
{
64+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
65+
"name":"org.firebirdsql.gds.ng.wire.version12.Version12Descriptor"
66+
},
67+
{
68+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
69+
"name":"org.firebirdsql.gds.ng.wire.version13.Version13Descriptor"
70+
},
71+
{
72+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
73+
"name":"org.firebirdsql.gds.ng.wire.version15.Version15Descriptor"
74+
},
75+
{
76+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
77+
"name":"org.firebirdsql.gds.ng.wire.version16.Version16Descriptor"
78+
},
79+
{
80+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
81+
"name":"org.firebirdsql.gds.ng.wire.version18.Version18Descriptor"
82+
},
83+
{
84+
"condition":{"typeReachable":"org.firebirdsql.jaybird.props.internal.UnregisteredDpbDefiner"},
85+
"name":"org.firebirdsql.jaybird.fb.constants.DpbItems",
86+
"allPublicFields":true
87+
},
88+
{
89+
"condition":{"typeReachable":"org.firebirdsql.jaybird.props.internal.UnregisteredDpbDefiner"},
90+
"name":"org.firebirdsql.jaybird.fb.constants.SpbItems",
91+
"allPublicFields":true
92+
},
93+
{
94+
"condition":{"typeReachable":"org.firebirdsql.jaybird.xca.FBManagedConnection"},
95+
"name":"org.firebirdsql.jaybird.xca.FBManagedConnection",
96+
"fields":[{"name":"connectionHandle"}, {"name":"unnotifiedWarnings"}]
97+
},
98+
{
99+
"condition":{"typeReachable":"org.firebirdsql.jaybird.xca.FBManagedConnectionFactory"},
100+
"name":"org.firebirdsql.jdbc.FBConnection",
101+
"methods":[{"name":"<init>","parameterTypes":["org.firebirdsql.jaybird.xca.FBManagedConnection"] }]
102+
},
103+
{
104+
"condition":{"typeReachable":"org.firebirdsql.jdbc.FBConnection"},
105+
"name":"org.firebirdsql.jdbc.FBConnection",
106+
"fields":[{"name":"savepointCounter"}]
107+
}
108+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"resources":{
3+
"includes":[{
4+
"condition":{"typeReachable":"org.firebirdsql.encodings.EncodingFactory"},
5+
"pattern":"\\QMETA-INF/services/org.firebirdsql.encodings.EncodingSet\\E"
6+
}, {
7+
"condition":{"typeReachable":"org.firebirdsql.gds.impl.GDSFactory"},
8+
"pattern":"\\QMETA-INF/services/org.firebirdsql.gds.impl.GDSFactoryPlugin\\E"
9+
}, {
10+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.ProtocolCollection"},
11+
"pattern":"\\QMETA-INF/services/org.firebirdsql.gds.ng.wire.ProtocolDescriptor\\E"
12+
}, {
13+
"condition":{"typeReachable":"org.firebirdsql.gds.ng.wire.auth.ClientAuthBlock"},
14+
"pattern":"\\QMETA-INF/services/org.firebirdsql.gds.ng.wire.auth.AuthenticationPluginSpi\\E"
15+
}, {
16+
"condition":{"typeReachable":"org.firebirdsql.jaybird.props.internal.ConnectionPropertyRegistry"},
17+
"pattern":"\\QMETA-INF/services/org.firebirdsql.jaybird.props.spi.ConnectionPropertyDefinerSpi\\E"
18+
}, {
19+
"condition":{"typeReachable":"org.firebirdsql.gds.MessageLoader"},
20+
"pattern":"\\Qisc_error_msg.properties\\E"
21+
}, {
22+
"condition":{"typeReachable":"org.firebirdsql.gds.MessageLoader"},
23+
"pattern":"\\Qisc_error_sqlstates.properties\\E"
24+
}, {
25+
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
26+
"pattern":"\\Qorg/firebirdsql/jaybird/version.properties\\E"
27+
}, {
28+
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
29+
"pattern":"\\Qorg/firebirdsql/jaybird/version_zh.properties\\E"
30+
}, {
31+
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
32+
"pattern":"\\Qorg/firebirdsql/jaybird/version_zh_CN.properties\\E"
33+
}, {
34+
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
35+
"pattern":"\\Qorg/firebirdsql/jaybird/version_zh_Hans.properties\\E"
36+
}, {
37+
"condition":{"typeReachable":"org.firebirdsql.jaybird.Version"},
38+
"pattern":"\\Qorg/firebirdsql/jaybird/version_zh_Hans_CN.properties\\E"
39+
}, {
40+
"condition":{"typeReachable":"org.firebirdsql.gds.MessageLoader"},
41+
"pattern":"\\Qorg/firebirdsql/jaybird_error_msg.properties\\E"
42+
}, {
43+
"condition":{"typeReachable":"org.firebirdsql.gds.MessageLoader"},
44+
"pattern":"\\Qorg/firebirdsql/jaybird_error_sqlstates.properties\\E"
45+
}]},
46+
"bundles":[{
47+
"name":"org.firebirdsql.jaybird.version",
48+
"locales":["zh-CN", "en"]
49+
}]
50+
}

kernel/transaction/type/base/seata-at/src/main/java/org/apache/shardingsphere/transaction/base/seata/at/SeataATShardingSphereTransactionManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ public boolean containsProviderType(final String providerType) {
155155
public void close() {
156156
dataSourceMap.clear();
157157
SeataTransactionHolder.clear();
158-
RmNettyRemotingClient.getInstance().destroy();
159158
TmNettyRemotingClient.getInstance().destroy();
159+
RmNettyRemotingClient.getInstance().destroy();
160160
ConfigurationFactory.reload();
161161
}
162162

test/native/pom.xml

+5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@
202202
</exclusion>
203203
</exclusions>
204204
</dependency>
205+
<dependency>
206+
<groupId>org.firebirdsql.jdbc</groupId>
207+
<artifactId>jaybird</artifactId>
208+
<scope>test</scope>
209+
</dependency>
205210
<dependency>
206211
<groupId>org.testcontainers</groupId>
207212
<artifactId>junit-jupiter</artifactId>

test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java

+11
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,15 @@ public void cleanEnvironment() throws SQLException {
200200
orderItemRepository.dropTableInMySQL();
201201
addressRepository.dropTableInMySQL();
202202
}
203+
204+
/**
205+
* Clean environment in Firebird.
206+
*
207+
* @throws SQLException An exception that provides information on a database access error or other errors.
208+
*/
209+
public void cleanEnvironmentInFirebird() throws SQLException {
210+
orderRepository.dropTableInFirebird();
211+
orderItemRepository.dropTableInFirebird();
212+
addressRepository.dropTableInFirebird();
213+
}
203214
}

test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/proxy/ProxyTestingServer.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@
2020
import lombok.Getter;
2121
import org.apache.curator.test.InstanceSpec;
2222
import org.apache.shardingsphere.proxy.Bootstrap;
23-
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
23+
import org.awaitility.Awaitility;
2424

2525
import java.io.IOException;
2626
import java.sql.SQLException;
2727
import java.util.concurrent.CompletableFuture;
28+
import java.util.concurrent.TimeUnit;
2829

2930
/**
3031
* This class is designed to start ShardingSphere Proxy directly in the current process,
@@ -36,7 +37,7 @@
3637
@Getter
3738
public final class ProxyTestingServer {
3839

39-
private final int proxyPort = InstanceSpec.getRandomPort();
40+
private final int proxyPort;
4041

4142
private final CompletableFuture<Void> completableFuture;
4243

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

5860
/**
59-
* Force close ShardingSphere Proxy. See {@link org.apache.shardingsphere.proxy.frontend.ShardingSphereProxy#close}.
61+
* Force close ShardingSphere Proxy.
6062
*/
6163
public void close() {
62-
ProxyContext.getInstance().getContextManager().close();
6364
completableFuture.cancel(false);
65+
Awaitility.await().atMost(1L, TimeUnit.MINUTES).until(completableFuture::isDone);
6466
}
6567
}

test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/repository/AddressRepository.java

+32
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ public void createTableInSQLServer() throws SQLException {
7070
}
7171
}
7272

73+
/**
74+
* create table t_address in Firebird.
75+
* Cannot use `create table if not exists` for Docker Image `ghcr.io/fdcastel/firebird:5.0.1`,
76+
* see <a href="https://github.com/FirebirdSQL/firebird/issues/8062">FirebirdSQL/firebird#8062</a>.
77+
*
78+
* @throws SQLException SQL exception
79+
*/
80+
public void createTableInFirebird() throws SQLException {
81+
String sql = "CREATE TABLE t_address (address_id BIGINT NOT NULL PRIMARY KEY, address_name VARCHAR(100) NOT NULL)";
82+
try (
83+
Connection connection = dataSource.getConnection();
84+
Statement statement = connection.createStatement()) {
85+
statement.executeUpdate(sql);
86+
}
87+
}
88+
7389
/**
7490
* drop table t_address in MySQL.
7591
*
@@ -84,6 +100,22 @@ public void dropTableInMySQL() throws SQLException {
84100
}
85101
}
86102

103+
/**
104+
* drop table in Firebird.
105+
* Docker Image `ghcr.io/fdcastel/firebird:5.0.1` does not work with `DROP TABLE IF EXISTS`.
106+
* See <a href="https://github.com/FirebirdSQL/firebird/issues/4203">FirebirdSQL/firebird#4203</a> .
107+
*
108+
* @throws SQLException SQL exception
109+
*/
110+
public void dropTableInFirebird() throws SQLException {
111+
String sql = "DROP TABLE t_address";
112+
try (
113+
Connection connection = dataSource.getConnection();
114+
Statement statement = connection.createStatement()) {
115+
statement.executeUpdate(sql);
116+
}
117+
}
118+
87119
/**
88120
* truncate table t_address.
89121
*

test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/repository/OrderItemRepository.java

+38
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ public void createTableInSQLServer() throws SQLException {
102102
}
103103
}
104104

105+
/**
106+
* create table in Firebird.
107+
* Cannot use `create table if not exists` for Docker Image `ghcr.io/fdcastel/firebird:5.0.1`,
108+
* see <a href="https://github.com/FirebirdSQL/firebird/issues/8062">FirebirdSQL/firebird#8062</a>.
109+
*
110+
* @throws SQLException SQL exception
111+
*/
112+
public void createTableInFirebird() throws SQLException {
113+
String sql = "CREATE TABLE t_order_item \n"
114+
+ "(order_item_id BIGINT generated by default as identity PRIMARY KEY,\n"
115+
+ "order_id BIGINT NOT NULL,\n"
116+
+ "user_id INT NOT NULL,\n"
117+
+ "phone VARCHAR(50),\n"
118+
+ "status VARCHAR(50)\n"
119+
+ ")";
120+
try (
121+
Connection connection = dataSource.getConnection();
122+
Statement statement = connection.createStatement()) {
123+
statement.executeUpdate(sql);
124+
}
125+
}
126+
105127
/**
106128
* drop table in MySQL.
107129
*
@@ -116,6 +138,22 @@ public void dropTableInMySQL() throws SQLException {
116138
}
117139
}
118140

141+
/**
142+
* drop table in Firebird.
143+
* Docker Image `ghcr.io/fdcastel/firebird:5.0.1` does not work with `DROP TABLE IF EXISTS`.
144+
* See <a href="https://github.com/FirebirdSQL/firebird/issues/4203">FirebirdSQL/firebird#4203</a> .
145+
*
146+
* @throws SQLException SQL exception
147+
*/
148+
public void dropTableInFirebird() throws SQLException {
149+
String sql = "DROP TABLE t_order_item";
150+
try (
151+
Connection connection = dataSource.getConnection();
152+
Statement statement = connection.createStatement()) {
153+
statement.executeUpdate(sql);
154+
}
155+
}
156+
119157
/**
120158
* truncate table.
121159
*

0 commit comments

Comments
 (0)