Skip to content

Commit

Permalink
Bump Junit Platform to 5.10.3 to support using `@EnabledInNativeImage…
Browse files Browse the repository at this point in the history
…` on the test classes
  • Loading branch information
linghengqian committed Jul 4, 2024
1 parent dab3777 commit 3396522
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,14 @@ Caused by: java.io.UnsupportedEncodingException: Codepage Cp1252 is not supporte
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ Possible configuration examples are as follows,
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"condition":{"typeReachable":"com.github.dockerjava.api.model.RuntimeInfo"},
"name":"com.github.dockerjava.api.model.RuntimeInfo",
"allPublicConstructors": true
}
]
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@
<opentelemetry.version>1.31.0</opentelemetry.version>
<kotlin-stdlib.version>1.9.10</kotlin-stdlib.version>

<junit.version>5.10.2</junit.version>
<junit.version>5.10.3</junit.version>
<hamcrest.version>2.2</hamcrest.version>
<mockito.version>4.11.0</mockito.version>
<awaitility.version>4.2.0</awaitility.version>
<testcontainers.version>1.19.3</testcontainers.version>
<testcontainers.version>1.19.8</testcontainers.version>
<commons-csv.version>1.9.0</commons-csv.version>

<graal-sdk.version>24.0.0</graal-sdk.version>
<graal-sdk.version>24.0.1</graal-sdk.version>
<jedis.version>4.4.6</jedis.version>

<!-- 3rd party library plugin versions -->
Expand Down
8 changes: 8 additions & 0 deletions test/native/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ using Seata Client under GraalVM Native Image requires using the version release
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
</exclusion>
<exclusion>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,6 @@ public Long insert(final Order order, final int autoGeneratedKeys) throws SQLExc
return order.getOrderId();
}

/**
* insert Order to table without auto generated key. Databases like ClickHouse do not support returning auto generated keys after executing SQL,
* see <a href="https://github.com/ClickHouse/ClickHouse/issues/56228">ClickHouse/ClickHouse#56228</a> .
*
* @param order order
* @throws SQLException SQL Exception
*/
public void insertWithoutAutoGeneratedKey(final Order order) throws SQLException {
insert(order, Statement.NO_GENERATED_KEYS);
}

/**
* delete by orderId.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

@EnabledInNativeImage
class ClickHouseTest {

private TestShardingService testShardingService;
Expand All @@ -37,7 +38,6 @@ class ClickHouseTest {
* after {@link TestShardingService#processSuccessInClickHouse()}.
*
*/
@EnabledInNativeImage
@Test
void assertShardingInLocalTransactions() {
HikariConfig config = new HikariConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.zaxxer.hikari.HikariDataSource;
import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService;
import org.awaitility.Awaitility;
import org.junit.ClassRule;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledInNativeImage;
import org.testcontainers.containers.GenericContainer;
Expand All @@ -43,6 +46,7 @@
* Unable to use `org.testcontainers:mysql:1.19.3` under GraalVM Native Image.
* Background comes from <a href="https://github.com/testcontainers/testcontainers-java/issues/7954">testcontainers/testcontainers-java#7954</a>.
*/
@EnabledInNativeImage
class MySQLTest {

private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.database.mysql.";
Expand All @@ -53,27 +57,40 @@ class MySQLTest {

private static final String DATABASE = "test";

@SuppressWarnings("resource")
@ClassRule
public static GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("mysql:8.4.0-oracle"))
.withEnv("MYSQL_DATABASE", DATABASE)
.withEnv("MYSQL_ROOT_PASSWORD", PASSWORD)
.withExposedPorts(3306);

private String jdbcUrlPrefix;

private TestShardingService testShardingService;

@SuppressWarnings("resource")
@BeforeAll
static void beforeAll() {
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue()));
}

@AfterAll
static void afterAll() {
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url");
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url");
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url");
}

@Test
@EnabledInNativeImage
void assertShardingInLocalTransactions() throws SQLException {
try (
GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("mysql:8.4.0-oracle"))
.withEnv("MYSQL_DATABASE", DATABASE)
.withEnv("MYSQL_ROOT_PASSWORD", PASSWORD)
.withExposedPorts(3306)) {
container.start();
jdbcUrlPrefix = "jdbc:mysql://localhost:" + container.getMappedPort(3306) + "/";
DataSource dataSource = createDataSource();
testShardingService = new TestShardingService(dataSource);
initEnvironment();
testShardingService.processSuccess();
testShardingService.cleanEnvironment();
}
container.start();
jdbcUrlPrefix = "jdbc:mysql://localhost:" + container.getMappedPort(3306) + "/";
DataSource dataSource = createDataSource();
testShardingService = new TestShardingService(dataSource);
initEnvironment();
testShardingService.processSuccess();
testShardingService.cleanEnvironment();
}

