You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/06/23 13:23:57 UTC
[shardingsphere] branch master updated: Revise #10898 and complete
test cases (#10950)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 a67e470 Revise #10898 and complete test cases (#10950)
a67e470 is described below
commit a67e4702d1d09690049c02c85f1dcd090f79ef4a
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Wed Jun 23 21:23:03 2021 +0800
Revise #10898 and complete test cases (#10950)
---
.../jdbc/connection/BackendConnection.java | 1 +
.../jdbc/connection/BackendConnectionTest.java | 31 ++++++++++++++++++++++
2 files changed, 32 insertions(+)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java
index 0beea56..463d288 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnection.java
@@ -233,6 +233,7 @@ public final class BackendConnection implements ExecutorJDBCManager {
result.add(ex);
}
}
+ cachedDatabaseCommunicationEngines.clear();
return result;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
index b9e3ea8..d25d0c9 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine;
import org.apache.shardingsphere.infra.executor.sql.execute.engine.ConnectionMode;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.datasource.JDBCBackendDataSource;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.transaction.BackendTransactionManager;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
@@ -362,4 +363,34 @@ public final class BackendConnectionTest {
Collection<ConnectionPostProcessor> connectionPostProcessors = (Collection<ConnectionPostProcessor>) field.get(backendConnection);
assertTrue(connectionPostProcessors.isEmpty());
}
+
+ @Test
+ public void assertAddDatabaseCommunicationEngine() {
+ DatabaseCommunicationEngine expectedEngine = mock(DatabaseCommunicationEngine.class);
+ backendConnection.add(expectedEngine);
+ Collection<DatabaseCommunicationEngine> actual = getCachedDatabaseCommunicationEngines();
+ assertThat(actual.size(), is(1));
+ assertThat(actual.iterator().next(), is(expectedEngine));
+ }
+
+ @Test
+ public void assertCloseDatabaseCommunicationEngines() throws SQLException {
+ DatabaseCommunicationEngine engine = mock(DatabaseCommunicationEngine.class);
+ SQLException expectedException = mock(SQLException.class);
+ doThrow(expectedException).when(engine).close();
+ Collection<DatabaseCommunicationEngine> cachedDatabaseCommunicationEngines = getCachedDatabaseCommunicationEngines();
+ cachedDatabaseCommunicationEngines.add(engine);
+ Collection<SQLException> actual = backendConnection.closeDatabaseCommunicationEngines();
+ verify(engine).close();
+ assertThat(actual.size(), is(1));
+ assertThat(actual.iterator().next(), is(expectedException));
+ assertTrue(cachedDatabaseCommunicationEngines.isEmpty());
+ }
+
+ @SneakyThrows
+ private Collection<DatabaseCommunicationEngine> getCachedDatabaseCommunicationEngines() {
+ Field field = BackendConnection.class.getDeclaredField("cachedDatabaseCommunicationEngines");
+ field.setAccessible(true);
+ return (Collection<DatabaseCommunicationEngine>) field.get(backendConnection);
+ }
}