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 40dcfe72a2a Add more test cases on ConnectionThreadExecutorGroupTest
(#37877)
40dcfe72a2a is described below
commit 40dcfe72a2a8005b5ceaa57e20b42e4515292083
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 28 21:14:59 2026 +0800
Add more test cases on ConnectionThreadExecutorGroupTest (#37877)
---
.../ConnectionThreadExecutorGroupTest.java | 42 +++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/executor/ConnectionThreadExecutorGroupTest.java
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/executor/ConnectionThreadExecutorGroupTest.java
index 01b80182d3b..0e3d2d063b7 100644
---
a/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/executor/ConnectionThreadExecutorGroupTest.java
+++
b/proxy/frontend/core/src/test/java/org/apache/shardingsphere/proxy/frontend/executor/ConnectionThreadExecutorGroupTest.java
@@ -19,8 +19,13 @@ package org.apache.shardingsphere.proxy.frontend.executor;
import org.junit.jupiter.api.Test;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.TimeUnit;
+
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
class ConnectionThreadExecutorGroupTest {
@@ -33,10 +38,45 @@ class ConnectionThreadExecutorGroupTest {
}
@Test
- void assertUnregister() {
+ void assertUnregisterWithRegisteredConnectionId() {
int connectionId = 2;
ConnectionThreadExecutorGroup.getInstance().register(connectionId);
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(connectionId);
assertNull(ConnectionThreadExecutorGroup.getInstance().get(connectionId));
}
+
+ @Test
+ void assertUnregisterWithoutRegisteredConnectionId() {
+ int connectionId = 3;
+
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(connectionId);
+
assertNull(ConnectionThreadExecutorGroup.getInstance().get(connectionId));
+ }
+
+ @Test
+ void assertUnregisterWithInterruptedAwait() throws InterruptedException {
+ int connectionId = 4;
+ CountDownLatch taskStartedLatch = new CountDownLatch(1);
+ CountDownLatch blockTaskLatch = new CountDownLatch(1);
+ ConnectionThreadExecutorGroup.getInstance().register(connectionId);
+ ExecutorService executorService =
ConnectionThreadExecutorGroup.getInstance().get(connectionId);
+ executorService.execute(() -> {
+ taskStartedLatch.countDown();
+ try {
+ blockTaskLatch.await();
+ } catch (final InterruptedException ex) {
+ Thread.currentThread().interrupt();
+ }
+ });
+ taskStartedLatch.await();
+ Thread.currentThread().interrupt();
+ try {
+
ConnectionThreadExecutorGroup.getInstance().unregisterAndAwaitTermination(connectionId);
+ assertTrue(Thread.currentThread().isInterrupted());
+ } finally {
+ Thread.interrupted();
+ blockTaskLatch.countDown();
+ executorService.awaitTermination(1L, TimeUnit.SECONDS);
+ }
+
assertNull(ConnectionThreadExecutorGroup.getInstance().get(connectionId));
+ }
}