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 2020/10/11 02:51:18 UTC

[shardingsphere] branch master updated: Add test cases for HintShardingStrategy and NoneShardingStrategy (#7734)

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 c0799fc  Add test cases for HintShardingStrategy and NoneShardingStrategy (#7734)
c0799fc is described below

commit c0799fcfc472473587a8eaa4813a1e5d3366ffb8
Author: Serendipity <ja...@163.com>
AuthorDate: Sun Oct 11 10:50:54 2020 +0800

    Add test cases for HintShardingStrategy and NoneShardingStrategy (#7734)
---
 .../type/hint/HintShardingStrategyTest.java        | 43 ++++++++++++++++++
 .../type/none/NoneShardingStrategyTest.java        | 53 ++++++++++++++++++++++
 2 files changed, 96 insertions(+)

diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/strategy/type/hint/HintShardingStrategyTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/strategy/type/hint/HintShardingStrategyTest.java
new file mode 100644
index 0000000..708077e
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/strategy/type/hint/HintShardingStrategyTest.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.sharding.route.strategy.type.hint;
+
+import com.google.common.collect.Sets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.sharding.route.engine.condition.value.ListShardingConditionValue;
+import org.apache.shardingsphere.sharding.route.strategy.fixture.HintShardingAlgorithmFixture;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class HintShardingStrategyTest {
+    
+    @Test
+    public void assertDoSharding() {
+        Collection<String> targets = Sets.newHashSet("1", "2", "3");
+        HintShardingStrategy hintShardingStrategy = new HintShardingStrategy(new HintShardingAlgorithmFixture());
+        Collection<String> actualSharding = hintShardingStrategy
+            .doSharding(targets, Collections.singletonList(new ListShardingConditionValue<>("column", "logicTable", Collections.singletonList(1))), new ConfigurationProperties(new Properties()));
+        assertThat(actualSharding.size(), is(1));
+        assertThat(actualSharding.iterator().next(), is("1"));
+    }
+}
diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/strategy/type/none/NoneShardingStrategyTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/strategy/type/none/NoneShardingStrategyTest.java
new file mode 100644
index 0000000..70ea933
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-route/src/test/java/org/apache/shardingsphere/sharding/route/strategy/type/none/NoneShardingStrategyTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.sharding.route.strategy.type.none;
+
+import com.google.common.collect.Sets;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+public final class NoneShardingStrategyTest {
+    
+    private NoneShardingStrategy noneShardingStrategy;
+    
+    @Before
+    public void setUp() {
+        noneShardingStrategy = new NoneShardingStrategy();
+    }
+    
+    @Test
+    public void assertGetShardingAlgorithm() {
+        Collection<String> targets = Sets.newHashSet("1", "2", "3");
+        Collection<String> actualSharding = noneShardingStrategy.doSharding(targets, Collections.emptySet(), new ConfigurationProperties(new Properties()));
+        assertThat(actualSharding.size(), is(3));
+        assertThat(actualSharding, is(targets));
+    }
+    
+    @Test
+    public void assertDoSharding() {
+        assertNull(noneShardingStrategy.getShardingAlgorithm());
+    }
+}