Skip to content

Commit

Permalink
Add GraalVM Reachability Metadata and corresponding nativeTest for Se…
Browse files Browse the repository at this point in the history
…ata integration
  • Loading branch information
linghengqian committed Feb 16, 2024
1 parent 2d554e7 commit ca9a874
Show file tree
Hide file tree
Showing 15 changed files with 425 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,25 @@
"fields":[{"name":"value"}]
},
{
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.NodeFactory"},
"name":"com.github.benmanes.caffeine.cache.PDMS",
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.PDW"},
"name":"com.github.benmanes.caffeine.cache.PDW",
"fields":[{"name":"writeTime"}]
},
{
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.SIMSW"},
"name":"com.github.benmanes.caffeine.cache.PDWMS",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.LocalCacheFactory"},
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalLoadingCache"},
"name":"com.github.benmanes.caffeine.cache.SIMS",
"methods":[{"name":"<init>","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }]
},
{
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.BoundedLocalCache$BoundedLocalManualCache"},
"name":"com.github.benmanes.caffeine.cache.SIMSW",
"methods":[{"name":"<init>","parameterTypes":["com.github.benmanes.caffeine.cache.Caffeine","com.github.benmanes.caffeine.cache.CacheLoader","boolean"] }]
},
{
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.StripedBuffer"},
"name":"com.github.benmanes.caffeine.cache.StripedBuffer",
Expand All @@ -58,5 +68,10 @@
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.StripedBuffer"},
"name":"java.lang.Thread",
"fields":[{"name":"threadLocalRandomProbe"}]
},
{
"condition":{"typeReachable":"com.github.benmanes.caffeine.cache.NodeFactory"},
"name":"com.github.benmanes.caffeine.cache.PDMS",
"methods":[{"name":"<init>","parameterTypes":[] }]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,6 @@
"condition":{"typeReachable":"org.apache.shardingsphere.infra.util.yaml.YamlEngine"},
"name":"org.apache.shardingsphere.driver.api.yaml.YamlJDBCConfigurationCustomizer"
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"},
"name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath.AbsolutePathURLProvider",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"},
"name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.absolutepath.AbsolutePathWithEnvironmentURLProvider",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"},
"name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathURLProvider",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"},
"name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathWithEnvironmentURLProvider",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.driver.jdbc.core.driver.ShardingSphereURLManager"},
"name":"org.apache.shardingsphere.driver.jdbc.core.driver.spi.classpath.ClasspathWithSystemPropsURLProvider",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.encrypt.rule.EncryptRule"},
"name":"org.apache.shardingsphere.encrypt.algorithm.assisted.MD5AssistedEncryptAlgorithm",
Expand Down Expand Up @@ -1191,6 +1166,16 @@
"condition":{"typeReachable":"org.apache.shardingsphere.infra.yaml.config.shortcut.YamlRuleConfigurationShortcuts"},
"name":"org.apache.shardingsphere.traffic.yaml.config.YamlTrafficRuleConfiguration"
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine"},
"name":"org.apache.shardingsphere.transaction.base.seata.at.SeataATShardingSphereTransactionManager",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.infra.executor.sql.hook.SPISQLExecutionHook"},
"name":"org.apache.shardingsphere.transaction.base.seata.at.SeataTransactionalSQLExecutionHook",
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"condition":{"typeReachable":"org.apache.shardingsphere.transaction.ShardingSphereTransactionManagerEngine"},
"name":"org.apache.shardingsphere.transaction.xa.XAShardingSphereTransactionManager",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ transport {
}
service {
#vgroup->rgroup
vgroupMapping.my_test_tx_group = "default"
vgroupMapping.default_tx_group = "default"
#only support single node
default.grouplist = "127.0.0.1:8891"
#degrade current not support
enableDegrade = false
#disable
disable = false
}
Expand All @@ -54,4 +52,7 @@ client {
retry.internal = 10
retry.times = 30
}
tm {
degradeCheck = false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ sharding.transaction.seata.tx.timeout = 30

client {
application.id = jdbc-test
transaction.service.group = my_test_tx_group
transaction.service.group = default_tx_group
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<narayana.version>5.12.4.Final</narayana.version>
<jboss-transaction-spi.version>7.6.0.Final</jboss-transaction-spi.version>
<jboss-logging.version>3.2.1.Final</jboss-logging.version>
<seata.version>1.6.1</seata.version>
<seata.version>1.7.1</seata.version>

<netty.version>4.1.106.Final</netty.version>
<bouncycastle.version>1.70</bouncycastle.version>
Expand Down
4 changes: 4 additions & 0 deletions test/native/native-image-filter/extra-filter.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
{"excludeClasses": "android.app.**"},
{"excludeClasses": "com.arjuna.**"},
{"excludeClasses": "com.atomikos.logging.**"},
{"excludeClasses": "com.alibaba.druid.**"},
{"excludeClasses": "com.fasterxml.jackson.databind.**"},
{"excludeClasses": "com.github.benmanes.caffeine.cache.**"},
{"excludeClasses": "com.github.dockerjava.api.**"},
Expand All @@ -30,10 +31,13 @@
{"excludeClasses": "ch.qos.logback.classic.**"},
{"excludeClasses": "io.grpc.**"},
{"excludeClasses": "io.netty.**"},
{"excludeClasses": "io.seata.**"},
{"excludeClasses": "io.vertx.core.**"},
{"excludeClasses": "groovy.**"},
{"excludeClasses": "libcore.io.**"},
{"excludeClasses": "net.bytebuddy.**"},
{"excludeClasses": "org.apache.calcite.**"},
{"excludeClasses": "org.apache.commons.logging.**"},
{"excludeClasses": "org.apache.logging.log4j.**"},
{"excludeClasses": "org.apache.log4j.**"},
{"excludeClasses": "org.apache.zookeeper.**"},
Expand Down
30 changes: 30 additions & 0 deletions test/native/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
<artifactId>shardingsphere-test-native</artifactId>
<name>${project.artifactId}</name>

<properties>
<!--Before merging https://github.com/apache/incubator-seata/pull/5234,
using Seata Client under GraalVM Native Image requires using the version released under its native branch-->
<seata.version>1.7.0-native-rc2</seata.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
Expand Down Expand Up @@ -61,31 +67,55 @@
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-transaction-xa-core</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-transaction-xa-narayana</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.narayana.jta</groupId>
<artifactId>jta</artifactId>
<version>${narayana.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.narayana.jts</groupId>
<artifactId>narayana-jts-integration</artifactId>
<version>${narayana.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-transaction-spi</artifactId>
<version>${jboss-transaction-spi.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>${jboss-logging.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-transaction-base-seata-at</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.seata</groupId>
<artifactId>seata-all</artifactId>
<version>${seata.version}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void processSuccess() throws SQLException {
assertThat(orderRepository.selectAll(), equalTo(new ArrayList<>()));
assertThat(orderItemRepository.selectAll(), equalTo(new ArrayList<>()));
assertThat(addressRepository.selectAll(), equalTo(new ArrayList<>()));
addressRepository.assertRollbackWithTransactions();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
import java.util.LinkedList;
import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
public final class AddressRepository {

Expand All @@ -39,6 +42,7 @@ public AddressRepository(final DataSource dataSource) {

/**
* create table t_address if not exists.
*
* @throws SQLException SQL exception
*/
public void createTableIfNotExists() throws SQLException {
Expand All @@ -53,6 +57,7 @@ public void createTableIfNotExists() throws SQLException {
/**
* create table t_address in MS SQL Server.
* This also ignored the default schema of the `dbo`.
*
* @throws SQLException SQL exception
*/
public void createTableInSQLServer() throws SQLException {
Expand All @@ -70,6 +75,7 @@ public void createTableInSQLServer() throws SQLException {

/**
* drop table t_address.
*
* @throws SQLException SQL exception
*/
public void dropTable() throws SQLException {
Expand All @@ -83,6 +89,7 @@ public void dropTable() throws SQLException {

/**
* truncate table t_address.
*
* @throws SQLException SQL exception
*/
public void truncateTable() throws SQLException {
Expand All @@ -96,6 +103,7 @@ public void truncateTable() throws SQLException {

/**
* insert something to table t_address.
*
* @param address address
* @return addressId of the insert statement
* @throws SQLException SQL exception
Expand All @@ -114,6 +122,7 @@ public Long insert(final Address address) throws SQLException {

/**
* delete by id.
*
* @param id id
* @throws SQLException SQL exception
*/
Expand All @@ -129,6 +138,7 @@ public void delete(final Long id) throws SQLException {

/**
* select all.
*
* @return list of address
* @throws SQLException SQL exception
*/
Expand All @@ -148,4 +158,30 @@ public List<Address> selectAll() throws SQLException {
}
return result;
}

/**
* Assert rollback with transactions.
* This is currently just a simple test against a non-existent table and does not involve the competition scenario of distributed transactions.
*
* @throws SQLException An exception that provides information on a database access error or other errors.
*/
public void assertRollbackWithTransactions() throws SQLException {
Connection connection = dataSource.getConnection();
try {
connection.setAutoCommit(false);
connection.createStatement().executeUpdate("INSERT INTO t_address (address_id, address_name) VALUES (2024, 'address_test_2024')");
connection.createStatement().executeUpdate("INSERT INTO t_table_does_not_exist (test_id_does_not_exist) VALUES (2024)");
connection.commit();
} catch (SQLException e) {
connection.rollback();
} finally {
connection.setAutoCommit(true);
connection.close();
}
try (
Connection conn = dataSource.getConnection();
ResultSet resultSet = conn.createStatement().executeQuery("SELECT * FROM t_address WHERE address_id = 2024")) {
assertThat(resultSet.next(), is(false));
}
}
}
Loading

0 comments on commit ca9a874

Please sign in to comment.