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/08/17 11:38:13 UTC

[shardingsphere] branch master updated: Add test cases for InlineShardingAlgorithm's range sharding (#6896)

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 bf91fe7  Add test cases for InlineShardingAlgorithm's range sharding (#6896)
bf91fe7 is described below

commit bf91fe795e35e705034a82dc2e88af744fa9f7ba
Author: Andrew <zh...@aliyun.com>
AuthorDate: Mon Aug 17 19:37:59 2020 +0800

    Add test cases for InlineShardingAlgorithm's range sharding (#6896)
---
 .../sharding/inline/InlineShardingAlgorithmTest.java        | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
index 7fa388a..b377f2e 100644
--- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
+++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
@@ -18,9 +18,11 @@
 package org.apache.shardingsphere.sharding.algorithm.sharding.inline;
 
 import com.google.common.collect.Lists;
+import com.google.common.collect.Range;
 import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
 import org.apache.shardingsphere.sharding.strategy.standard.StandardShardingStrategy;
 import org.apache.shardingsphere.sharding.strategy.value.ListRouteValue;
+import org.apache.shardingsphere.sharding.strategy.value.RangeRouteValue;
 import org.apache.shardingsphere.sharding.strategy.value.RouteValue;
 import org.junit.Before;
 import org.junit.Test;
@@ -31,6 +33,8 @@ import java.util.Properties;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
 
 public final class InlineShardingAlgorithmTest {
 
@@ -47,6 +51,7 @@ public final class InlineShardingAlgorithmTest {
     private StandardShardingStrategy createShardingStrategy() {
         InlineShardingAlgorithm shardingAlgorithm = new InlineShardingAlgorithm();
         shardingAlgorithm.getProps().setProperty("algorithm.expression", "t_order_$->{order_id % 4}");
+        shardingAlgorithm.getProps().setProperty("allow.range.query.with.inline.sharding", "true");
         shardingAlgorithm.init();
         return new StandardShardingStrategy("order_id", shardingAlgorithm);
     }
@@ -69,6 +74,14 @@ public final class InlineShardingAlgorithmTest {
     }
     
     @Test
+    public void assertDoShardingWithRangeRouteValue() {
+        List<String> availableTargetNames = Lists.newArrayList("t_order_0", "t_order_1", "t_order_2", "t_order_3");
+        List<RouteValue> shardingValues = Lists.newArrayList(new RangeRouteValue<>("order_id", "t_order", mock(Range.class)));
+        Collection<String> actual = shardingStrategy.doSharding(availableTargetNames, shardingValues, new ConfigurationProperties(new Properties()));
+        assertTrue(actual.containsAll(availableTargetNames));
+    }
+    
+    @Test
     public void assertDoShardingWithNonExistNodes() {
         List<String> availableTargetNames = Lists.newArrayList("t_order_0", "t_order_1");
         List<RouteValue> shardingValues = Lists.newArrayList(new ListRouteValue<>("order_id", "t_order", Lists.newArrayList(0, 1, 2, 3)));