You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/05/16 10:26:30 UTC

[shardingsphere] branch master updated: Add test cases for SQLRewriteContextDecoratorFactory and ExecutionPrepareDecoratorFactory . (#17701)

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

zhangliang 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 125e5a1f960 Add test cases for SQLRewriteContextDecoratorFactory and ExecutionPrepareDecoratorFactory . (#17701)
125e5a1f960 is described below

commit 125e5a1f960060ed2e0caa075b6a3efea9a5d85d
Author: VOPEN.XYZ <x_...@yeah.net>
AuthorDate: Mon May 16 18:26:24 2022 +0800

    Add test cases for SQLRewriteContextDecoratorFactory and ExecutionPrepareDecoratorFactory . (#17701)
    
    * change file line separator with LF
    
    * Add test cases for SQLRewriteContextDecoratorFactory and ExecutionPrepareDecoratorFactory .
---
 .../fixture/FixtureExecutionPrepareDecorator.java  | 43 ++++++++++++++++++++
 .../infra/executor/sql/fixture/FixtureRule.java    | 28 +++++++++++++
 .../ExecutionPrepareDecoratorFactoryTest.java      | 46 +++++++++++++++++++++
 ....executor.sql.prepare.ExecutionPrepareDecorator | 18 +++++++++
 .../SQLRewriteContextDecoratorFactoryTest.java     | 47 ++++++++++++++++++++++
 .../infra/rewrite/fixture/FixtureRule.java         | 28 +++++++++++++
 .../fixture/FixtureSQLRewriteContextDecorator.java | 41 +++++++++++++++++++
 ...nfra.rewrite.context.SQLRewriteContextDecorator | 18 +++++++++
 8 files changed, 269 insertions(+)

diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureExecutionPrepareDecorator.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureExecutionPrepareDecorator.java
new file mode 100644
index 00000000000..17fe7646834
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureExecutionPrepareDecorator.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.infra.executor.sql.fixture;
+
+import java.util.Collection;
+import java.util.Collections;
+import org.apache.shardingsphere.infra.executor.kernel.model.ExecutionGroup;
+import org.apache.shardingsphere.infra.executor.sql.prepare.ExecutionPrepareDecorator;
+import org.apache.shardingsphere.infra.route.context.RouteContext;
+
+public final class FixtureExecutionPrepareDecorator implements ExecutionPrepareDecorator<Object, FixtureRule> {
+    
+    @Override
+    public Collection<ExecutionGroup<Object>> decorate(final RouteContext routeContext, final FixtureRule rule,
+                                                       final Collection<ExecutionGroup<Object>> executionGroups) {
+        return Collections.emptyList();
+    }
+    
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+    
+    @Override
+    public Class<FixtureRule> getTypeClass() {
+        return FixtureRule.class;
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureRule.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureRule.java
new file mode 100644
index 00000000000..882b07f2eb8
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/fixture/FixtureRule.java
@@ -0,0 +1,28 @@
+/*
+ * 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.executor.sql.fixture;
+
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+
+public final class FixtureRule implements ShardingSphereRule {
+    
+    @Override
+    public String getType() {
+        return FixtureRule.class.getSimpleName();
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/prepare/ExecutionPrepareDecoratorFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/prepare/ExecutionPrepareDecoratorFactoryTest.java
new file mode 100644
index 00000000000..8485e3373ef
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/prepare/ExecutionPrepareDecoratorFactoryTest.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.infra.executor.sql.prepare;
+
+import org.apache.shardingsphere.infra.executor.sql.fixture.FixtureExecutionPrepareDecorator;
+import org.apache.shardingsphere.infra.executor.sql.fixture.FixtureRule;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class ExecutionPrepareDecoratorFactoryTest {
+    
+    @Test
+    @SuppressWarnings("rawtypes")
+    public void assertGetInstance() {
+        FixtureRule rule = new FixtureRule();
+        Map<ShardingSphereRule, ExecutionPrepareDecorator> actual = ExecutionPrepareDecoratorFactory.getInstance(Collections.singleton(rule));
+        assertNotNull(actual);
+        assertFalse(actual.isEmpty());
+        assertTrue(actual.containsKey(rule));
+        assertThat(actual.get(rule), instanceOf(FixtureExecutionPrepareDecorator.class));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-executor/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.executor.sql.prepare.ExecutionPrepareDecorator b/shardingsphere-infra/shardingsphere-infra-executor/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.executor.sql.prepare.ExecutionPrepareDecorator
new file mode 100644
index 00000000000..90d3fe0ae29
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-executor/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.executor.sql.prepare.ExecutionPrepareDecorator
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.executor.sql.fixture.FixtureExecutionPrepareDecorator
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextDecoratorFactoryTest.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextDecoratorFactoryTest.java
new file mode 100644
index 00000000000..e744083f471
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/context/SQLRewriteContextDecoratorFactoryTest.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.rewrite.context;
+
+import org.apache.shardingsphere.infra.rewrite.fixture.FixtureRule;
+import org.apache.shardingsphere.infra.rewrite.fixture.FixtureSQLRewriteContextDecorator;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public final class SQLRewriteContextDecoratorFactoryTest {
+    
+    @Test
+    @SuppressWarnings("rawtypes")
+    public void assertGetInstance() {
+        FixtureRule rule = new FixtureRule();
+        Map<ShardingSphereRule, SQLRewriteContextDecorator> actual = SQLRewriteContextDecoratorFactory.getInstance(
+                Collections.singleton(rule));
+        assertNotNull(actual);
+        assertFalse(actual.isEmpty());
+        assertTrue(actual.containsKey(rule));
+        assertThat(actual.get(rule), instanceOf(FixtureSQLRewriteContextDecorator.class));
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/fixture/FixtureRule.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/fixture/FixtureRule.java
new file mode 100644
index 00000000000..8390c0816a4
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/fixture/FixtureRule.java
@@ -0,0 +1,28 @@
+/*
+ * 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.rewrite.fixture;
+
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+
+public final class FixtureRule implements ShardingSphereRule {
+    
+    @Override
+    public String getType() {
+        return FixtureRule.class.getSimpleName();
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/fixture/FixtureSQLRewriteContextDecorator.java b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/fixture/FixtureSQLRewriteContextDecorator.java
new file mode 100644
index 00000000000..6bbfab53c23
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/java/org/apache/shardingsphere/infra/rewrite/fixture/FixtureSQLRewriteContextDecorator.java
@@ -0,0 +1,41 @@
+/*
+ * 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.rewrite.fixture;
+
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContext;
+import org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator;
+import org.apache.shardingsphere.infra.route.context.RouteContext;
+
+public final class FixtureSQLRewriteContextDecorator implements SQLRewriteContextDecorator<FixtureRule> {
+    
+    @Override
+    public void decorate(final FixtureRule rule, final ConfigurationProperties props, final SQLRewriteContext sqlRewriteContext,
+                         final RouteContext routeContext) {
+    }
+    
+    @Override
+    public int getOrder() {
+        return 0;
+    }
+    
+    @Override
+    public Class<FixtureRule> getTypeClass() {
+        return FixtureRule.class;
+    }
+}
diff --git a/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator
new file mode 100644
index 00000000000..825a1dcb094
--- /dev/null
+++ b/shardingsphere-infra/shardingsphere-infra-rewrite/src/test/resources/META-INF/services/org.apache.shardingsphere.infra.rewrite.context.SQLRewriteContextDecorator
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+org.apache.shardingsphere.infra.rewrite.fixture.FixtureSQLRewriteContextDecorator