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

liguoping 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 3b3df1fc09a Refactor DistSQL RAL assertion logic of integration test 
(#20873)
3b3df1fc09a is described below

commit 3b3df1fc09a9f303b692a10d3b3dbc689c29bce8
Author: zhaojinchao <[email protected]>
AuthorDate: Thu Sep 8 15:19:01 2022 +0800

    Refactor DistSQL RAL assertion logic of integration test (#20873)
    
    * Refactor DistSQL RAL assertion logic
    
    * Fix checkstyle
    
    * Modify
---
 .../cases/dataset/metadata/DataSetColumn.java      |  3 +++
 .../test/integration/engine/ral/BaseRALIT.java     | 21 ++++++++++++----
 .../ral/dataset/empty_rules/show_instance_list.xml | 29 ++++++++++++++++++++++
 .../cases/ral/ral-integration-test-cases.xml       |  4 +++
 4 files changed, 52 insertions(+), 5 deletions(-)

diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/metadata/DataSetColumn.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/metadata/DataSetColumn.java
index be15ef08286..cf3480bea2f 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/metadata/DataSetColumn.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/cases/dataset/metadata/DataSetColumn.java
@@ -34,6 +34,9 @@ public final class DataSetColumn {
     @XmlAttribute(required = true)
     private String name;
     
+    @XmlAttribute
+    private String assertion;
+    
     @XmlAttribute
     private String type;
 }
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/BaseRALIT.java
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/BaseRALIT.java
index e1eefc0790a..4321aa6e97d 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/BaseRALIT.java
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/java/org/apache/shardingsphere/test/integration/engine/ral/BaseRALIT.java
@@ -34,6 +34,7 @@ import java.sql.SQLException;
 import java.util.Collection;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
@@ -87,7 +88,7 @@ public abstract class BaseRALIT extends SingleITCase {
     
     protected final void assertResultSet(final ResultSet resultSet) throws 
SQLException {
         assertMetaData(resultSet.getMetaData(), getExpectedColumns());
-        assertRows(resultSet, getDataSet().getRows());
+        assertRows(resultSet, getNotAssertionColumns(), 
getDataSet().getRows());
     }
     
     private Collection<DataSetColumn> getExpectedColumns() {
@@ -98,6 +99,14 @@ public abstract class BaseRALIT extends SingleITCase {
         return result;
     }
     
+    private Collection<String> getNotAssertionColumns() {
+        Collection<String> result = new LinkedList<>();
+        for (DataSetMetaData each : getDataSet().getMetaDataList()) {
+            result.addAll(each.getColumns().stream().filter(column -> 
"false".equals(column.getAssertion())).map(DataSetColumn::getName).collect(Collectors.toList()));
+        }
+        return result;
+    }
+    
     private void assertMetaData(final ResultSetMetaData actual, final 
Collection<DataSetColumn> expected) throws SQLException {
         assertThat(actual.getColumnCount(), is(expected.size()));
         int index = 1;
@@ -106,22 +115,24 @@ public abstract class BaseRALIT extends SingleITCase {
         }
     }
     
-    private void assertRows(final ResultSet actual, final List<DataSetRow> 
expected) throws SQLException {
+    private void assertRows(final ResultSet actual, final Collection<String> 
notAssertionColumns, final List<DataSetRow> expected) throws SQLException {
         int rowCount = 0;
         ResultSetMetaData actualMetaData = actual.getMetaData();
         while (actual.next()) {
             assertTrue("Size of actual result set is different with size of 
expected dat set rows.", rowCount < expected.size());
-            assertRow(actual, actualMetaData, expected.get(rowCount));
+            assertRow(actual, notAssertionColumns, actualMetaData, 
expected.get(rowCount));
             rowCount++;
         }
         assertThat("Size of actual result set is different with size of 
expected dat set rows.", rowCount, is(expected.size()));
     }
     
-    private void assertRow(final ResultSet actual, final ResultSetMetaData 
actualMetaData, final DataSetRow expected) throws SQLException {
+    private void assertRow(final ResultSet actual, final Collection<String> 
notAssertionColumns, final ResultSetMetaData actualMetaData, final DataSetRow 
expected) throws SQLException {
         int columnIndex = 1;
         for (String each : expected.splitValues("|")) {
             String columnLabel = actualMetaData.getColumnLabel(columnIndex);
-            assertObjectValue(actual, columnIndex, columnLabel, each);
+            if (!notAssertionColumns.contains(columnLabel)) {
+                assertObjectValue(actual, columnIndex, columnLabel, each);
+            }
             columnIndex++;
         }
     }
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/ral/dataset/empty_rules/show_instance_list.xml
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/ral/dataset/empty_rules/show_instance_list.xml
new file mode 100644
index 00000000000..a7e34dcf9c0
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/ral/dataset/empty_rules/show_instance_list.xml
@@ -0,0 +1,29 @@
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one or more
+  ~ contributor license agreements.  See the NOTICE file distributed with
+  ~ this work for additional information regarding copyright ownership.
+  ~ The ASF licenses this file to You under the Apache License, Version 2.0
+  ~ (the "License"); you may not use this file except in compliance with
+  ~ the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<dataset>
+    <metadata>
+        <column name="instance_id" assertion="false"/>
+        <column name="host" assertion="false" />
+        <column name="port" />
+        <column name="status" />
+        <column name="mode_type" assertion="false"/>
+        <column name="worker_id" />
+        <column name="labels" />
+    </metadata>
+    <row values=" | | 3307 | OK | | 0 | " />
+</dataset>
diff --git 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/ral/ral-integration-test-cases.xml
 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/ral/ral-integration-test-cases.xml
index b6983bbf193..6a19987c9a8 100644
--- 
a/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/ral/ral-integration-test-cases.xml
+++ 
b/shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-suite/src/test/resources/cases/ral/ral-integration-test-cases.xml
@@ -73,5 +73,9 @@
             sql="PREVIEW SELECT * FROM t_single_table s INNER JOIN t_user_item 
i ON s.single_id = i.item_id WHERE i.user_id = 1">
         <assertion expected-data-file="preview_federation_select.xml"/>
     </test-case>
+    
+    <test-case sql="SHOW INSTANCE LIST">
+        <assertion expected-data-file="show_instance_list.xml"/>
+    </test-case>
 </integration-test-cases>
 

Reply via email to