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 2022/12/31 11:37:32 UTC

[shardingsphere] branch master updated: Revise #23176 (#23224)

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 807acd0457d Revise #23176 (#23224)
807acd0457d is described below

commit 807acd0457d2cd75497746cd4fc0d3ef52bd6263
Author: zhaojinchao <zh...@apache.org>
AuthorDate: Sat Dec 31 19:37:25 2022 +0800

    Revise #23176 (#23224)
---
 .../builtin-algorithm/metadata-repository.cn.md    |  2 +-
 .../builtin-algorithm/metadata-repository.en.md    |  2 +-
 .../jdbc/mysql/MySQLJDBCRepositoryProvider.java    |  7 +-
 .../mysql/MySQLJDBCRepositoryProviderTest.java     | 82 ++++++++--------------
 4 files changed, 33 insertions(+), 60 deletions(-)

diff --git a/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.cn.md b/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.cn.md
index 1dd453f33fa..1938a530826 100644
--- a/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.cn.md
+++ b/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.cn.md
@@ -19,7 +19,7 @@ Apache ShardingSphere 为不同的运行模式提供了不同的元数据持久
 
 | *名称*     | *数据类型* | *说明*                  | *默认值*                                                                   |
 |----------|--------|-----------------------|-------------------------------------------------------------------------|
-| provider | String | 元数据存储类型,可选值为 H2,MYSQL | H2                                                                      |
+| provider | String | 元数据存储类型,可选值为 H2,MySQL | H2                                                                      |
 | jdbc_url | String | JDBC URL              | jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL |
 | username | String | 账号                    | sa                                                                      |
 | password | String | 密码                    |                                                                         |
diff --git a/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.en.md b/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.en.md
index f79de0c9115..dae6bfb5dce 100644
--- a/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.en.md
+++ b/docs/document/content/user-manual/common-config/builtin-algorithm/metadata-repository.en.md
@@ -19,7 +19,7 @@ Attributes:
 
 | *Name*   | *Type* | *Description*                                              | *Default Value*                                                         |
 |----------|--------|------------------------------------------------------------|-------------------------------------------------------------------------|
-| provider | String | Type for metadata persist, the optional value is H2, MYSQL | H2                                                                      |
+| provider | String | Type for metadata persist, the optional value is H2, MySQL | H2                                                                      |
 | jdbc_url | String | JDBC URL                                                   | jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL |
 | username | String | username                                                   | sa                                                                      |
 | password | String | password                                                   |                                                                         |
diff --git a/mode/type/standalone/repository/provider/jdbc/mysql/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProvider.java b/mode/type/standalone/repository/provider/jdbc/mysql/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProvider.java
index 347356f4c13..22f6edf1c2f 100644
--- a/mode/type/standalone/repository/provider/jdbc/mysql/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProvider.java
+++ b/mode/type/standalone/repository/provider/jdbc/mysql/src/main/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProvider.java
@@ -61,11 +61,6 @@ public final class MySQLJDBCRepositoryProvider implements JDBCRepositoryProvider
     
     @Override
     public String getType() {
-        return "MYSQL";
-    }
-    
-    @Override
-    public boolean isDefault() {
-        return false;
+        return "MySQL";
     }
 }
diff --git a/mode/type/standalone/repository/provider/jdbc/mysql/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProviderTest.java b/mode/type/standalone/repository/provider/jdbc/mysql/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProviderTest.java
index 1d513062266..95397a6727d 100644
--- a/mode/type/standalone/repository/provider/jdbc/mysql/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProviderTest.java
+++ b/mode/type/standalone/repository/provider/jdbc/mysql/src/test/java/org/apache/shardingsphere/mode/repository/standalone/jdbc/mysql/MySQLJDBCRepositoryProviderTest.java
@@ -17,10 +17,6 @@
 
 package org.apache.shardingsphere.mode.repository.standalone.jdbc.mysql;
 
-import com.mysql.jdbc.ConnectionImpl;
-import com.mysql.jdbc.JDBC42CallableStatement;
-import com.mysql.jdbc.ResultSetImpl;
-import com.mysql.jdbc.StatementImpl;
 import com.zaxxer.hikari.HikariDataSource;
 import org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository;
 import org.junit.After;
@@ -31,73 +27,64 @@ import org.mockito.Mock;
 import org.mockito.MockedConstruction;
 import org.mockito.junit.MockitoJUnitRunner;
 
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
 import java.sql.SQLException;
