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 2022/10/25 16:03:50 UTC
[shardingsphere] branch master updated: Fix JDBCRepositoryTest error log printing (#21747)
This is an automated email from the ASF dual-hosted git repository.
zhaojinchao 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 65508b30291 Fix JDBCRepositoryTest error log printing (#21747)
65508b30291 is described below
commit 65508b30291506f4baa428231789f02192f77c30
Author: 马称 <ma...@163.com>
AuthorDate: Wed Oct 26 00:03:44 2022 +0800
Fix JDBCRepositoryTest error log printing (#21747)
* Fix JDBCRepositoryTest error log printing
* Fix CI
---
.../standalone/jdbc/JDBCRepositoryTest.java | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/mode/type/standalone/repository/provider/jdbc/core/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java b/mode/type/standalone/repository/provider/jdbc/core/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java
index b525b8ae740..ac557cbb9e7 100644
--- a/mode/type/standalone/repository/provider/jdbc/core/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java
+++ b/mode/type/standalone/repository/provider/jdbc/core/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/JDBCRepositoryTest.java
@@ -31,7 +31,6 @@ import org.mockito.Mock;
import org.mockito.MockedConstruction;
import org.mockito.junit.MockitoJUnitRunner;
-import java.sql.SQLException;
import java.util.List;
import java.util.Properties;
@@ -102,7 +101,9 @@ public final class JDBCRepositoryTest {
@Test
public void assertGetFailure() throws Exception {
- when(mockJdbcConnection.prepareStatement(eq(fixture.selectByKeySQL()))).thenThrow(new SQLException());
+ when(mockJdbcConnection.prepareStatement(eq(fixture.selectByKeySQL()))).thenReturn(mockPreparedStatement);
+ when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
+ when(mockResultSet.next()).thenReturn(false);
String actual = repository.getDirectly("key");
assertThat(actual, is(""));
}
@@ -127,7 +128,9 @@ public final class JDBCRepositoryTest {
@Test
public void assertPersistAndGetChildrenKeysFailure() throws Exception {
- when(mockJdbcConnection.prepareStatement(eq(fixture.selectByParentKeySQL()))).thenThrow(new SQLException());
+ when(mockJdbcConnection.prepareStatement(eq(fixture.selectByParentKeySQL()))).thenReturn(mockPreparedStatement);
+ when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
+ when(mockResultSet.next()).thenReturn(false);
List<String> actual = repository.getChildrenKeys("key");
assertThat(actual.size(), is(0));
}
@@ -194,7 +197,7 @@ public final class JDBCRepositoryTest {
when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
when(mockResultSet.next()).thenReturn(true);
when(mockResultSet.getString(eq("value"))).thenReturn("oldValue");
- when(mockJdbcConnection.prepareStatement(eq(fixture.updateSQL()))).thenThrow(new SQLException());
+ when(mockJdbcConnection.prepareStatement(eq(fixture.updateSQL()))).thenReturn(mockPreparedStatement);
repository.persist(key, "value");
verify(mockPreparedStatementForPersist, times(0)).executeUpdate();
}
@@ -218,10 +221,11 @@ public final class JDBCRepositoryTest {
@Test
public void assertPersistFailureDuringInsert() throws Exception {
- String key = "key";
- when(mockJdbcConnection.prepareStatement(eq(fixture.selectByKeySQL()))).thenThrow(new SQLException());
- when(mockJdbcConnection.prepareStatement(eq(fixture.insertSQL()))).thenThrow(new SQLException());
- repository.persist(key, "value");
+ when(mockJdbcConnection.prepareStatement(eq(fixture.selectByKeySQL()))).thenReturn(mockPreparedStatement);
+ when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
+ when(mockResultSet.next()).thenReturn(false);
+ when(mockJdbcConnection.prepareStatement(eq(fixture.insertSQL()))).thenReturn(mockPreparedStatement);
+ repository.persist("key", "value");
verify(mockPreparedStatementForPersist, times(0)).executeUpdate();
}
@@ -237,7 +241,7 @@ public final class JDBCRepositoryTest {
@Test
public void assertDeleteFailure() throws Exception {
String key = "key";
- when(mockJdbcConnection.prepareStatement(eq(fixture.deleteSQL()))).thenThrow(new SQLException());
+ when(mockJdbcConnection.prepareStatement(eq(fixture.deleteSQL()))).thenReturn(mockPreparedStatementForPersist);
repository.delete(key);
verify(mockPreparedStatement, times(0)).executeUpdate();
}