You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/10/02 06:59:29 UTC

[shardingsphere] branch master updated: [Issue #20400]-Add unit test for YamlSQLParserRuleConfigurationSwapper (#21290)

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

duanzhengqiang 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 d7565e9b4f6 [Issue #20400]-Add unit test for YamlSQLParserRuleConfigurationSwapper (#21290)
d7565e9b4f6 is described below

commit d7565e9b4f6d59f7a81f6f93e5ea2f34eef73416
Author: Abhinav Koppula <ab...@gmail.com>
AuthorDate: Sun Oct 2 12:29:21 2022 +0530

    [Issue #20400]-Add unit test for YamlSQLParserRuleConfigurationSwapper (#21290)
    
    * [Issue #20400]-Add unit test for YamlSQLParserRuleConfigurationSwapper
    
    * [ReviewComment]-Renamed actualResult to actual
---
 .../YamlSQLParserRuleConfigurationSwapperTest.java | 87 ++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserRuleConfigurationSwapperTest.java b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserRuleConfigurationSwapperTest.java
new file mode 100644
index 00000000000..b8df431dacc
--- /dev/null
+++ b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-core/src/test/java/org/apache/shardingsphere/parser/yaml/swapper/YamlSQLParserRuleConfigurationSwapperTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.parser.yaml.swapper;
+
+import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
+import org.apache.shardingsphere.parser.constant.SQLParserOrder;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.shardingsphere.parser.yaml.config.YamlSQLParserCacheOptionRuleConfiguration;
+import org.apache.shardingsphere.parser.yaml.config.YamlSQLParserRuleConfiguration;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.junit.Test;
+
+public final class YamlSQLParserRuleConfigurationSwapperTest {
+    
+    @Test
+    public void assertSwapToYamlConfiguration() {
+        YamlSQLParserRuleConfiguration actual =
+                new YamlSQLParserRuleConfigurationSwapper().swapToYamlConfiguration(new SQLParserRuleConfiguration(true, new CacheOption(2, 5), new CacheOption(4, 7)));
+        assertTrue(actual.isSqlCommentParseEnabled());
+        assertThat(actual.getParseTreeCache().getInitialCapacity(), is(2));
+        assertThat(actual.getParseTreeCache().getMaximumSize(), is(5L));
+        assertThat(actual.getSqlStatementCache().getInitialCapacity(), is(4));
+        assertThat(actual.getSqlStatementCache().getMaximumSize(), is(7L));
+    }
+    
+    @Test
+    public void assertSwapToObjectWithDefaultConfig() {
+        YamlSQLParserRuleConfiguration configuration = new YamlSQLParserRuleConfiguration();
+        configuration.setSqlCommentParseEnabled(true);
+        SQLParserRuleConfiguration actual = new YamlSQLParserRuleConfigurationSwapper().swapToObject(configuration);
+        assertThat(actual.getParseTreeCache().getInitialCapacity(), is(128));
+        assertThat(actual.getParseTreeCache().getMaximumSize(), is(1024L));
+        assertThat(actual.getSqlStatementCache().getInitialCapacity(), is(2000));
+        assertThat(actual.getSqlStatementCache().getMaximumSize(), is(65535L));
+    }
+    
+    @Test
+    public void assertSwapToObject() {
+        YamlSQLParserRuleConfiguration configuration = new YamlSQLParserRuleConfiguration();
+        configuration.setSqlCommentParseEnabled(true);
+        configuration.setParseTreeCache(new YamlSQLParserCacheOptionRuleConfiguration());
+        configuration.getParseTreeCache().setInitialCapacity(2);
+        configuration.getParseTreeCache().setMaximumSize(5L);
+        configuration.setSqlStatementCache(new YamlSQLParserCacheOptionRuleConfiguration());
+        configuration.getSqlStatementCache().setInitialCapacity(4);
+        configuration.getSqlStatementCache().setMaximumSize(7L);
+        SQLParserRuleConfiguration actual = new YamlSQLParserRuleConfigurationSwapper().swapToObject(configuration);
+        assertThat(actual.getParseTreeCache().getInitialCapacity(), is(2));
+        assertThat(actual.getParseTreeCache().getMaximumSize(), is(5L));
+        assertThat(actual.getSqlStatementCache().getInitialCapacity(), is(4));
+        assertThat(actual.getSqlStatementCache().getMaximumSize(), is(7L));
+    }
+    
+    @Test
+    public void assertGetTypeClass() {
+        assertThat(new YamlSQLParserRuleConfigurationSwapper().getTypeClass().toString(), is(SQLParserRuleConfiguration.class.toString()));
+    }
+    
+    @Test
+    public void assertGetRuleTagName() {
+        assertThat(new YamlSQLParserRuleConfigurationSwapper().getRuleTagName(), is("SQL_PARSER"));
+    }
+    
+    @Test
+    public void assertGetOrder() {
+        assertThat(new YamlSQLParserRuleConfigurationSwapper().getOrder(), is(SQLParserOrder.ORDER));
+    }
+}