You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/10/20 09:50:56 UTC

[shardingsphere] branch master updated: [ISSUE #21569] Add Tests for ShardingAutoTableAlgorithmUtil Class (#21603)

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

duanzhengqiang 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 8848cfa0636 [ISSUE #21569] Add Tests for ShardingAutoTableAlgorithmUtil Class (#21603)
8848cfa0636 is described below

commit 8848cfa063628daaccb1e43c9f00b476eda40267
Author: Karthick Balathandayuthapani <78...@users.noreply.github.com>
AuthorDate: Thu Oct 20 15:20:50 2022 +0530

    [ISSUE #21569] Add Tests for ShardingAutoTableAlgorithmUtil Class (#21603)
    
    * [ISSUE #21569] Add Tests for ShardingAutoTableAlgorithmUtil Class
    
    * [ISSUE #21569] Fix checkstyle errors
    
    * [ISSUE #21569] Change the ShardingAutoTableAlgorithmUtilTest class as final
    
    * [ISSUE #21569] remove empty spaces and final modifier for method variables
    
    * [ISSUE #21569] Change assertEquals to assertThat in tests
    
    Co-authored-by: Karthick B <ka...@tesco.com>
---
 .../ShardingAutoTableAlgorithmUtilTest.java        | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/ShardingAutoTableAlgorithmUtilTest.java b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/ShardingAutoTableAlgorithmUtilTest.java
new file mode 100644
index 00000000000..272be69b13b
--- /dev/null
+++ b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/ShardingAutoTableAlgorithmUtilTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.algorithm.sharding;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Optional;
+import org.apache.shardingsphere.infra.datanode.DataNodeInfo;
+import org.junit.Before;
+import org.junit.Test;
+
+public final class ShardingAutoTableAlgorithmUtilTest {
+    
+    private Collection<String> collection;
+    
+    private DataNodeInfo dataNodeInfo;
+    
+    @Before
+    public void setup() {
+        collection = new ArrayList<>();
+        collection.add("PREFIX----SUFFIX");
+        collection.add("PREFIXSUFFIXSTRING");
+        collection.add("PREFIX----------");
+        String prefix = "PREFIX";
+        int suffixMinLength = 10;
+        char paddingChar = '-';
+        dataNodeInfo = new DataNodeInfo(prefix, suffixMinLength, paddingChar);
+    }
+    
+    @Test
+    public void assertFindMatchedTargetNameForValidInputs() {
+        Optional<String> output = ShardingAutoTableAlgorithmUtil.findMatchedTargetName(collection, "SUFFIX", dataNodeInfo);
+        assertTrue(output.isPresent());
+        assertThat("PREFIX----SUFFIX", is(output.get()));
+        Optional<String> output1 = ShardingAutoTableAlgorithmUtil.findMatchedTargetName(collection, "SUFFIXSTRING", dataNodeInfo);
+        assertTrue(output1.isPresent());
+        assertThat("PREFIXSUFFIXSTRING", is(output1.get()));
+        Optional<String> output2 = ShardingAutoTableAlgorithmUtil.findMatchedTargetName(collection, "", dataNodeInfo);
+        assertTrue(output2.isPresent());
+        assertThat("PREFIX----------", is(output2.get()));
+    }
+    
+    @Test
+    public void assertFindMatchedTargetNameNonExistingInput() {
+        Optional<String> output = ShardingAutoTableAlgorithmUtil.findMatchedTargetName(collection, "NONEXISTINGSUFFIX", dataNodeInfo);
+        assertFalse(output.isPresent());
+    }
+}