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

Fixes @EnabledInNativeImage failure in some unit tests #30031

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import io.etcd.jetcd.test.EtcdClusterExtension;
import io.etcd.jetcd.launcher.Etcd;
import io.etcd.jetcd.launcher.EtcdCluster;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
Expand All @@ -30,27 +31,20 @@
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledInNativeImage;
import org.junit.jupiter.api.extension.RegisterExtension;

import javax.sql.DataSource;
import java.io.IOException;
import java.net.URI;
import java.sql.SQLException;
import java.time.Duration;
import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;

@EnabledInNativeImage
class EtcdTest {

@RegisterExtension
public static final EtcdClusterExtension CLUSTER = EtcdClusterExtension.builder()
.withNodes(1)
.withMountDirectory(false)
.build();

private static final String SYSTEM_PROP_KEY_PREFIX = "fixture.test-native.yaml.mode.cluster.etcd.";

private TestShardingService testShardingService;
Expand All @@ -63,16 +57,24 @@ class EtcdTest {
* @see org.apache.shardingsphere.mode.repository.cluster.etcd.EtcdRepository
*/
@Test
@EnabledInNativeImage
void assertShardingInLocalTransactions() throws SQLException {
DataSource dataSource = createDataSource();
testShardingService = new TestShardingService(dataSource);
initEnvironment();
Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(() -> {
dataSource.getConnection().close();
return true;
});
testShardingService.processSuccess();
testShardingService.cleanEnvironment();
try (
EtcdCluster etcd = Etcd.builder()
.withNodes(1)
.withMountedDataDirectory(false)
.build()) {
etcd.start();
DataSource dataSource = createDataSource(etcd.clientEndpoints());
testShardingService = new TestShardingService(dataSource);
initEnvironment();
Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(() -> {
dataSource.getConnection().close();
return true;
});
testShardingService.processSuccess();
testShardingService.cleanEnvironment();
}
}

private void initEnvironment() throws SQLException {
Expand All @@ -84,8 +86,8 @@ private void initEnvironment() throws SQLException {
testShardingService.getAddressRepository().truncateTable();
}

private DataSource createDataSource() {
URI clientEndpoint = CLUSTER.clientEndpoints().get(0);
private DataSource createDataSource(final List<URI> clientEndpoints) {
URI clientEndpoint = clientEndpoints.get(0);
Awaitility.await().atMost(Duration.ofSeconds(30L)).ignoreExceptions().until(() -> verifyEtcdClusterRunning(clientEndpoint));
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
Expand Down
Loading