Hisoka-X commented on code in PR #4772:
URL: https://github.com/apache/seatunnel/pull/4772#discussion_r1226294038
##########
seatunnel-connectors-v2/connector-clickhouse/src/test/java/org/apache/seatunnel/connectors/seatunnel/clickhouse/ClickhouseFactoryTest.java:
##########
@@ -24,12 +24,43 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import net.jpountz.xxhash.XXHash64;
+import net.jpountz.xxhash.XXHashFactory;
+
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
public class ClickhouseFactoryTest {
+ private static final XXHash64 HASH_INSTANCE =
XXHashFactory.fastestInstance().hash64();
@Test
public void testOptionRule() {
Assertions.assertNotNull((new ClickhouseSourceFactory()).optionRule());
Assertions.assertNotNull((new ClickhouseSinkFactory()).optionRule());
Assertions.assertNotNull((new
ClickhouseFileSinkFactory()).optionRule());
}
+
+ public int getShard(Object shardValue) {
+ int shardWeightCount = 6;
+ int offset =
+ (int)
+ ((HASH_INSTANCE.hash(
+ ByteBuffer.wrap(
+ shardValue
+ .toString()
+
.getBytes(StandardCharsets.UTF_8)),
+ 0)
+ & Long.MAX_VALUE)
+ % shardWeightCount);
+ return offset;
+ }
+
+ @Test
+ public void testShared() {
+ String a = "a,b,c,d,e,f";
+ for (Object o : Arrays.stream(a.split(",")).toArray()) {
+ System.out.println(getShard(o));
Review Comment:
Please use `Assertions` to make sure to result are right. Also please
provide the test case to make sure to all shard can be selected. Tips: maybe we
can use 10000 keys with random string to invoke `getShard` then get each shard
index count which return by `getShard`. I believe when the number of keys more
large, the shard index will be more balanced.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]