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 2023/05/29 11:09:13 UTC

[shardingsphere] branch master updated: Fix logic error in MySQLDataSourceChecker (#25936)

This is an automated email from the ASF dual-hosted git repository.

zhonghongsheng 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 74d912e5fa7 Fix logic error in MySQLDataSourceChecker (#25936)
74d912e5fa7 is described below

commit 74d912e5fa7055436b2a523cbee24ccb88c41dd7
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Mon May 29 19:09:01 2023 +0800

    Fix logic error in MySQLDataSourceChecker (#25936)
---
 .../mysql/check/datasource/MySQLDataSourceChecker.java      | 13 +++++++------
 .../mysql/check/datasource/MySQLDataSourceCheckerTest.java  | 11 ++++++-----
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
index a1c7d855a03..0150fdca5a2 100644
--- a/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
+++ b/kernel/data-pipeline/dialect/mysql/src/main/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceChecker.java
@@ -100,12 +100,13 @@ public final class MySQLDataSourceChecker extends AbstractDataSourceChecker {
                 preparedStatement.setString(parameterIndex++, entry.getKey());
             }
             try (ResultSet resultSet = preparedStatement.executeQuery()) {
-                resultSet.next();
-                String key = resultSet.getString(1).toUpperCase();
-                String toBeCheckedValue = REQUIRED_VARIABLES.get(key);
-                String actualValue = resultSet.getString(2);
-                ShardingSpherePreconditions.checkState(toBeCheckedValue.equalsIgnoreCase(actualValue),
-                        () -> new PrepareJobWithInvalidSourceDataSourceException(key, toBeCheckedValue, actualValue));
+                while (resultSet.next()) {
+                    String key = resultSet.getString(1).toUpperCase();
+                    String expectedValue = REQUIRED_VARIABLES.get(key);
+                    String actualValue = resultSet.getString(2);
+                    ShardingSpherePreconditions.checkState(expectedValue.equalsIgnoreCase(actualValue),
+                            () -> new PrepareJobWithInvalidSourceDataSourceException(key, expectedValue, actualValue));
+                }
             }
         } catch (final SQLException ex) {
             throw new PrepareJobWithCheckPrivilegeFailedException(ex);
diff --git a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceCheckerTest.java b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceCheckerTest.java
index b930782988d..0c85a27ceb4 100644
--- a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceCheckerTest.java
+++ b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/check/datasource/MySQLDataSourceCheckerTest.java
@@ -33,6 +33,7 @@ import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
 
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
@@ -89,18 +90,18 @@ class MySQLDataSourceCheckerTest {
     
     @Test
     void assertCheckVariableSuccess() throws SQLException {
-        when(resultSet.next()).thenReturn(true, true);
+        when(resultSet.next()).thenReturn(true, true, true, false);
         when(resultSet.getString(1)).thenReturn("LOG_BIN", "BINLOG_FORMAT", "BINLOG_ROW_IMAGE");
         when(resultSet.getString(2)).thenReturn("ON", "ROW", "FULL");
-        new MySQLDataSourceChecker().checkVariable(dataSources);
+        assertDoesNotThrow(() -> new MySQLDataSourceChecker().checkVariable(dataSources));
         verify(preparedStatement, times(1)).executeQuery();
     }
     
     @Test
     void assertCheckVariableWithWrongVariable() throws SQLException {
-        when(resultSet.next()).thenReturn(true, true);
-        when(resultSet.getString(1)).thenReturn("LOG_BIN", "BINLOG_FORMAT");
-        when(resultSet.getString(2)).thenReturn("OFF", "ROW");
+        when(resultSet.next()).thenReturn(true, true, false);
+        when(resultSet.getString(1)).thenReturn("BINLOG_FORMAT", "LOG_BIN");
+        when(resultSet.getString(2)).thenReturn("ROW", "OFF");
         assertThrows(PrepareJobWithInvalidSourceDataSourceException.class, () -> new MySQLDataSourceChecker().checkVariable(dataSources));
     }