This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new e091c4b1dc5 Refactor ClickHouseTest (#36666)
e091c4b1dc5 is described below
commit e091c4b1dc51b1a0e7f75f9ec2be6bbae4169768
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Sep 23 12:27:48 2025 +0800
Refactor ClickHouseTest (#36666)
---
.../test/natived/commons/TestShardingService.java | 36 +++++++++-------------
.../natived/jdbc/databases/ClickHouseTest.java | 6 ++--
2 files changed, 19 insertions(+), 23 deletions(-)
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java
index ca22ad7237d..3a2913247fa 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/commons/TestShardingService.java
@@ -73,15 +73,15 @@ public final class TestShardingService {
* @throws SQLException An exception that provides information on a
database access error or other errors
*/
public void processSuccessInClickHouse() throws SQLException {
- final Collection<Long> orderIds =
insertData(Statement.NO_GENERATED_KEYS);
- extracted();
+ Collection<Long> orderIds = insertData(Statement.NO_GENERATED_KEYS);
+ assertQueryInClickHouse();
deleteDataInClickHouse(orderIds);
assertTrue(orderRepository.selectAll().isEmpty());
assertTrue(orderItemRepository.selectAll().isEmpty());
assertTrue(addressRepository.selectAll().isEmpty());
}
- private void extracted() throws SQLException {
+ private void assertQueryInClickHouse() throws SQLException {
Collection<Order> orders = orderRepository.selectAll();
assertThat(orders.stream().map(Order::getOrderId).collect(Collectors.toList()),
not(empty()));
assertThat(orders.stream().map(Order::getOrderType).collect(Collectors.toList()),
@@ -105,6 +105,15 @@ public final class TestShardingService {
is(LongStream.range(1L, 11L).mapToObj(each -> new
Address(each, "address_test_" + each)).collect(Collectors.toSet())));
}
+ private void deleteDataInClickHouse(final Collection<Long> orderIds)
throws SQLException {
+ long count = 1L;
+ for (Long each : orderIds) {
+ orderRepository.deleteInClickHouse(each);
+ orderItemRepository.deleteInClickHouse(each);
+ addressRepository.deleteInClickHouse(count++);
+ }
+ }
+
/**
* Process success in Hive.
* Hive has not fully supported BEGIN, COMMIT, and ROLLBACK. Refer to <a
href="https://cwiki.apache.org/confluence/display/Hive/Hive+Transactions">Hive
Transactions</a>.
@@ -115,7 +124,7 @@ public final class TestShardingService {
* @throws SQLException An exception that provides information on a
database access error or other errors
*/
public void processSuccessInHive() throws SQLException {
- final Collection<Long> orderIds =
insertData(Statement.RETURN_GENERATED_KEYS);
+ Collection<Long> orderIds =
insertData(Statement.RETURN_GENERATED_KEYS);
deleteData(orderIds);
assertTrue(orderRepository.selectAll().isEmpty());
assertTrue(orderItemRepository.selectAll().isEmpty());
@@ -133,8 +142,8 @@ public final class TestShardingService {
* @throws SQLException SQL exception
*/
public void processSuccessWithoutTransactions() throws SQLException {
- final Collection<Long> orderIds =
insertData(Statement.RETURN_GENERATED_KEYS);
- extracted();
+ Collection<Long> orderIds =
insertData(Statement.RETURN_GENERATED_KEYS);
+ assertQueryInClickHouse();
deleteData(orderIds);
assertTrue(orderRepository.selectAll().isEmpty());
assertTrue(orderItemRepository.selectAll().isEmpty());
@@ -185,21 +194,6 @@ public final class TestShardingService {
}
}
- /**
- * Delete data in ClickHouse.
- *
- * @param orderIds orderId of the insert statement
- * @throws SQLException An exception that provides information on a
database access error or other errors
- */
- public void deleteDataInClickHouse(final Collection<Long> orderIds) throws
SQLException {
- long count = 1L;
- for (Long each : orderIds) {
- orderRepository.deleteInClickHouse(each);
- orderItemRepository.deleteInClickHouse(each);
- addressRepository.deleteInClickHouse(count++);
- }
- }
-
/**
* Clean environment.
*
diff --git
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java
index 7a0170cba97..49761529cdf 100644
---
a/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java
+++
b/test/native/src/test/java/org/apache/shardingsphere/test/natived/jdbc/databases/ClickHouseTest.java
@@ -30,6 +30,8 @@ import org.testcontainers.junit.jupiter.Testcontainers;
import javax.sql.DataSource;
import java.sql.SQLException;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
@EnabledInNativeImage
@Testcontainers
class ClickHouseTest {
@@ -43,12 +45,12 @@ class ClickHouseTest {
}
@Test
- void assertShardingInLocalTransactions() throws SQLException {
+ void assertShardingInLocalTransactions() {
HikariConfig config = new HikariConfig();
config.setDriverClassName("org.apache.shardingsphere.driver.ShardingSphereDriver");
config.setJdbcUrl("jdbc:shardingsphere:classpath:test-native/yaml/jdbc/databases/clickhouse.yaml");
logicDataSource = new HikariDataSource(config);
TestShardingService testShardingService = new
TestShardingService(logicDataSource);
- testShardingService.processSuccessInClickHouse();
+ assertDoesNotThrow(testShardingService::processSuccessInClickHouse);
}
}