+import java.sql.PreparedStatement;
 import java.util.List;
 import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mockConstruction;
 import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mock;
 
 @RunWith(MockitoJUnitRunner.class)
 public class MySQLJDBCRepositoryProviderTest {
     
     @Mock
-    private ConnectionImpl mockJdbcConnection;
+    private Connection connection;
     
     @Mock
-    private StatementImpl mockStatement;
+    private PreparedStatement preparedStatement;
     
     @Mock
-    private JDBC42CallableStatement mockPreparedStatement;
+    private ResultSet resultSet;
     
-    @Mock
-    private JDBC42CallableStatement mockPreparedStatementForPersist;
-    
-    @Mock
-    private ResultSetImpl mockResultSet;
+    private MockedConstruction<HikariDataSource> construction;
     
     private final MySQLJDBCRepositoryProvider provider = new MySQLJDBCRepositoryProvider();
     
-    private MockedConstruction<HikariDataSource> mockedConstruction;
-    
-    private JDBCRepository repository;
+    private final JDBCRepository repository = new JDBCRepository();
     
     @Before
     public void setUp() throws SQLException {
-        this.mockedConstruction = mockConstruction(HikariDataSource.class, (mock, context) -> when(mock.getConnection()).thenReturn(mockJdbcConnection));
-        when(mockJdbcConnection.createStatement()).thenReturn(mockStatement);
+        construction = mockConstruction(HikariDataSource.class, (mock, context) -> when(mock.getConnection()).thenReturn(connection));
+        when(connection.createStatement()).thenReturn(mock(Statement.class));
         Properties props = new Properties();
         props.setProperty("jdbc_url", "jdbc:mysql://localhost:3306/config");
         props.setProperty("username", "sa");
         props.setProperty("password", "");
-        props.setProperty("provider", "MYSQL");
-        repository = new JDBCRepository();
+        props.setProperty("provider", "MySQL");
         repository.init(props);
     }
     
     @After
     public void stop() {
         repository.close();
-        this.mockedConstruction.close();
+        construction.close();
     }
     
     @Test
     public void assertPersistAndGet() throws SQLException {
-        when(mockJdbcConnection.prepareStatement(eq(provider.selectByKeySQL()))).thenReturn(mockPreparedStatement);
-        when(mockJdbcConnection.prepareStatement(eq(provider.insertSQL()))).thenReturn(mockPreparedStatementForPersist);
-        when(mockJdbcConnection.prepareStatement(eq(provider.updateSQL()))).thenReturn(mockPreparedStatementForPersist);
-        when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
-        when(mockResultSet.next())
-                .thenReturn(false)
-                .thenReturn(true)
-                .thenReturn(true);
-        when(mockResultSet.getString(eq("value")))
-                .thenReturn("test1_content")
-                .thenReturn("test1_content")
-                .thenReturn("modify_content");
+        when(connection.prepareStatement(provider.selectByKeySQL())).thenReturn(preparedStatement);
+        when(connection.prepareStatement(provider.insertSQL())).thenReturn(preparedStatement);
+        when(connection.prepareStatement(provider.updateSQL())).thenReturn(preparedStatement);
+        when(preparedStatement.executeQuery()).thenReturn(resultSet);
+        when(resultSet.next()).thenReturn(false, true, true);
+        when(resultSet.getString("value")).thenReturn("test1_content", "test1_content", "modify_content");
         repository.persist("/testPath/test1", "test1_content");
         assertThat(repository.getDirectly("/testPath/test1"), is("test1_content"));
         repository.persist("/testPath/test1", "modify_content");
@@ -106,21 +93,12 @@ public class MySQLJDBCRepositoryProviderTest {
     
     @Test
     public void assertPersistAndGetChildrenKeys() throws SQLException {
-        when(mockJdbcConnection.prepareStatement(eq(provider.selectByKeySQL()))).thenReturn(mockPreparedStatement);
-        when(mockJdbcConnection.prepareStatement(eq(provider.insertSQL()))).thenReturn(mockPreparedStatementForPersist);
-        when(mockJdbcConnection.prepareStatement(eq(provider.selectByParentKeySQL()))).thenReturn(mockPreparedStatement);
-        when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
-        when(mockResultSet.next())
-                .thenReturn(false)
-                .thenReturn(false)
-                .thenReturn(false)
-                .thenReturn(false)
-                .thenReturn(true)
-                .thenReturn(true)
-                .thenReturn(false);
-        when(mockResultSet.getString(eq("key")))
-                .thenReturn("test1")
-                .thenReturn("test2");
+        when(connection.prepareStatement(provider.selectByKeySQL())).thenReturn(preparedStatement);
+        when(connection.prepareStatement(provider.insertSQL())).thenReturn(preparedStatement);
+        when(connection.prepareStatement(provider.selectByParentKeySQL())).thenReturn(preparedStatement);
+        when(preparedStatement.executeQuery()).thenReturn(resultSet);
+        when(resultSet.next()).thenReturn(false, false, false, false, true, true, false);
+        when(resultSet.getString("key")).thenReturn("test1", "test2");
         repository.persist("/testPath/test1", "test1_content");
         repository.persist("/testPath/test2", "test2_content");
         List<String> childrenKeys = repository.getChildrenKeys("/testPath");
@@ -130,10 +108,10 @@ public class MySQLJDBCRepositoryProviderTest {
     
     @Test
     public void assertDelete() throws SQLException {
-        when(mockJdbcConnection.prepareStatement(eq(provider.selectByKeySQL()))).thenReturn(mockPreparedStatement);
-        when(mockJdbcConnection.prepareStatement(eq(provider.deleteSQL()))).thenReturn(mockPreparedStatementForPersist);
-        when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
-        when(mockResultSet.next()).thenReturn(false);
+        when(connection.prepareStatement(provider.selectByKeySQL())).thenReturn(preparedStatement);
+        when(connection.prepareStatement(provider.deleteSQL())).thenReturn(preparedStatement);
+        when(preparedStatement.executeQuery()).thenReturn(resultSet);
+        when(resultSet.next()).thenReturn(false);
         repository.delete("/testPath");
         assertThat(repository.getDirectly("/testPath"), is(""));
     }