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 4c17bbfa17d Align DistSQL executor tests with production SPIs (#40053)
4c17bbfa17d is described below

commit 4c17bbfa17d32cae555dd42832b03ed736b8d660
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Oct 4 22:36:59 2026 +0800

    Align DistSQL executor tests with production SPIs (#40053)
---
 .../DistSQLExecutorConcurrentIsolationTest.java    | 114 ---------------------
 .../spi/query/DistSQLQueryExecutorTest.java        |  69 +++++++++++++
 .../spi/update/DistSQLUpdateExecutorTest.java      |  69 +++++++++++++
 .../DatabaseRuleDefinitionExecutorTest.java        |  70 +++++++++++++
 4 files changed, 208 insertions(+), 114 deletions(-)

diff --git 
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/concurrent/DistSQLExecutorConcurrentIsolationTest.java
 
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/concurrent/DistSQLExecutorConcurrentIsolationTest.java
deleted file mode 100644
index f50945c6a71..00000000000
--- 
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/engine/concurrent/DistSQLExecutorConcurrentIsolationTest.java
+++ /dev/null
@@ -1,114 +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.distsql.handler.engine.concurrent;
-
-import 
org.apache.shardingsphere.distsql.handler.engine.concurrent.fixture.FixtureDatabaseRuleDefinitionStatement;
-import 
org.apache.shardingsphere.distsql.handler.engine.concurrent.fixture.FixtureDistSQLQueryStatement;
-import 
org.apache.shardingsphere.distsql.handler.engine.concurrent.fixture.FixtureDistSQLUpdateStatement;
-import 
org.apache.shardingsphere.distsql.handler.engine.concurrent.fixture.FixtureRule;
-import 
org.apache.shardingsphere.distsql.handler.executor.aware.DistSQLExecutorRuleAware;
-import 
org.apache.shardingsphere.distsql.handler.executor.spi.query.DistSQLQueryExecutor;
-import 
org.apache.shardingsphere.distsql.handler.executor.spi.update.DistSQLUpdateExecutor;
-import 
org.apache.shardingsphere.distsql.handler.executor.spi.update.rule.database.DatabaseRuleDefinitionExecutor;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.junit.jupiter.api.Test;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.Matchers.not;
-import static org.hamcrest.Matchers.sameInstance;
-
-class DistSQLExecutorConcurrentIsolationTest {
-    
-    private static final int THREAD_COUNT = 2;
-    
-    private static final int TIMEOUT_SECONDS = 10;
-    
-    @Test
-    void assertDatabaseRuleDefinitionExecutorConcurrentIsolation() throws 
Exception {
-        CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);
-        assertConcurrentIsolation(createDatabaseRuleDefinitionTask(barrier, 
new FixtureRule("first")), createDatabaseRuleDefinitionTask(barrier, new 
FixtureRule("second")));
-    }
-    
-    @Test
-    void assertDistSQLQueryExecutorConcurrentIsolation() throws Exception {
-        CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);
-        assertConcurrentIsolation(createDistSQLQueryTask(barrier, new 
FixtureRule("first")), createDistSQLQueryTask(barrier, new 
FixtureRule("second")));
-    }
-    
-    @Test
-    void assertDistSQLUpdateExecutorConcurrentIsolation() throws Exception {
-        CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);
-        assertConcurrentIsolation(createDistSQLUpdateTask(barrier, new 
FixtureRule("first")), createDistSQLUpdateTask(barrier, new 
FixtureRule("second")));
-    }
-    
-    @SuppressWarnings("unchecked")
-    private Callable<Object> createDatabaseRuleDefinitionTask(final 
CyclicBarrier barrier, final FixtureRule expectedRule) {
-        return () -> {
-            
DatabaseRuleDefinitionExecutor<FixtureDatabaseRuleDefinitionStatement, 
ShardingSphereRule> executor =
-                    
TypedSPILoader.getService(DatabaseRuleDefinitionExecutor.class, 
FixtureDatabaseRuleDefinitionStatement.class);
-            executor.setDatabase(null);
-            executor.setRule(expectedRule);
-            barrier.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
-            executor.checkBeforeUpdate(new 
FixtureDatabaseRuleDefinitionStatement(expectedRule));
-            return executor;
-        };
-    }
-    
-    @SuppressWarnings("unchecked")
-    private Callable<Object> createDistSQLQueryTask(final CyclicBarrier 
barrier, final FixtureRule expectedRule) {
-        return () -> {
-            DistSQLQueryExecutor<FixtureDistSQLQueryStatement> executor = 
TypedSPILoader.getService(DistSQLQueryExecutor.class, 
FixtureDistSQLQueryStatement.class);
-            ((DistSQLExecutorRuleAware<ShardingSphereRule>) 
executor).setRule(expectedRule);
-            barrier.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
-            executor.getColumnNames(new 
FixtureDistSQLQueryStatement(expectedRule));
-            return executor;
-        };
-    }
-    
-    @SuppressWarnings("unchecked")
-    private Callable<Object> createDistSQLUpdateTask(final CyclicBarrier 
barrier, final FixtureRule expectedRule) {
-        return () -> {
-            DistSQLUpdateExecutor<FixtureDistSQLUpdateStatement> executor = 
TypedSPILoader.getService(DistSQLUpdateExecutor.class, 
FixtureDistSQLUpdateStatement.class);
-            ((DistSQLExecutorRuleAware<ShardingSphereRule>) 
executor).setRule(expectedRule);
-            barrier.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
-            executor.executeUpdate(new 
FixtureDistSQLUpdateStatement(expectedRule), null);
-            return executor;
-        };
-    }
-    
-    private void assertConcurrentIsolation(final Callable<Object> firstTask, 
final Callable<Object> secondTask) throws Exception {
-        ExecutorService executorService = 
Executors.newFixedThreadPool(THREAD_COUNT);
-        try {
-            Future<Object> firstFuture = executorService.submit(firstTask);
-            Future<Object> secondFuture = executorService.submit(secondTask);
-            Object firstExecutor = firstFuture.get(TIMEOUT_SECONDS, 
TimeUnit.SECONDS);
-            Object secondExecutor = secondFuture.get(TIMEOUT_SECONDS, 
TimeUnit.SECONDS);
-            assertThat(firstExecutor, not(sameInstance(secondExecutor)));
-        } finally {
-            executorService.shutdownNow();
-        }
-    }
-}
diff --git 
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/query/DistSQLQueryExecutorTest.java
 
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/query/DistSQLQueryExecutorTest.java
new file mode 100644
index 00000000000..e7738edacd7
--- /dev/null
+++ 
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/query/DistSQLQueryExecutorTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.distsql.handler.executor.spi.query;
+
+import 
org.apache.shardingsphere.distsql.handler.executor.aware.DistSQLExecutorRuleAware;
+import 
org.apache.shardingsphere.distsql.handler.executor.spi.fixture.FixtureRule;
+import 
org.apache.shardingsphere.distsql.handler.executor.spi.query.fixture.FixtureDistSQLQueryStatement;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.sameInstance;
+
+class DistSQLQueryExecutorTest {
+    
+    private static final int THREAD_COUNT = 2;
+    
+    private static final int TIMEOUT_SECONDS = 10;
+    
+    @Test
+    void assertConcurrentIsolation() throws Exception {
+        CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);
+        ExecutorService executorService = 
Executors.newFixedThreadPool(THREAD_COUNT);
+        try {
+            Future<DistSQLQueryExecutor<FixtureDistSQLQueryStatement>> 
firstFuture = executorService.submit(createTask(barrier, new 
FixtureRule("first")));
+            Future<DistSQLQueryExecutor<FixtureDistSQLQueryStatement>> 
secondFuture = executorService.submit(createTask(barrier, new 
FixtureRule("second")));
+            DistSQLQueryExecutor<FixtureDistSQLQueryStatement> actualFirst = 
firstFuture.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+            DistSQLQueryExecutor<FixtureDistSQLQueryStatement> actualSecond = 
secondFuture.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+            assertThat(actualFirst, not(sameInstance(actualSecond)));
+        } finally {
+            executorService.shutdownNow();
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    private Callable<DistSQLQueryExecutor<FixtureDistSQLQueryStatement>> 
createTask(final CyclicBarrier barrier, final FixtureRule expectedRule) {
+        return () -> {
+            DistSQLQueryExecutor<FixtureDistSQLQueryStatement> result = 
TypedSPILoader.getService(DistSQLQueryExecutor.class, 
FixtureDistSQLQueryStatement.class);
+            ((DistSQLExecutorRuleAware<ShardingSphereRule>) 
result).setRule(expectedRule);
+            barrier.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+            result.getColumnNames(new 
FixtureDistSQLQueryStatement(expectedRule));
+            return result;
+        };
+    }
+}
diff --git 
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/update/DistSQLUpdateExecutorTest.java
 
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/update/DistSQLUpdateExecutorTest.java
new file mode 100644
index 00000000000..04c6ff0ec26
--- /dev/null
+++ 
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/update/DistSQLUpdateExecutorTest.java
@@ -0,0 +1,69 @@
+/*
+ * 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.distsql.handler.executor.spi.update;
+
+import 
org.apache.shardingsphere.distsql.handler.executor.aware.DistSQLExecutorRuleAware;
+import 
org.apache.shardingsphere.distsql.handler.executor.spi.fixture.FixtureRule;
+import 
org.apache.shardingsphere.distsql.handler.executor.spi.update.fixture.FixtureDistSQLUpdateStatement;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.sameInstance;
+
+class DistSQLUpdateExecutorTest {
+    
+    private static final int THREAD_COUNT = 2;
+    
+    private static final int TIMEOUT_SECONDS = 10;
+    
+    @Test
+    void assertConcurrentIsolation() throws Exception {
+        CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);
+        ExecutorService executorService = 
Executors.newFixedThreadPool(THREAD_COUNT);
+        try {
+            Future<DistSQLUpdateExecutor<FixtureDistSQLUpdateStatement>> 
firstFuture = executorService.submit(createTask(barrier, new 
FixtureRule("first")));
+            Future<DistSQLUpdateExecutor<FixtureDistSQLUpdateStatement>> 
secondFuture = executorService.submit(createTask(barrier, new 
FixtureRule("second")));
+            DistSQLUpdateExecutor<FixtureDistSQLUpdateStatement> actualFirst = 
firstFuture.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+            DistSQLUpdateExecutor<FixtureDistSQLUpdateStatement> actualSecond 
= secondFuture.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+            assertThat(actualFirst, not(sameInstance(actualSecond)));
+        } finally {
+            executorService.shutdownNow();
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    private Callable<DistSQLUpdateExecutor<FixtureDistSQLUpdateStatement>> 
createTask(final CyclicBarrier barrier, final FixtureRule expectedRule) {
+        return () -> {
+            DistSQLUpdateExecutor<FixtureDistSQLUpdateStatement> result = 
TypedSPILoader.getService(DistSQLUpdateExecutor.class, 
FixtureDistSQLUpdateStatement.class);
+            ((DistSQLExecutorRuleAware<ShardingSphereRule>) 
result).setRule(expectedRule);
+            barrier.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+            result.executeUpdate(new 
FixtureDistSQLUpdateStatement(expectedRule), null);
+            return result;
+        };
+    }
+}
diff --git 
a/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/update/rule/database/DatabaseRuleDefinitionExecutorTest.java
 
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/update/rule/database/DatabaseRuleDefinitionExecutorTest.java
new file mode 100644
index 00000000000..66c3fa90a68
--- /dev/null
+++ 
b/infra/distsql-handler/src/test/java/org/apache/shardingsphere/distsql/handler/executor/spi/update/rule/database/DatabaseRuleDefinitionExecutorTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.distsql.handler.executor.spi.update.rule.database;
+
+import 
org.apache.shardingsphere.distsql.handler.executor.spi.fixture.FixtureRule;
+import 
org.apache.shardingsphere.distsql.handler.executor.spi.update.rule.database.fixture.FixtureDatabaseRuleDefinitionStatement;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.sameInstance;
+
+class DatabaseRuleDefinitionExecutorTest {
+    
+    private static final int THREAD_COUNT = 2;
+    
+    private static final int TIMEOUT_SECONDS = 10;
+    
+    @Test
+    void assertConcurrentIsolation() throws Exception {
+        CyclicBarrier barrier = new CyclicBarrier(THREAD_COUNT);
+        ExecutorService executorService = 
Executors.newFixedThreadPool(THREAD_COUNT);
+        try {
+            
Future<DatabaseRuleDefinitionExecutor<FixtureDatabaseRuleDefinitionStatement, 
ShardingSphereRule>> firstFuture = executorService.submit(createTask(barrier, 
new FixtureRule("first")));
+            
Future<DatabaseRuleDefinitionExecutor<FixtureDatabaseRuleDefinitionStatement, 
ShardingSphereRule>> secondFuture = executorService.submit(createTask(barrier, 
new FixtureRule("second")));
+            
DatabaseRuleDefinitionExecutor<FixtureDatabaseRuleDefinitionStatement, 
ShardingSphereRule> actualFirst = firstFuture.get(TIMEOUT_SECONDS, 
TimeUnit.SECONDS);
+            
DatabaseRuleDefinitionExecutor<FixtureDatabaseRuleDefinitionStatement, 
ShardingSphereRule> actualSecond = secondFuture.get(TIMEOUT_SECONDS, 
TimeUnit.SECONDS);
+            assertThat(actualFirst, not(sameInstance(actualSecond)));
+        } finally {
+            executorService.shutdownNow();
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    private 
Callable<DatabaseRuleDefinitionExecutor<FixtureDatabaseRuleDefinitionStatement, 
ShardingSphereRule>> createTask(final CyclicBarrier barrier, final FixtureRule 
expectedRule) {
+        return () -> {
+            
DatabaseRuleDefinitionExecutor<FixtureDatabaseRuleDefinitionStatement, 
ShardingSphereRule> result =
+                    
TypedSPILoader.getService(DatabaseRuleDefinitionExecutor.class, 
FixtureDatabaseRuleDefinitionStatement.class);
+            result.setDatabase(null);
+            result.setRule(expectedRule);
+            barrier.await(TIMEOUT_SECONDS, TimeUnit.SECONDS);
+            result.checkBeforeUpdate(new 
FixtureDatabaseRuleDefinitionStatement(expectedRule));
+            return result;
+        };
+    }
+}

Reply via email to