You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2026/08/15 11:26:50 UTC
(shardingsphere) branch master updated: Refactor SQL route tests and remove SQLRouteTest (#39469)
This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 122298f6797 Refactor SQL route tests and remove SQLRouteTest (#39469)
122298f6797 is described below
commit 122298f67978825e0cac51b00e552035650573c5
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Aug 15 19:26:43 2026 +0800
Refactor SQL route tests and remove SQLRouteTest (#39469)
* Refactor SQL route tests and remove SQLRouteTest
* Refactor SQL route tests and remove SQLRouteTest
---
.../type/ShardingRouteEngineFactoryTest.java | 16 ++++++
.../complex/ShardingComplexRouteEngineTest.java | 24 +++++++++
.../route/engine/type/standard/SQLRouteTest.java | 59 ----------------------
3 files changed, 40 insertions(+), 59 deletions(-)
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
index a282c2713dc..87801639f84 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactoryTest.java
@@ -30,7 +30,9 @@ import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.session.connection.ConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
import org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
+import org.apache.shardingsphere.sharding.route.engine.condition.value.ListShardingConditionValue;
import org.apache.shardingsphere.sharding.route.engine.type.broadcast.ShardingInstanceBroadcastRouteEngine;
import org.apache.shardingsphere.sharding.route.engine.type.broadcast.ShardingTableBroadcastRouteEngine;
import org.apache.shardingsphere.sharding.route.engine.type.complex.ShardingComplexRouteEngine;
@@ -183,6 +185,20 @@ class ShardingRouteEngineFactoryTest {
assertThat(actual, isA(ShardingStandardRouteEngine.class));
}
+ @Test
+ void assertNewInstanceForBindingTables() {
+ when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SQLStatement.class));
+ tableNames.add("t_order");
+ tableNames.add("t_order_item");
+ when(shardingRule.isBindingTablesUseShardingColumnsJoin(sqlStatementContext, tableNames)).thenReturn(true);
+ ShardingCondition shardingCondition = new ShardingCondition();
+ shardingCondition.getValues().add(new ListShardingConditionValue<>("user_id", "t_order", Collections.singleton(1L)));
+ when(shardingConditions.getConditions()).thenReturn(Collections.singletonList(shardingCondition));
+ QueryContext queryContext = new QueryContext(sqlStatementContext, "", Collections.emptyList(), new HintValueContext(), mockConnectionContext(), mock(ShardingSphereMetaData.class));
+ ShardingRouteEngine actual = ShardingRouteEngineFactory.newInstance(shardingRule, database, queryContext, shardingConditions, tableNames, props);
+ assertThat(actual, isA(ShardingStandardRouteEngine.class));
+ }
+
@Test
void assertNewInstanceForComplex() {
when(sqlStatementContext.getSqlStatement()).thenReturn(mock(SQLStatement.class));
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRouteEngineTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRouteEngineTest.java
index 3de98e25069..4018781a424 100644
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRouteEngineTest.java
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/complex/ShardingComplexRouteEngineTest.java
@@ -23,6 +23,9 @@ import org.apache.shardingsphere.infra.hint.HintValueContext;
import org.apache.shardingsphere.infra.route.context.RouteContext;
import org.apache.shardingsphere.infra.route.context.RouteUnit;
import org.apache.shardingsphere.sharding.exception.metadata.ShardingTableRuleNotFoundException;
+import org.apache.shardingsphere.sharding.route.engine.condition.ShardingCondition;
+import org.apache.shardingsphere.sharding.route.engine.condition.ShardingConditions;
+import org.apache.shardingsphere.sharding.route.engine.condition.value.ListShardingConditionValue;
import org.apache.shardingsphere.sharding.route.engine.fixture.ShardingRouteEngineFixtureBuilder;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.junit.jupiter.api.Test;
@@ -31,7 +34,9 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.stream.Collectors;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -66,6 +71,25 @@ class ShardingComplexRouteEngineTest {
assertThat(routeUnits.get(0).getTableMappers().iterator().next().getLogicName(), is("t_order"));
}
+ @Test
+ void assertRoutingForMultipleShardingTables() {
+ ShardingCondition shardingCondition = new ShardingCondition();
+ shardingCondition.getValues().add(new ListShardingConditionValue<>("user_id", "t_order", Collections.singleton(1L)));
+ shardingCondition.getValues().add(new ListShardingConditionValue<>("user_id", "t_user", Collections.singleton(1L)));
+ ShardingConditions shardingConditions = new ShardingConditions(
+ Collections.singletonList(shardingCondition), mock(SQLStatementContext.class), mock(ShardingRule.class));
+ ShardingComplexRouteEngine routeEngine = new ShardingComplexRouteEngine(shardingConditions,
+ mock(SQLStatementContext.class), new HintValueContext(), new ConfigurationProperties(new Properties()), Arrays.asList("t_order", "t_user"));
+ RouteContext routeContext = routeEngine.route(ShardingRouteEngineFixtureBuilder.createAllShardingRule());
+ List<RouteUnit> routeUnits = new ArrayList<>(routeContext.getRouteUnits());
+ assertThat(routeUnits.size(), is(1));
+ assertThat(routeUnits.get(0).getDataSourceMapper().getActualName(), is("ds_1"));
+ Map<String, String> actualTableNames = routeUnits.get(0).getTableMappers().stream().collect(Collectors.toMap(each -> each.getLogicName(), each -> each.getActualName()));
+ assertThat(actualTableNames.size(), is(2));
+ assertThat(actualTableNames.get("t_order"), is("t_order_1"));
+ assertThat(actualTableNames.get("t_user"), is("t_user_1"));
+ }
+
@Test
void assertRoutingForShardingTableJoinWithUpperCase() {
ShardingComplexRouteEngine routeEngine = new ShardingComplexRouteEngine(ShardingRouteEngineFixtureBuilder.createShardingConditions("T_ORDER"),
diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SQLRouteTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SQLRouteTest.java
deleted file mode 100644
index 8d4a7711454..00000000000
--- a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/route/engine/type/standard/SQLRouteTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.sharding.route.engine.type.standard;
-
-import org.apache.shardingsphere.sharding.route.engine.type.standard.assertion.ShardingRouteAssert;
-import org.junit.jupiter.api.extension.ExtensionContext;
-import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
-import org.junit.jupiter.params.provider.ArgumentsSource;
-import org.junit.jupiter.params.support.ParameterDeclarations;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.stream.Stream;
-
-class SQLRouteTest {
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertRoute(final String name, final String sql, final List<Object> params) {
- // TODO add assertion for ShardingRouteAssert.assertRoute
- ShardingRouteAssert.assertRoute(sql, params);
- }
-
- private static final class TestCaseArgumentsProvider implements ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(
- Arguments.of("noTableUnicastRandomDataSource", "SELECT 1, 1 + 2", Collections.singletonList(1)),
- Arguments.of("withBroadcastTable", "SELECT a.user_id, status from t_order_item a join t_product b on a.product_id = b.product_id where a.user_id = ?",
- Collections.singletonList(1)),
- Arguments.of("allBindingWithBroadcastTable",
- "SELECT a.user_id, a.status from t_order a join t_order_item b on a.order_id = b.order_id join t_product c on b.product_id = c.product_id where a.user_id = ?",
- Collections.singletonList(1)),
- Arguments.of("complexTableWithBroadcastTable",
- "SELECT a.user_id, status from t_order a join t_user b on a.user_id = b.user_id join t_product c on a.product_id = c.product_id where a.user_id = ? and b.user_id =?",
- Arrays.asList(1, 1)),
- Arguments.of("insertTable", "INSERT INTO t_order (order_id, user_id) VALUES (?, ?)", Arrays.asList(1, 1)));
- }
- }
-}