You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/04/25 10:32:36 UTC
[shardingsphere] branch master updated: Add global clock DistSQL parser IT test cases (#25322)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 e2e5e7eec13 Add global clock DistSQL parser IT test cases (#25322)
e2e5e7eec13 is described below
commit e2e5e7eec13d3a23e290f82e9a56a21470863d44
Author: ChenJiaHao <Pa...@163.com>
AuthorDate: Tue Apr 25 18:32:28 2023 +0800
Add global clock DistSQL parser IT test cases (#25322)
---
test/it/parser/pom.xml | 5 ++
.../ral/impl/UpdatableRALStatementAssert.java | 5 ++
.../AlterGlobalClockRuleStatementAssert.java | 66 ++++++++++++++++++++++
.../cases/parser/jaxb/RootSQLParserTestCases.java | 8 +++
.../ral/AlterGlobalClockRuleStatementTestCase.java | 46 +++++++++++++++
.../ral/ShowGlobalClockRuleStatementTestCase.java | 26 +++++++++
.../src/main/resources/case/ral/queryable.xml | 1 +
.../src/main/resources/case/ral/updatable.xml | 5 ++
.../main/resources/sql/supported/ral/queryable.xml | 1 +
.../main/resources/sql/supported/ral/updatable.xml | 1 +
10 files changed, 164 insertions(+)
diff --git a/test/it/parser/pom.xml b/test/it/parser/pom.xml
index 01317f4f31d..be6e1f0eace 100644
--- a/test/it/parser/pom.xml
+++ b/test/it/parser/pom.xml
@@ -90,6 +90,11 @@
<artifactId>shardingsphere-authority-distsql-parser</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-global-clock-distsql-parser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-traffic-distsql-parser</artifactId>
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/UpdatableRALStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/UpdatableRALStatementAssert.java
index 6e87186121f..1a8bde443f1 100644
--- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/UpdatableRALStatementAssert.java
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/UpdatableRALStatementAssert.java
@@ -28,11 +28,13 @@ import org.apache.shardingsphere.distsql.parser.statement.ral.updatable.LockClus
import org.apache.shardingsphere.distsql.parser.statement.ral.updatable.RefreshTableMetaDataStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.updatable.SetDistVariableStatement;
import org.apache.shardingsphere.distsql.parser.statement.ral.updatable.UnlabelComputeNodeStatement;
+import org.apache.shardingsphere.globalclock.distsql.parser.statement.updatable.AlterGlobalClockRuleStatement;
import org.apache.shardingsphere.parser.distsql.parser.statement.updatable.AlterSQLParserRuleStatement;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.AlterReadwriteSplittingStorageUnitStatusStatement;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ExistingAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable.AlterComputeNodeStatementAssert;
+import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable.AlterGlobalClockRuleStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable.AlterReadwriteSplittingStorageUnitStatusStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable.AlterSQLParserRuleStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable.AlterTrafficRuleStatementAssert;
@@ -45,6 +47,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.r
import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable.UnlabelComputeNodeStatementAssert;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterComputeNodeStatementTestCase;
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterGlobalClockRuleStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterReadwriteSplittingStorageUnitStatusStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterSQLParserRuleStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterTrafficRuleStatementTestCase;
@@ -97,6 +100,8 @@ public final class UpdatableRALStatementAssert {
(AlterReadwriteSplittingStorageUnitStatusStatement) actual, (AlterReadwriteSplittingStorageUnitStatusStatementTestCase) expected);
} else if (actual instanceof LockClusterStatement) {
LockClusterStatementAssert.assertIs(assertContext, (LockClusterStatement) actual, (LockClusterStatementTestCase) expected);
+ } else if (actual instanceof AlterGlobalClockRuleStatement) {
+ AlterGlobalClockRuleStatementAssert.assertIs(assertContext, (AlterGlobalClockRuleStatement) actual, (AlterGlobalClockRuleStatementTestCase) expected);
}
}
}
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/updatable/AlterGlobalClockRuleStatementAssert.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/updatable/AlterGlobalClockRuleStatementAssert.java
new file mode 100644
index 00000000000..590936ca2d1
--- /dev/null
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/ral/impl/updatable/AlterGlobalClockRuleStatementAssert.java
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ral.impl.updatable;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.globalclock.distsql.parser.statement.updatable.AlterGlobalClockRuleStatement;
+import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.SQLCaseAssertContext;
+import org.apache.shardingsphere.test.it.sql.parser.internal.asserts.statement.ExistingAssert;
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterGlobalClockRuleStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+/**
+ * Alter global clock rule statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class AlterGlobalClockRuleStatementAssert {
+
+ /**
+ * Assert alter global clock rule statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual alter global clock rule statement
+ * @param expected expected alter global clock rule statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext, final AlterGlobalClockRuleStatement actual, final AlterGlobalClockRuleStatementTestCase expected) {
+ if (ExistingAssert.assertIs(assertContext, actual, expected)) {
+ assertGlobalClockRule(assertContext, actual, expected);
+ }
+ }
+
+ private static void assertGlobalClockRule(final SQLCaseAssertContext assertContext, final AlterGlobalClockRuleStatement actual, final AlterGlobalClockRuleStatementTestCase expected) {
+ if (null == expected) {
+ assertNull(actual, assertContext.getText("Actual global clock rule should not exist."));
+ } else {
+ assertNotNull(actual, assertContext.getText("Actual global clock rule should exist."));
+ assertThat(assertContext.getText(String.format("Actual type should be %s , but it was %s", expected.getType(), actual.getType())),
+ actual.getType(), is(expected.getType()));
+ assertThat(assertContext.getText(String.format("Actual provider should be %s , but it was %s", expected.getProvider(), actual.getProvider())),
+ actual.getProvider(), is(expected.getProvider()));
+ assertThat(assertContext.getText(String.format("Actual enabled should be %s , but it was %s", expected.isEnabled(), actual.isEnabled())),
+ actual.isEnabled(), is(expected.isEnabled()));
+ assertThat(assertContext.getText(String.format("Actual properties size should be %s , but it was %s", expected.getProperties().size(), actual.getProps().size())),
+ actual.getProps().size(), is(expected.getProperties().size()));
+ }
+ }
+}
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
index 3f6505075dc..ab25dfa0abc 100644
--- a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/RootSQLParserTestCases.java
@@ -288,6 +288,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.SelectStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.dml.UpdateStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterComputeNodeStatementTestCase;
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterGlobalClockRuleStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterLocalTransactionRuleStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterReadwriteSplittingStorageUnitStatusStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.AlterSQLParserRuleStatementTestCase;
@@ -311,6 +312,7 @@ import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.s
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ShowComputeNodesStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ShowDistVariableStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ShowDistVariablesStatementTestCase;
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ShowGlobalClockRuleStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ShowMigrationListStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ShowSQLParserRuleStatementTestCase;
import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral.ShowSQLTranslatorRuleStatementTestCase;
@@ -1240,6 +1242,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "alter-traffic-rule")
private final List<AlterTrafficRuleStatementTestCase> alterTrafficRulesTestCases = new LinkedList<>();
+ @XmlElement(name = "alter-global-clock-rule")
+ private final List<AlterGlobalClockRuleStatementTestCase> alterGlobalClockRulesTestCases = new LinkedList<>();
+
@XmlElement(name = "alter-sql-parser-rule")
private final List<AlterSQLParserRuleStatementTestCase> alterSQLParserRuleTestCases = new LinkedList<>();
@@ -1597,6 +1602,9 @@ public final class RootSQLParserTestCases {
@XmlElement(name = "show-sql-translator-rule")
private final List<ShowSQLTranslatorRuleStatementTestCase> showSQLTranslatorRuleStatementTestCases = new LinkedList<>();
+ @XmlElement(name = "show-global-clock-rule")
+ private final List<ShowGlobalClockRuleStatementTestCase> showGlobalClockRuleStatementTestCases = new LinkedList<>();
+
@XmlElement(name = "create-foreign-table")
private final List<CreateForeignTableStatementTestCase> createForeignTableStatementTestCases = new LinkedList<>();
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterGlobalClockRuleStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterGlobalClockRuleStatementTestCase.java
new file mode 100644
index 00000000000..7c312e04d41
--- /dev/null
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/AlterGlobalClockRuleStatementTestCase.java
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral;
+
+import lombok.Getter;
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.segment.impl.distsql.ExpectedProperty;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Alter global clock rule statement test case.
+ */
+@Getter
+public final class AlterGlobalClockRuleStatementTestCase extends SQLParserTestCase {
+
+ @XmlAttribute
+ private String type;
+
+ @XmlAttribute
+ private String provider;
+
+ @XmlAttribute
+ private boolean enabled;
+
+ @XmlElement(name = "property")
+ private final List<ExpectedProperty> properties = new LinkedList<>();
+}
diff --git a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/ShowGlobalClockRuleStatementTestCase.java b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/ShowGlobalClockRuleStatementTestCase.java
new file mode 100644
index 00000000000..0fa8007d942
--- /dev/null
+++ b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/cases/parser/jaxb/statement/ral/ShowGlobalClockRuleStatementTestCase.java
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+
+package org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.statement.ral;
+
+import org.apache.shardingsphere.test.it.sql.parser.internal.cases.parser.jaxb.SQLParserTestCase;
+
+/**
+ * Show global clock rule statement test case.
+ */
+public final class ShowGlobalClockRuleStatementTestCase extends SQLParserTestCase {
+}
diff --git a/test/it/parser/src/main/resources/case/ral/queryable.xml b/test/it/parser/src/main/resources/case/ral/queryable.xml
index 6f63f1f2a07..ce0143da170 100644
--- a/test/it/parser/src/main/resources/case/ral/queryable.xml
+++ b/test/it/parser/src/main/resources/case/ral/queryable.xml
@@ -32,6 +32,7 @@
<show-sql-parser-rule sql-case-id="show-sql-parser-rule" />
<show-traffic-rules sql-case-id="show-traffic-rules" rule-name="rule_name" />
<show-sql-translator-rule sql-case-id="show-sql-translator-rule" />
+ <show-global-clock-rule sql-case-id="show-global-clock-rule" />
<show-compute-nodes sql-case-id="show-compute-nodes" />
<show-compute-node-info sql-case-id="show-compute-node-info" />
diff --git a/test/it/parser/src/main/resources/case/ral/updatable.xml b/test/it/parser/src/main/resources/case/ral/updatable.xml
index 374b559b314..fbf5fd3094f 100644
--- a/test/it/parser/src/main/resources/case/ral/updatable.xml
+++ b/test/it/parser/src/main/resources/case/ral/updatable.xml
@@ -46,6 +46,11 @@
</load-balancer>
</rule>
</alter-traffic-rule>
+
+ <alter-global-clock-rule sql-case-id="alter-global-clock-rule" type="TSO" provider="redis" enabled="false">
+ <property key="host" value="127.0.0.1" />
+ <property key="port" value="6379" />
+ </alter-global-clock-rule>
<alter-compute-node sql-case-id="alter-compute-node-xa-recovery-nodes" instance-id="instance_xa_recovery" key="XA_RECOVERY_NODES" value="instance_1" />
<alter-compute-node sql-case-id="alter-compute-node-xa-recovery-nodes-with-multiple-values" instance-id="instance_xa_recovery_multiple" key="XA_RECOVERY_NODES" value="instance_1,instance_2" />
diff --git a/test/it/parser/src/main/resources/sql/supported/ral/queryable.xml b/test/it/parser/src/main/resources/sql/supported/ral/queryable.xml
index 554865c6ba3..a119f3bfcd9 100644
--- a/test/it/parser/src/main/resources/sql/supported/ral/queryable.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ral/queryable.xml
@@ -29,6 +29,7 @@
<sql-case id="show-sql-parser-rule" value="SHOW SQL_PARSER RULE" db-types="ShardingSphere" />
<sql-case id="show-traffic-rules" value="SHOW TRAFFIC RULE rule_name" db-types="ShardingSphere" />
<sql-case id="show-sql-translator-rule" value="SHOW SQL_TRANSLATOR RULE" db-types="ShardingSphere" />
+ <sql-case id="show-global-clock-rule" value="SHOW GLOBAL CLOCK RULE" db-types="ShardingSphere" />
<sql-case id="show-compute-nodes" value="SHOW COMPUTE NODES" db-types="ShardingSphere" />
<sql-case id="show-compute-node-info" value="SHOW COMPUTE NODE INFO" db-types="ShardingSphere" />
diff --git a/test/it/parser/src/main/resources/sql/supported/ral/updatable.xml b/test/it/parser/src/main/resources/sql/supported/ral/updatable.xml
index 8c8bf5f37dd..b637a66dfee 100644
--- a/test/it/parser/src/main/resources/sql/supported/ral/updatable.xml
+++ b/test/it/parser/src/main/resources/sql/supported/ral/updatable.xml
@@ -30,6 +30,7 @@
<sql-case id="alter-xa-transaction-rule" value="ALTER TRANSACTION RULE(DEFAULT='XA', TYPE(NAME='Atomikos'))" db-types="ShardingSphere" />
<sql-case id="alter-xa-transaction-rule-without-quote-on-build-in-default-type-name-and-provider-type-name" value="ALTER TRANSACTION RULE(DEFAULT=XA, TYPE(NAME=Atomikos))" db-types="ShardingSphere" />
<sql-case id="alter-traffic-rule" value="ALTER TRAFFIC RULE sql_match_traffic (LABELS(OLTP),TRAFFIC_ALGORITHM(TYPE(NAME='SQL_MATCH',PROPERTIES('sql' = 'SELECT * FROM t_order WHERE order_id = ?; UPDATE t_order SET order_id = ?;'))), LOAD_BALANCER(TYPE(NAME='RANDOM', PROPERTIES('key'='value'))) )" db-types="ShardingSphere" />
+ <sql-case id="alter-global-clock-rule" value="ALTER GLOBAL CLOCK RULE(type = 'TSO', provider = 'redis', enabled = false, properties('host'='127.0.0.1','port'='6379'));" db-types="ShardingSphere" />
<sql-case id="alter-compute-node-xa-recovery-nodes" value="ALTER COMPUTE NODE instance_xa_recovery SET XA_RECOVERY_NODES='instance_1'" db-types="ShardingSphere" />
<sql-case id="alter-compute-node-xa-recovery-nodes-with-multiple-values" value="ALTER COMPUTE NODE instance_xa_recovery_multiple SET XA_RECOVERY_NODES='instance_1,instance_2'" db-types="ShardingSphere" />