You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/09/14 05:09:18 UTC

[GitHub] [shardingsphere] LeeGuoPing opened a new pull request #12417: Add unit test for shardingsphere-shadow-core

LeeGuoPing opened a new pull request #12417:
URL: https://github.com/apache/shardingsphere/pull/12417


   Fixes #12344.
   
   Changes proposed in this pull request:
   -
   -
   -
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] menghaoranss merged pull request #12417: Add unit test for shardingsphere-shadow-core

Posted by GitBox <gi...@apache.org>.
menghaoranss merged pull request #12417:
URL: https://github.com/apache/shardingsphere/pull/12417


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] LeeGuoPing commented on a change in pull request #12417: Add unit test for shardingsphere-shadow-core

Posted by GitBox <gi...@apache.org>.
LeeGuoPing commented on a change in pull request #12417:
URL: https://github.com/apache/shardingsphere/pull/12417#discussion_r708844451



##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/NoteShadowAlgorithmDeterminerTest.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.shadow.route.future.engine.determiner.algorithm;
+
+import org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.algorithm.shadow.note.SimpleSQLNoteShadowAlgorithm;
+import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
+import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowAlgorithmDeterminer;
+import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.rule.ShadowRule;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class NoteShadowAlgorithmDeterminerTest {
+
+    private ShadowAlgorithmDeterminer shadowAlgorithmDeterminer;
+
+    @Before
+    public void init() {
+        shadowAlgorithmDeterminer = new NoteShadowAlgorithmDeterminer(createNoteShadowAlgorithm());
+    }
+
+    private NoteShadowAlgorithm createNoteShadowAlgorithm() {
+        NoteShadowAlgorithm<String> noteShadowAlgorithm = new SimpleSQLNoteShadowAlgorithm();
+        noteShadowAlgorithm.setProps(createProps());
+        noteShadowAlgorithm.init();
+        return noteShadowAlgorithm;
+    }
+
+    private Properties createProps() {
+        Properties properties = new Properties();
+        properties.setProperty("shadow", "true");
+        properties.setProperty("user_id", "1");
+        return properties;
+    }
+
+    @Test
+    public void assertIsShadow() {
+        assertThat(shadowAlgorithmDeterminer.isShadow(createShadowDetermineCondition(), new ShadowRule(createAlgorithmProvidedShadowRuleConfiguration()), "t_order"), is(true));
+    }
+
+    private AlgorithmProvidedShadowRuleConfiguration createAlgorithmProvidedShadowRuleConfiguration() {
+        AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration("shadow", Arrays.asList("ds", "ds1"), Arrays.asList("shadow_ds", "shadow_ds1"));
+        result.setEnable(true);
+        result.setDataSources(createDataSources());
+        result.setTables(createTables());
+        result.setShadowAlgorithms(createShadowAlgorithms());
+        return result;
+    }
+
+    private Map<String, ShadowAlgorithm> createShadowAlgorithms() {
+        Map<String, ShadowAlgorithm> result = new LinkedHashMap<>();
+        result.put("user_id-insert-regex-algorithm", createNoteShadowAlgorithm());
+        return result;
+    }
+
+    private Map<String, ShadowTableConfiguration> createTables() {
+        Map<String, ShadowTableConfiguration> result = new LinkedHashMap<>();
+        result.put("t_order", new ShadowTableConfiguration(createShadowAlgorithmNames()));
+        return result;
+    }
+
+    private Collection<String> createShadowAlgorithmNames() {
+        Collection<String> result = new LinkedList<>();
+        result.add("user_id-insert-regex-algorithm");
+        return result;
+    }
+
+    private Map<String, ShadowDataSourceConfiguration> createDataSources() {
+        Map<String, ShadowDataSourceConfiguration> result = new LinkedHashMap<>();
+        result.put("ds-data-source", new ShadowDataSourceConfiguration("ds", "ds_shadow"));
+        result.put("ds1-data-source", new ShadowDataSourceConfiguration("ds1", "ds1_shadow"));
+        return result;
+    }
+
+    private ShadowDetermineCondition createShadowDetermineCondition() {
+        ShadowDetermineCondition shadowDetermineCondition = new ShadowDetermineCondition(ShadowOperationType.INSERT);
+        shadowDetermineCondition.initSqlNotes(createSqlNotes());
+        return shadowDetermineCondition;
+    }
+
+    private Collection<String> createSqlNotes() {
+        Collection<String> result = new LinkedList<>();
+        result.add("/*user_id=1,shadow=true*/");
+        return result;
+    }
+

Review comment:
       > @LeeGuoPing Thank you for your contribution, please delete the extra blank lines.
   
   @soulasuna I have deleted it just now.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] soulasuna commented on a change in pull request #12417: Add unit test for shardingsphere-shadow-core

