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 9761864  [DistSQL] Add `create/alter traffic rule` parse tests. 
(#15204)
9761864 is described below

commit 9761864a5b5f177646bc3d622d4a6de932f77660
Author: lanchengx <[email protected]>
AuthorDate: Mon Jan 31 23:54:17 2022 +0800

    [DistSQL] Add `create/alter traffic rule` parse tests. (#15204)
    
    * Add `create/alter traffic rule` parse tests.
    
    * Reformat.
---
 .../ral/impl/CommonDistSQLStatementAssert.java     | 10 ++++
 .../common/AlterTrafficRuleStatementAssert.java    | 70 ++++++++++++++++++++++
 .../common/CreateTrafficRuleStatementAssert.java   | 70 ++++++++++++++++++++++
 .../jaxb/cases/domain/SQLParserTestCases.java      | 10 ++++
 .../impl/distsql/ral/ExpectedTrafficRule.java      | 43 +++++++++++++
 .../ral/AlterTrafficRuleStatementTestCase.java     | 38 ++++++++++++
 .../ral/CreateTrafficRuleStatementTestCase.java    | 38 ++++++++++++
 .../src/main/resources/case/ral/common.xml         | 30 ++++++++++
 .../main/resources/sql/supported/ral/common.xml    |  2 +
 9 files changed, 311 insertions(+)

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 8c1ee6e..e1d9659 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
@@ -34,9 +34,13 @@ import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowTa
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowTrafficRulesStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowTransactionRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowVariableStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.AlterTrafficRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateTrafficRuleStatement;
 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.AlterTrafficRuleStatementAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.CreateTrafficRuleStatementAssert;
 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.ExportSchemaConfigurationStatementAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.RefreshTableMetadataStatementAssert;
@@ -52,6 +56,8 @@ 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.AlterTrafficRuleStatementTestCase;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.CreateTrafficRuleStatementTestCase;
 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.ExportSchemaConfigurationStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.RefreshTableMetadataStatementTestCase;
@@ -109,6 +115,10 @@ public final class CommonDistSQLStatementAssert {
             DropTrafficRuleStatementAssert.assertIs(assertContext, 
(DropTrafficRuleStatement) actual, (DropTrafficRuleStatementTestCase) expected);
         } else if (actual instanceof ExportSchemaConfigurationStatement) {
             ExportSchemaConfigurationStatementAssert.assertIs(assertContext, 
(ExportSchemaConfigurationStatement) actual, 
(ExportSchemaConfigurationStatementTestCase) expected);
+        } else if (actual instanceof CreateTrafficRuleStatement) {
+            CreateTrafficRuleStatementAssert.assertIs(assertContext, 
(CreateTrafficRuleStatement) actual, (CreateTrafficRuleStatementTestCase) 
expected);
+        } else if (actual instanceof AlterTrafficRuleStatement) {
+            AlterTrafficRuleStatementAssert.assertIs(assertContext, 
(AlterTrafficRuleStatement) actual, (AlterTrafficRuleStatementTestCase) 
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/AlterTrafficRuleStatementAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/common/AlterTrafficRuleStatementAssert.java
new file mode 100644
index 0000000..5cd1d0a
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/common/AlterTrafficRuleStatementAssert.java
@@ -0,0 +1,70 @@
+/*
+ * 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 org.apache.shardingsphere.distsql.parser.segment.TrafficRuleSegment;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.AlterTrafficRuleStatement;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.distsql.AlgorithmAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.ral.ExpectedTrafficRule;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterTrafficRuleStatementTestCase;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Alter traffic rule statement assert.
+ */
+public final class AlterTrafficRuleStatementAssert {
+    
+    /**
+     * Assert alter traffic rule statement is correct with expected parser 
result.
+     *
+     * @param assertContext assert context
+     * @param actual actual alter traffic rule statement
+     * @param expected expected alter traffic rule statement test case
+     */
+    public static void assertIs(final SQLCaseAssertContext assertContext, 
final AlterTrafficRuleStatement actual, final AlterTrafficRuleStatementTestCase 
expected) {
+        if (null == expected) {
+            assertNull(assertContext.getText("Actual statement should not 
exist."), actual);
+        } else {
+            assertNotNull(assertContext.getText("Actual statement should 
exist."), actual);
+            assertNotNull(actual);
+            assertTrafficRuleSegments(assertContext, actual.getSegments(), 
expected.getRules());
+        }
+    }
+    
+    private static void assertTrafficRuleSegments(final SQLCaseAssertContext 
assertContext, final Collection<TrafficRuleSegment> actual, final 
List<ExpectedTrafficRule> expected) {
+        Map<String, TrafficRuleSegment> actualMap = 
actual.stream().collect(Collectors.toMap(TrafficRuleSegment::getName, each -> 
each));
+        expected.forEach(each -> {
+            TrafficRuleSegment actualRule = actualMap.get(each.getName());
+            assertNotNull(actualRule);
+            assertThat(actualRule.getName(), is(each.getName()));
+            assertThat(actualRule.getLabels(), is(each.getLabels()));
+            AlgorithmAssert.assertIs(assertContext, actualRule.getAlgorithm(), 
each.getTrafficAlgorithm());
+            AlgorithmAssert.assertIs(assertContext, 
actualRule.getLoadBalancer(), each.getLoadBalancer());
+        });
+    }
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/common/CreateTrafficRuleStatementAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/common/CreateTrafficRuleStatementAssert.java
new file mode 100644
index 0000000..0411aab
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/common/CreateTrafficRuleStatementAssert.java
@@ -0,0 +1,70 @@
+/*
+ * 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 org.apache.shardingsphere.distsql.parser.segment.TrafficRuleSegment;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.CreateTrafficRuleStatement;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.distsql.AlgorithmAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.ral.ExpectedTrafficRule;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.CreateTrafficRuleStatementTestCase;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Create traffic rule statement assert.
+ */
+public final class CreateTrafficRuleStatementAssert {
+    
+    /**
+     * Assert create traffic rule statement is correct with expected parser 
result.
+     *
+     * @param assertContext assert context
+     * @param actual actual create traffic rule statement
+     * @param expected expected create traffic rule statement test case
+     */
+    public static void assertIs(final SQLCaseAssertContext assertContext, 
final CreateTrafficRuleStatement actual, final 
CreateTrafficRuleStatementTestCase expected) {
+        if (null == expected) {
+            assertNull(assertContext.getText("Actual statement should not 
exist."), actual);
+        } else {
+            assertNotNull(assertContext.getText("Actual statement should 
exist."), actual);
+            assertNotNull(actual);
+            assertTrafficRuleSegments(assertContext, actual.getSegments(), 
expected.getRules());
+        }
+    }
+    
+    private static void assertTrafficRuleSegments(final SQLCaseAssertContext 
assertContext, final Collection<TrafficRuleSegment> actual, final 
List<ExpectedTrafficRule> expected) {
+        Map<String, TrafficRuleSegment> actualMap = 
actual.stream().collect(Collectors.toMap(TrafficRuleSegment::getName, each -> 
each));
+        expected.forEach(each -> {
+            TrafficRuleSegment actualRule = actualMap.get(each.getName());
+            assertNotNull(actualRule);
+            assertThat(actualRule.getName(), is(each.getName()));
+            assertThat(actualRule.getLabels(), is(each.getLabels()));
+            AlgorithmAssert.assertIs(assertContext, actualRule.getAlgorithm(), 
each.getTrafficAlgorithm());
+            AlgorithmAssert.assertIs(assertContext, 
actualRule.getLoadBalancer(), each.getLoadBalancer());
+        });
+    }
+}
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 a424b1e..ff7ccfe 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
@@ -162,9 +162,11 @@ 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.AddShardingHintDatabaseValueStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AddShardingHintTableValueStatementTestCase;
 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.AlterTrafficRuleStatementTestCase;
 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.CreateTrafficRuleStatementTestCase;
 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.ExportSchemaConfigurationStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ParseStatementTestCase;
@@ -996,6 +998,12 @@ public final class SQLParserTestCases {
     @XmlElement(name = "show-traffic-rules")
     private final List<ShowTrafficRulesStatementTestCase> 
showTrafficRulesStatementTestCases = new LinkedList<>();
     
+    @XmlElement(name = "create-traffic-rule")
+    private final List<CreateTrafficRuleStatementTestCase> 
createTrafficRulesStatementTestCases = new LinkedList<>();
+    
+    @XmlElement(name = "alter-traffic-rule")
+    private final List<AlterTrafficRuleStatementTestCase> 
alterTrafficRulesStatementTestCases = new LinkedList<>();
+    
     @XmlElement(name = "alter-sql-parser-rule")
     private final List<AlterSQLParserRuleStatementTestCase> 
alterSQLParserRuleStatementTestCases = new LinkedList<>();
     
@@ -1305,6 +1313,8 @@ public final class SQLParserTestCases {
         putAll(showAuthorityRuleStatementTestCases, result);
         putAll(showTransactionRuleStatementTestCases, result);
         putAll(showTrafficRulesStatementTestCases, result);
+        putAll(createTrafficRulesStatementTestCases, result);
+        putAll(alterTrafficRulesStatementTestCases, result);
         putAll(alterSQLParserRuleStatementTestCases, result);
         putAll(createTypeStatementTestCases, result);
         putAll(createConversionStatementTestCase, result);
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/ral/ExpectedTrafficRule.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/ral/ExpectedTrafficRule.java
new file mode 100644
index 0000000..8ab6d39
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/segment/impl/distsql/ral/ExpectedTrafficRule.java
@@ -0,0 +1,43 @@
+/*
+ * 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.segment.impl.distsql.ral;
+
+import lombok.Getter;
+import lombok.Setter;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.AbstractExpectedIdentifierSQLSegment;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.ExpectedAlgorithm;
+
+import javax.xml.bind.annotation.XmlElement;
+import java.util.Collection;
+
+/**
+ * Expected traffic rule.
+ */
+@Getter
+@Setter
+public final class ExpectedTrafficRule extends 
AbstractExpectedIdentifierSQLSegment {
+    
+    @XmlElement(name = "label")
+    private Collection<String> labels;
+    
+    @XmlElement(name = "traffic-algorithm")
+    private ExpectedAlgorithm trafficAlgorithm;
+    
+    @XmlElement(name = "load-balancer")
+    private ExpectedAlgorithm loadBalancer;
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterTrafficRuleStatementTestCase.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterTrafficRuleStatementTestCase.java
new file mode 100644
index 0000000..5f91e0c
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/AlterTrafficRuleStatementTestCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.segment.impl.distsql.ral.ExpectedTrafficRule;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Alter traffic rule statement test case.
+ */
+@Getter
+@Setter
+public final class AlterTrafficRuleStatementTestCase extends SQLParserTestCase 
{
+   
+    @XmlElement(name = "rule")
+    private final List<ExpectedTrafficRule> rules = new LinkedList<>();
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/CreateTrafficRuleStatementTestCase.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/CreateTrafficRuleStatementTestCase.java
new file mode 100644
index 0000000..a513d89
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/CreateTrafficRuleStatementTestCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.segment.impl.distsql.ral.ExpectedTrafficRule;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Create traffic rule statement test case.
+ */
+@Getter
+@Setter
+public final class CreateTrafficRuleStatementTestCase extends 
SQLParserTestCase {
+   
+    @XmlElement(name = "rule")
+    private final List<ExpectedTrafficRule> rules = new LinkedList<>();
+}
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 2d46e86..7d15e07 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
@@ -54,4 +54,34 @@
     <export-schema-config sql-case-id="export-schema-config">
         <schema name="schema_name" start-index="26" stop-index="36" />
     </export-schema-config>
+    <create-traffic-rule sql-case-id="create-traffic-rule" >
+        <rule name="sql_match_traffic">
+            <label>OLTP</label>
+            <traffic-algorithm algorithm-name="SQL_MATCH">
+                <properties>
+                    <property key="sql" value="SELECT * FROM t_order WHERE 
order_id = ?; UPDATE t_order SET order_id = ?;"/>
+                </properties>
+            </traffic-algorithm>
+            <load-balancer algorithm-name="RANDOM">
+                <properties>
+                    <property key="key" value="value"/>
+                </properties>
+            </load-balancer>
+        </rule>
+    </create-traffic-rule>
+    <alter-traffic-rule sql-case-id="alter-traffic-rule" >
+        <rule name="sql_match_traffic">
+            <label>OLTP</label>
+            <traffic-algorithm algorithm-name="SQL_MATCH">
+                <properties>
+                    <property key="sql" value="SELECT * FROM t_order WHERE 
order_id = ?; UPDATE t_order SET order_id = ?;"/>
+                </properties>
+            </traffic-algorithm>
+            <load-balancer algorithm-name="RANDOM">
+                <properties>
+                    <property key="key" value="value"/>
+                </properties>
+            </load-balancer>
+        </rule>
+    </alter-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 5c7719c..38a6f85 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
@@ -42,4 +42,6 @@
     <distsql-case id="show-traffic-rules" value="SHOW TRAFFIC RULE rule_name" 
/>
     <distsql-case id="drop-traffic-rule" value="DROP TRAFFIC RULE rule_name" />
     <distsql-case id="export-schema-config" value="EXPORT SCHEMA CONFIG FROM 
schema_name" />
+    <distsql-case id="create-traffic-rule" value="CREATE 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'))) )" />
+    <distsql-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'))) )" />
 </sql-cases>

Reply via email to