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 2024/10/15 10:36:04 UTC
(shardingsphere) branch master updated: Add more test cases on DataSourcesCloser (#33257)
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 efe19fde627 Add more test cases on DataSourcesCloser (#33257)
efe19fde627 is described below
commit efe19fde627a144e34cb8ada78a2e75a092badb7
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Tue Oct 15 18:35:57 2024 +0800
Add more test cases on DataSourcesCloser (#33257)
---
.../infra/util/close/DataSourcesCloserTest.java | 24 ++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)
diff --git a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/close/DataSourcesCloserTest.java b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/close/DataSourcesCloserTest.java
index 0c93ad5aa49..92fdc178be2 100644
--- a/infra/util/src/test/java/org/apache/shardingsphere/infra/util/close/DataSourcesCloserTest.java
+++ b/infra/util/src/test/java/org/apache/shardingsphere/infra/util/close/DataSourcesCloserTest.java
@@ -27,21 +27,33 @@ import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.withSettings;
class DataSourcesCloserTest {
@Test
- void assertClose() throws Exception {
+ void assertCloseSuccess() throws Exception {
+ DataSource dataSource0 = mock(DataSource.class, withSettings().extraInterfaces(AutoCloseable.class));
+ DataSource dataSource1 = mock(DataSource.class, withSettings().extraInterfaces(AutoCloseable.class));
+ DataSource dataSource2 = mock(DataSource.class, withSettings().extraInterfaces(AutoCloseable.class));
+ DataSource dataSource3 = mock(DataSource.class);
+ DataSourcesCloser.close(Arrays.asList(dataSource0, dataSource1, dataSource2, dataSource3));
+ verify((AutoCloseable) dataSource0).close();
+ verify((AutoCloseable) dataSource1).close();
+ verify((AutoCloseable) dataSource2).close();
+ }
+
+ @Test
+ void assertCloseFailed() throws Exception {
DataSource dataSource0 = mock(DataSource.class, withSettings().extraInterfaces(AutoCloseable.class));
DataSource dataSource1 = mock(DataSource.class, withSettings().extraInterfaces(AutoCloseable.class));
doThrow(new SQLException("test")).when((AutoCloseable) dataSource1).close();
DataSource dataSource2 = mock(DataSource.class, withSettings().extraInterfaces(AutoCloseable.class));
- assertThrows(SQLWrapperException.class, () -> DataSourcesCloser.close(Arrays.asList(dataSource0, dataSource1, dataSource2)));
- verify((AutoCloseable) dataSource0, times(1)).close();
- verify((AutoCloseable) dataSource1, times(1)).close();
- verify((AutoCloseable) dataSource2, times(1)).close();
+ DataSource dataSource3 = mock(DataSource.class);
+ assertThrows(SQLWrapperException.class, () -> DataSourcesCloser.close(Arrays.asList(dataSource0, dataSource1, dataSource2, dataSource3)));
+ verify((AutoCloseable) dataSource0).close();
+ verify((AutoCloseable) dataSource1).close();
+ verify((AutoCloseable) dataSource2).close();
}
}