You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2020/12/11 03:20:31 UTC

[shardingsphere] branch master updated: Fix#8238 (#8543)

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

panjuan 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 ad5a159  Fix#8238 (#8543)
ad5a159 is described below

commit ad5a1599fa7ef16454bab0a37f18e2a2d410150b
Author: huanghao495430759 <34...@users.noreply.github.com>
AuthorDate: Fri Dec 11 11:20:06 2020 +0800

    Fix#8238 (#8543)
    
    * Add test case for PostgreSQLCommand #8439
    
    * Add test case for UpdateResponseHeader #8440
    
    * Add test case for PostgreSQLCommand #8439
    
    * Add test case for UpdateResponseHeader #8440
    
    * revert commit
    
    * Fixes #8238. add test case for ParseTreeCacheLoader and SQLStatementCacheLoader.
    
    * Fixes #8238. add blank line in SQLStatementCacheLoader.
    
    Co-authored-by: huanghao-jk <hu...@360jinrong.net>
---
 .../parser/cache/SQLStatementCacheLoaderTest.java  | 47 ++++++++++++++++++++++
 .../core/cache/ParseTreeCacheBuilderTest.java      | 35 ++++++++++++++++
 .../core/cache/ParseTreeCacheLoaderTest.java       | 46 +++++++++++++++++++++
 3 files changed, 128 insertions(+)

diff --git a/shardingsphere-infra/shardingsphere-infra-parser/src/test/java/org/apache/shardingsphere/infra/parser/cache/SQLStatementCacheLoaderTest.java b/shardingsphere-infra/shardingsphere-infra-parser/src/test/java/org/apache/shardingsphere/infra/parser/cache/SQLStatementCacheLoaderTest.java
new file mode 100644
index 0000000..469ff86
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-parser/src/test/java/org/apache/shardingsphere/infra/parser/cache/SQLStatementCacheLoaderTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.infra.parser.cache;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.parser.sql.SQLStatementParserExecutor;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.lang.reflect.Field;
+
+import static org.hamcrest.CoreMatchers.isA;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class SQLStatementCacheLoaderTest {
+
+    private static final String SQL = "select * from user where id=1";
+
+    @SneakyThrows
+    @Test
+    public void assertSQLStatementCacheLoad() {
+        SQLStatementCacheLoader sqlStatementCacheLoader = new SQLStatementCacheLoader("MySQL");
+        Field sqlStatementParserExecutorField = sqlStatementCacheLoader.getClass().getDeclaredField("sqlStatementParserExecutor");
+        SQLStatementParserExecutor executor = mock(SQLStatementParserExecutor.class, Mockito.RETURNS_DEEP_STUBS);
+        sqlStatementParserExecutorField.setAccessible(true);
+        sqlStatementParserExecutorField.set(sqlStatementCacheLoader, executor);
+        assertThat(sqlStatementCacheLoader.load(SQL), isA(SQLStatement.class));
+        sqlStatementParserExecutorField.setAccessible(false);
+    }
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/test/java/org/apache/shardingsphere/sql/parser/core/cache/ParseTreeCacheBuilderTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/test/java/org/apache/shardingsphere/sql/parser/core/cache/ParseTreeCacheBuilderTest.java
new file mode 100644
index 0000000..996bdc6
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/test/java/org/apache/shardingsphere/sql/parser/core/cache/ParseTreeCacheBuilderTest.java
@@ -0,0 +1,35 @@
+/*
+ * 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.sql.parser.core.cache;
+
+import com.google.common.cache.LoadingCache;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.isA;
+import static org.junit.Assert.assertThat;
+
+public final class ParseTreeCacheBuilderTest {
+
+    @Test
+    public void assertParseTreeCacheBuild() {
+        LoadingCache<String, ParseTree> cache = ParseTreeCacheBuilder.build(new CacheOption(1, 10, 1), "MySQL");
+        assertThat(cache, isA(LoadingCache.class));
+    }
+}
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/test/java/org/apache/shardingsphere/sql/parser/core/cache/ParseTreeCacheLoaderTest.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/test/java/org/apache/shardingsphere/sql/parser/core/cache/ParseTreeCacheLoaderTest.java
new file mode 100644
index 0000000..4e4e907
--- /dev/null
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/test/java/org/apache/shardingsphere/sql/parser/core/cache/ParseTreeCacheLoaderTest.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.sql.parser.core.cache;
+
+import lombok.SneakyThrows;
+import org.antlr.v4.runtime.tree.ParseTree;
+import org.apache.shardingsphere.sql.parser.core.parser.SQLParserExecutor;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import java.lang.reflect.Field;
+
+import static org.hamcrest.CoreMatchers.isA;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+
+public final class ParseTreeCacheLoaderTest {
+
+    private static final String SQL = "select * from user where id=1";
+
+    @SneakyThrows
+    @Test
+    public void assertParseTreeCacheLoader() {
+        SQLParserExecutor sqlParserExecutor = mock(SQLParserExecutor.class, Mockito.RETURNS_DEEP_STUBS);
+        ParseTreeCacheLoader loader = new ParseTreeCacheLoader("MySQL");
+        Field sqlParserExecutorField = loader.getClass().getDeclaredField("sqlParserExecutor");
+        sqlParserExecutorField.setAccessible(true);
+        sqlParserExecutorField.set(loader, sqlParserExecutor);
+        assertThat(loader.load(SQL), isA(ParseTree.class));
+    }
+}