Posted by GitBox <gi...@apache.org>.
soulasuna commented on a change in pull request #12417:
URL: https://github.com/apache/shardingsphere/pull/12417#discussion_r708809185



##########
File path: shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/test/java/org/apache/shardingsphere/shadow/route/future/engine/determiner/algorithm/NoteShadowAlgorithmDeterminerTest.java
##########
@@ -0,0 +1,117 @@
+/*
+ * 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.shadow.route.future.engine.determiner.algorithm;
+
+import org.apache.shardingsphere.shadow.algorithm.config.AlgorithmProvidedShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.algorithm.shadow.note.SimpleSQLNoteShadowAlgorithm;
+import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.api.shadow.column.ShadowOperationType;
+import org.apache.shardingsphere.shadow.api.shadow.note.NoteShadowAlgorithm;
+import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowAlgorithmDeterminer;
+import org.apache.shardingsphere.shadow.route.future.engine.determiner.ShadowDetermineCondition;
+import org.apache.shardingsphere.shadow.rule.ShadowRule;
+import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class NoteShadowAlgorithmDeterminerTest {
+
+    private ShadowAlgorithmDeterminer shadowAlgorithmDeterminer;
+
+    @Before
+    public void init() {
+        shadowAlgorithmDeterminer = new NoteShadowAlgorithmDeterminer(createNoteShadowAlgorithm());
+    }
+
+    private NoteShadowAlgorithm createNoteShadowAlgorithm() {
+        NoteShadowAlgorithm<String> noteShadowAlgorithm = new SimpleSQLNoteShadowAlgorithm();
+        noteShadowAlgorithm.setProps(createProps());
+        noteShadowAlgorithm.init();
+        return noteShadowAlgorithm;
+    }
+
+    private Properties createProps() {
+        Properties properties = new Properties();
+        properties.setProperty("shadow", "true");
+        properties.setProperty("user_id", "1");
+        return properties;
+    }
+
+    @Test
+    public void assertIsShadow() {
+        assertThat(shadowAlgorithmDeterminer.isShadow(createShadowDetermineCondition(), new ShadowRule(createAlgorithmProvidedShadowRuleConfiguration()), "t_order"), is(true));
+    }
+
+    private AlgorithmProvidedShadowRuleConfiguration createAlgorithmProvidedShadowRuleConfiguration() {
+        AlgorithmProvidedShadowRuleConfiguration result = new AlgorithmProvidedShadowRuleConfiguration("shadow", Arrays.asList("ds", "ds1"), Arrays.asList("shadow_ds", "shadow_ds1"));
+        result.setEnable(true);
+        result.setDataSources(createDataSources());
+        result.setTables(createTables());
+        result.setShadowAlgorithms(createShadowAlgorithms());
+        return result;
+    }
+
+    private Map<String, ShadowAlgorithm> createShadowAlgorithms() {
+        Map<String, ShadowAlgorithm> result = new LinkedHashMap<>();
+        result.put("user_id-insert-regex-algorithm", createNoteShadowAlgorithm());
+        return result;
+    }
+
+    private Map<String, ShadowTableConfiguration> createTables() {
+        Map<String, ShadowTableConfiguration> result = new LinkedHashMap<>();
+        result.put("t_order", new ShadowTableConfiguration(createShadowAlgorithmNames()));
+        return result;
+    }
+
+    private Collection<String> createShadowAlgorithmNames() {
+        Collection<String> result = new LinkedList<>();
+        result.add("user_id-insert-regex-algorithm");
+        return result;
+    }
+
+    private Map<String, ShadowDataSourceConfiguration> createDataSources() {
+        Map<String, ShadowDataSourceConfiguration> result = new LinkedHashMap<>();
+        result.put("ds-data-source", new ShadowDataSourceConfiguration("ds", "ds_shadow"));
+        result.put("ds1-data-source", new ShadowDataSourceConfiguration("ds1", "ds1_shadow"));
+        return result;
+    }
+
+    private ShadowDetermineCondition createShadowDetermineCondition() {
+        ShadowDetermineCondition shadowDetermineCondition = new ShadowDetermineCondition(ShadowOperationType.INSERT);
+        shadowDetermineCondition.initSqlNotes(createSqlNotes());
+        return shadowDetermineCondition;
+    }
+
+    private Collection<String> createSqlNotes() {
+        Collection<String> result = new LinkedList<>();
+        result.add("/*user_id=1,shadow=true*/");
+        return result;
+    }
+

Review comment:
       @LeeGuoPing Thank you for your contribution, please delete the extra blank lines.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org