This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 d4441c63960 Move DataSourcePoolActiveDetector (#28038)
d4441c63960 is described below
commit d4441c63960be0273ebbda62a30a9a18f62070df
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 11 13:20:20 2023 +0800
Move DataSourcePoolActiveDetector (#28038)
---
.../destroyer/{detector => }/DataSourcePoolActiveDetector.java | 6 ++++--
.../datasource/pool/destroyer/DataSourcePoolDestroyer.java | 4 ++--
.../destroyer/fixture/DataSourcePoolActiveDetectorFixture.java | 10 +++++-----
...fra.datasource.pool.destroyer.DataSourcePoolActiveDetector} | 0
.../hikari/detector/HikariDataSourcePoolActiveDetector.java | 2 +-
...fra.datasource.pool.destroyer.DataSourcePoolActiveDetector} | 0
6 files changed, 12 insertions(+), 10 deletions(-)
diff --git
a/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetector.java
b/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolActiveDetector.java
similarity index 89%
rename from
infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetector.java
rename to
infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolActiveDetector.java
index 3734e79216e..5a483263629 100644
---
a/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/detector/DataSourcePoolActiveDetector.java
+++
b/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolActiveDetector.java
@@ -15,12 +15,13 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.infra.datasource.pool.destroyer.detector;
+package org.apache.shardingsphere.infra.datasource.pool.destroyer;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
import javax.sql.DataSource;
+import java.sql.SQLException;
/**
* Data source pool active detector.
@@ -33,6 +34,7 @@ public interface DataSourcePoolActiveDetector extends
TypedSPI {
*
* @param dataSource data source pool to be detected
* @return contains active connection or not
+ * @throws SQLException SQL exception
*/
- boolean containsActiveConnection(DataSource dataSource);
+ boolean containsActiveConnection(DataSource dataSource) throws
SQLException;
}
diff --git
a/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyer.java
b/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyer.java
index d8a95b8058a..49dc73995b1 100644
---
a/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyer.java
+++
b/infra/datasource/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/DataSourcePoolDestroyer.java
@@ -19,10 +19,10 @@ package
org.apache.shardingsphere.infra.datasource.pool.destroyer;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
-import
org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetector;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import javax.sql.DataSource;
+import java.sql.SQLException;
import java.util.Optional;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -53,7 +53,7 @@ public final class DataSourcePoolDestroyer {
((AutoCloseable) dataSource).close();
}
- private void waitUntilActiveConnectionComplete() {
+ private void waitUntilActiveConnectionComplete() throws SQLException {
Optional<DataSourcePoolActiveDetector> activeDetector =
TypedSPILoader.findService(DataSourcePoolActiveDetector.class,
dataSource.getClass().getName());
while (activeDetector.isPresent() &&
activeDetector.get().containsActiveConnection(dataSource)) {
try {
diff --git
a/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/fixture/DataSourcePoolActiveDetectorFixture.java
b/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/fixture/DataSourcePoolActiveDetectorFixture.java
index 8b7fe843c0d..9cab103dd0b 100644
---
a/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/fixture/DataSourcePoolActiveDetectorFixture.java
+++
b/infra/datasource/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/destroyer/fixture/DataSourcePoolActiveDetectorFixture.java
@@ -17,8 +17,7 @@
package org.apache.shardingsphere.infra.datasource.pool.destroyer.fixture;
-import lombok.SneakyThrows;
-import
org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetector;
+import
org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolActiveDetector;
import org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
import javax.sql.DataSource;
@@ -26,10 +25,11 @@ import java.sql.SQLException;
public final class DataSourcePoolActiveDetectorFixture implements
DataSourcePoolActiveDetector {
- @SneakyThrows(SQLException.class)
@Override
- public boolean containsActiveConnection(final DataSource dataSource) {
- return
!dataSource.unwrap(MockedDataSource.class).getOpenedConnections().isEmpty();
+ public boolean containsActiveConnection(final DataSource dataSource)
throws SQLException {
+ try (MockedDataSource wrappedDataSource =
dataSource.unwrap(MockedDataSource.class)) {
+ return !wrappedDataSource.getOpenedConnections().isEmpty();
+ }
}
@Override
diff --git
a/infra/datasource/core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetector
b/infra/datasource/core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolActiveDetector
similarity index 100%
rename from
infra/datasource/core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetector
rename to
infra/datasource/core/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolActiveDetector
diff --git
a/infra/datasource/type/hikari/src/main/java/org/apache/shardingsphere/infra/datasource/hikari/detector/HikariDataSourcePoolActiveDetector.java
b/infra/datasource/type/hikari/src/main/java/org/apache/shardingsphere/infra/datasource/hikari/detector/HikariDataSourcePoolActiveDetector.java
index 59834d61271..e0ea4b5464e 100644
---
a/infra/datasource/type/hikari/src/main/java/org/apache/shardingsphere/infra/datasource/hikari/detector/HikariDataSourcePoolActiveDetector.java
+++
b/infra/datasource/type/hikari/src/main/java/org/apache/shardingsphere/infra/datasource/hikari/detector/HikariDataSourcePoolActiveDetector.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.infra.datasource.hikari.detector;
import lombok.SneakyThrows;
-import
org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetector;
+import
org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolActiveDetector;
import javax.sql.DataSource;
diff --git
a/infra/datasource/type/hikari/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetector
b/infra/datasource/type/hikari/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolActiveDetector
similarity index 100%
rename from
infra/datasource/type/hikari/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.destroyer.detector.DataSourcePoolActiveDetector
rename to
infra/datasource/type/hikari/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.datasource.pool.destroyer.DataSourcePoolActiveDetector