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 df42bf6 [DistSQL] Add `drop traffic rule` syntax parse test. (#15074)
df42bf6 is described below
commit df42bf6085773b0d607ebba8da492d0d738e45fc
Author: lanchengx <[email protected]>
AuthorDate: Wed Jan 26 13:13:27 2022 +0800
[DistSQL] Add `drop traffic rule` syntax parse test. (#15074)
* Add `drop traffic rule` syntax parse test.
* Update common.xml
* Update common.xml
---
.../ral/impl/CommonDistSQLStatementAssert.java | 7 ++-
.../common/DropTrafficRuleStatementAssert.java | 54 ++++++++++++++++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 5 ++
.../ral/DropTrafficRuleStatementTestCase.java | 36 +++++++++++++++
.../src/main/resources/case/ral/common.xml | 3 ++
.../main/resources/sql/supported/ral/common.xml | 1 +
6 files changed, 105 insertions(+), 1 deletion(-)
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/CommonDistSQLStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/CommonDistSQLStatementAssert.java
index 3022b32..bc81bf7 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/CommonDistSQLStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/CommonDistSQLStatementAssert.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.CommonDistSQLState
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.RefreshTableMetadataStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.alter.AlterSQLParserRuleStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.common.drop.DropTrafficRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowAllVariablesStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowAuthorityRuleStatement;
@@ -35,6 +36,7 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowVa
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.AlterSQLParserRuleStatementAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.DropTrafficRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.RefreshTableMetadataStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.SetVariableStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.ShowAllVariablesStatementAssert;
@@ -48,6 +50,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.ShowVariableStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterSQLParserRuleStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.DropTrafficRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.RefreshTableMetadataStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.SetVariableStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowAllVariablesStatementTestCase;
@@ -99,6 +102,8 @@ public final class CommonDistSQLStatementAssert {
ShowSQLParserRuleStatementAssert.assertIs(assertContext,
(ShowSQLParserRuleStatement) actual, (ShowSQLParserRuleStatementTestCase)
expected);
} else if (actual instanceof AlterSQLParserRuleStatement) {
AlterSQLParserRuleStatementAssert.assertIs(assertContext,
(AlterSQLParserRuleStatement) actual, (AlterSQLParserRuleStatementTestCase)
expected);
- }
+ } else if (actual instanceof DropTrafficRuleStatement) {
+ DropTrafficRuleStatementAssert.assertIs(assertContext,
(DropTrafficRuleStatement) actual, (DropTrafficRuleStatementTestCase) expected);
+ }
}
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/common/DropTrafficRuleStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/common/DropTrafficRuleStatementAssert.java
new file mode 100644
index 0000000..f103230
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/common/DropTrafficRuleStatementAssert.java
@@ -0,0 +1,54 @@
+/*
+ * 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.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.common.drop.DropTrafficRuleStatement;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.DropTrafficRuleStatementTestCase;
+
+import java.util.ArrayList;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Drop traffic rule statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DropTrafficRuleStatementAssert {
+
+ /**
+ * Assert drop traffic rule statement is correct with expected parser
result.
+ *
+ * @param assertContext assert context
+ * @param actual actual drop traffic rule statement
+ * @param expected expected drop traffic rule statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final DropTrafficRuleStatement actual, final DropTrafficRuleStatementTestCase
expected) {
+ if (null == expected) {
+ assertNull(assertContext.getText("Actual statement should not
exist."), actual);
+ } else {
+ assertNotNull(assertContext.getText("Actual statement should
exist."), actual);
+ assertThat(assertContext.getText("Rule name id assertion error"),
new ArrayList<>(actual.getRuleNames()), is(new
ArrayList<>(expected.getRuleNames())));
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index c286944..cfed0e3 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -165,6 +165,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ClearHintStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ClearReadwriteSplittingHintStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ClearShardingHintStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.DropTrafficRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ParseStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.PreviewStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.RefreshTableMetadataStatementTestCase;
@@ -997,6 +998,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "alter-sql-parser-rule")
private final List<AlterSQLParserRuleStatementTestCase>
alterSQLParserRuleStatementTestCases = new LinkedList<>();
+ @XmlElement(name = "drop-traffic-rule")
+ private final List<DropTrafficRuleStatementTestCase>
dropTrafficRuleStatementTestCases = new LinkedList<>();
+
@XmlElement(name = "show-table-metadata")
private final List<ShowTableMetadataStatementTestCase>
showTableMetadataStatementTestCases = new LinkedList<>();
@@ -1314,6 +1318,7 @@ public final class SQLParserTestCases {
putAll(alterLanguageStatementTestCases, result);
putAll(dropLanguageStatementTestCases, result);
putAll(showTableMetadataStatementTestCases, result);
+ putAll(dropTrafficRuleStatementTestCases, result);
putAll(helpStatementTestCases, result);
putAll(showUnusedShardingAlgorithmsStatementTestCases, result);
putAll(showUnusedShardingKeyGeneratorsStatementTestCases, result);
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/DropTrafficRuleStatementTestCase.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/DropTrafficRuleStatementTestCase.java
new file mode 100644
index 0000000..7617a76
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/DropTrafficRuleStatementTestCase.java
@@ -0,0 +1,36 @@
+/*
+ * 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.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral;
+
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+import java.util.Collection;
+
+/**
+ * Drop traffic rule statement test case.
+ */
+@Getter
+@Setter
+public final class DropTrafficRuleStatementTestCase extends SQLParserTestCase {
+
+ @XmlElement(name = "rule-name")
+ private Collection<String> ruleNames;
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/common.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/common.xml
index e0d956a..5830923 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/common.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/common.xml
@@ -48,4 +48,7 @@
</sql-parser>
</alter-sql-parser-rule>
<show-traffic-rules sql-case-id="show-traffic-rules"
rule-name="rule_name"/>
+ <drop-traffic-rule sql-case-id="drop-traffic-rule" >
+ <rule-name>rule_name</rule-name>
+ </drop-traffic-rule>
</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/common.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/common.xml
index f36277d..fa89403 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/common.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/common.xml
@@ -40,4 +40,5 @@
<distsql-case id="show-sql-parser-rule" value="SHOW SQL_PARSER RULE" />
<distsql-case id="alter-sql-parser-rule" value="ALTER SQL_PARSER RULE
SQL_COMMENT_PARSE_ENABLE=false,PARSE_TREE_CACHE(INITIAL_CAPACITY=10,
MAXIMUM_SIZE=11,CONCURRENCY_LEVEL=1), SQL_STATEMENT_CACHE(INITIAL_CAPACITY=11,
MAXIMUM_SIZE=11,CONCURRENCY_LEVEL=100)" />
<distsql-case id="show-traffic-rules" value="SHOW TRAFFIC RULE rule_name"
/>
+ <distsql-case id="drop-traffic-rule" value="DROP TRAFFIC RULE rule_name" />
</sql-cases>