private void initEnvironment() throws SQLException {
Expand All @@ -94,11 +111,10 @@ private Connection openConnection() throws SQLException {

@SuppressWarnings({"SqlDialectInspection", "SqlNoDataSourceInspection"})
private DataSource createDataSource() throws SQLException {
Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptionsMatching(e -> e instanceof CommunicationsException)
.until(() -> {
openConnection().close();
return true;
});
Awaitility.await().atMost(Duration.ofMinutes(1L)).ignoreExceptionsMatching(e -> e instanceof CommunicationsException).until(() -> {
openConnection().close();
return true;
});
try (
Connection connection = openConnection();
Statement statement = connection.createStatement()) {
Expand All @@ -109,18 +125,9 @@ private DataSource createDataSource() throws SQLException {
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/databases/mysql.yaml?placeholder-type=system_props");
try {
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue()));
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0");
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1");
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2");
return new HikariDataSource(config);
} finally {
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url");
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url");
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url");
}
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0");
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1");
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2");
return new HikariDataSource(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import com.zaxxer.hikari.HikariDataSource;
import org.apache.shardingsphere.test.natived.jdbc.commons.TestShardingService;
import org.awaitility.Awaitility;
import org.junit.ClassRule;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledInNativeImage;
import org.testcontainers.containers.GenericContainer;
Expand All @@ -38,6 +41,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

@EnabledInNativeImage
class OpenGaussTest {

private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.database.opengauss.";
Expand All @@ -48,26 +52,39 @@ class OpenGaussTest {

private static final String DATABASE = "postgres";

@SuppressWarnings("resource")
@ClassRule
public static GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("opengauss/opengauss:5.0.0"))
.withEnv("GS_PASSWORD", PASSWORD)
.withExposedPorts(5432);

private String jdbcUrlPrefix;

private TestShardingService testShardingService;

@SuppressWarnings("resource")
@BeforeAll
static void beforeAll() {
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue()));
}

@AfterAll
static void afterAll() {
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url");
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url");
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url");
}

@Test
@EnabledInNativeImage
void assertShardingInLocalTransactions() throws SQLException {
try (
GenericContainer<?> openGaussContainer = new GenericContainer<>(DockerImageName.parse("opengauss/opengauss:5.0.0"))
.withEnv("GS_PASSWORD", PASSWORD)
.withExposedPorts(5432)) {
openGaussContainer.start();
jdbcUrlPrefix = "jdbc:opengauss://localhost:" + openGaussContainer.getMappedPort(5432) + "/";
DataSource dataSource = createDataSource();
testShardingService = new TestShardingService(dataSource);
initEnvironment();
testShardingService.processSuccess();
testShardingService.cleanEnvironment();
}
container.start();
jdbcUrlPrefix = "jdbc:opengauss://localhost:" + container.getMappedPort(5432) + "/";
DataSource dataSource = createDataSource();
testShardingService = new TestShardingService(dataSource);
initEnvironment();
testShardingService.processSuccess();
testShardingService.cleanEnvironment();
}

private void initEnvironment() throws SQLException {
Expand Down Expand Up @@ -102,18 +119,9 @@ private DataSource createDataSource() throws SQLException {
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/databases/opengauss.yaml?placeholder-type=system_props");
try {
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url"), is(nullValue()));
assertThat(System.getProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url"), is(nullValue()));
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0");
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1");
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2");
return new HikariDataSource(config);
} finally {
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url");
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url");
System.clearProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url");
}
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds0.jdbc-url", jdbcUrlPrefix + "demo_ds_0");
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds1.jdbc-url", jdbcUrlPrefix + "demo_ds_1");
System.setProperty(SYSTEM_PROP_KEY_PREFIX + "ds2.jdbc-url", jdbcUrlPrefix + "demo_ds_2");
return new HikariDataSource(config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import javax.sql.DataSource;
import java.sql.SQLException;

@EnabledInNativeImage
class PostgresTest {

private TestShardingService testShardingService;

@EnabledInNativeImage
@Test
void assertShardingInLocalTransactions() throws SQLException {
HikariConfig config = new HikariConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import javax.sql.DataSource;
import java.sql.SQLException;

@EnabledInNativeImage
class SQLServerTest {

private TestShardingService testShardingService;

@EnabledInNativeImage
@Test
void assertShardingInLocalTransactions() throws SQLException {
HikariConfig config = new HikariConfig();
Expand Down
Loading

0 comments on commit 3396522

Please sign in to comment.