Skip to content

Commit

Permalink
test(common): add shard bit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomThief committed Jun 12, 2020
1 parent 2642947 commit 8efa710
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.github.phantomthief.jedis;

import static java.util.stream.Collectors.toSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -65,6 +68,23 @@ void test() {
assertEquals(booleanCount, helper.getShardBitCount("test", keyHashRange, 0, 10));
Map<Long, String> test1 = JedisHelper.getShardBitKeys(keys, "test", keyHashRange);
assertEquals(keys.stream().distinct().count(), test1.size());

Stream<Long> stream = helper.iterateShardBit("test", keyHashRange, 0, 10);
Set<Long> collect = stream.collect(toSet());
for (long i = 0; i < 10; i++) {
if (i % 3 == 0) {
assertTrue(collect.contains(i));
} else {
assertFalse(collect.contains(i));
}
}
helper.delShardBit("test", keyHashRange, 0, 10);

stream = helper.iterateShardBit("test", keyHashRange, 0, 10);
collect = stream.collect(toSet());
for (long i = 0; i < 10; i++) {
assertFalse(collect.contains(i));
}
}
}
}

0 comments on commit 8efa710

Please sign in to comment.