diff --git a/commons/src/test/java/io/github/dengliming/redismodule/common/ArgsUtilTest.java b/commons/src/test/java/io/github/dengliming/redismodule/common/ArgsUtilTest.java new file mode 100644 index 0000000..626e747 --- /dev/null +++ b/commons/src/test/java/io/github/dengliming/redismodule/common/ArgsUtilTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 dengliming. + * + * Licensed 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 io.github.dengliming.redismodule.common; + +import io.github.dengliming.redismodule.common.util.ArgsUtil; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ArgsUtilTest { + + @Test + public void testAppend() { + assertThat(ArgsUtil.append("key1", "a", "b", "c")).containsExactly("key1", "a", "b", "c"); + Map params = new HashMap<>(); + params.put("k1", "v1"); + params.put("k2", "v2"); + Object[] result = ArgsUtil.append("key2", params); + assertThat(result).hasSize(5); + assertThat(result).contains("key2"); + assertThat(result).contains("k1", "v1"); + assertThat(result).contains("k2", "v2"); + } +} diff --git a/commons/src/test/java/io/github/dengliming/redismodule/common/RAssertTest.java b/commons/src/test/java/io/github/dengliming/redismodule/common/RAssertTest.java new file mode 100644 index 0000000..4dfa896 --- /dev/null +++ b/commons/src/test/java/io/github/dengliming/redismodule/common/RAssertTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2022 dengliming. + * + * Licensed 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 io.github.dengliming.redismodule.common; + +import io.github.dengliming.redismodule.common.util.RAssert; +import org.junit.jupiter.api.Test; + +import java.util.HashMap; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class RAssertTest { + + @Test + public void test() { + assertThrows(IllegalArgumentException.class, () -> RAssert.notNull(null, "test not null"), + "test not null"); + + assertThrows(IllegalArgumentException.class, () -> RAssert.notEmpty((CharSequence) null, "test CharSequence not empty"), + "test CharSequence not empty"); + + assertThrows(IllegalArgumentException.class, () -> RAssert.notEmpty(new Object[]{}, "test Object[] not empty"), + "test Object[] not empty"); + + assertThrows(IllegalArgumentException.class, () -> RAssert.notEmpty(new int[]{}, "test int[] not empty"), + "test int[] not empty"); + + assertThrows(IllegalArgumentException.class, () -> RAssert.notEmpty(new double[]{}, "test double[] not empty"), + "test double[] not empty"); + + assertThrows(IllegalArgumentException.class, () -> RAssert.isTrue(false, "test boolean is false"), + "test boolean is false"); + + assertThrows(IllegalArgumentException.class, () -> RAssert.notEmpty(new HashMap<>(), "test HashMap not empty"), + "test HashMap not empty"); + } +} diff --git a/commons/src/test/java/io/github/dengliming/redismodule/common/TestSettingsTest.java b/commons/src/test/java/io/github/dengliming/redismodule/common/TestSettingsTest.java new file mode 100644 index 0000000..85943d2 --- /dev/null +++ b/commons/src/test/java/io/github/dengliming/redismodule/common/TestSettingsTest.java @@ -0,0 +1,30 @@ +/* + * Copyright 2022 dengliming. + * + * Licensed 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 io.github.dengliming.redismodule.common; + +import io.github.dengliming.redismodule.common.util.TestSettings; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TestSettingsTest { + + @Test + public void test() { + assertThat(TestSettings.password()).isEmpty(); + } +} diff --git a/redisai/src/main/java/io/github/dengliming/redismodule/redisai/args/StoreScriptArgs.java b/redisai/src/main/java/io/github/dengliming/redismodule/redisai/args/StoreScriptArgs.java index 1ccc094..29aadc0 100644 --- a/redisai/src/main/java/io/github/dengliming/redismodule/redisai/args/StoreScriptArgs.java +++ b/redisai/src/main/java/io/github/dengliming/redismodule/redisai/args/StoreScriptArgs.java @@ -79,9 +79,7 @@ public void build(List args) { if (entryPoints != null && !entryPoints.isEmpty()) { args.add(Keywords.ENTRY_POINTS); args.add(entryPoints.size()); - for (String entryPoint : entryPoints) { - args.add(entryPoint); - } + args.addAll(entryPoints); } if (script != null) { diff --git a/redisai/src/test/java/io/github/dengliming/redismodule/redisai/RedisAITest.java b/redisai/src/test/java/io/github/dengliming/redismodule/redisai/RedisAITest.java index 1ac2d49..473affd 100644 --- a/redisai/src/test/java/io/github/dengliming/redismodule/redisai/RedisAITest.java +++ b/redisai/src/test/java/io/github/dengliming/redismodule/redisai/RedisAITest.java @@ -17,6 +17,7 @@ package io.github.dengliming.redismodule.redisai; import io.github.dengliming.redismodule.redisai.args.SetModelArgs; +import io.github.dengliming.redismodule.redisai.args.StoreScriptArgs; import io.github.dengliming.redismodule.redisai.model.Model; import io.github.dengliming.redismodule.redisai.model.Script; import io.github.dengliming.redismodule.redisai.model.Tensor; @@ -27,12 +28,13 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; +import java.util.Collections; import java.util.Map; +import java.util.Objects; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; - /** * @author dengliming */ @@ -56,9 +58,17 @@ public void testTensor() { public void testModel() throws Exception { RedisAI redisAI = getRedisAI(); // Set Model - byte[] blob = Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("test_data/graph.pb").toURI())); - assertThat(redisAI.setModel("model1", new SetModelArgs().backEnd(Backend.TF).device(Device.CPU) - .inputs(Arrays.asList("a", "b")).outputs(Arrays.asList("mul")).blob(blob))).isTrue(); + byte[] blob = Files.readAllBytes(Paths.get(Objects.requireNonNull(getClass().getClassLoader().getResource( + "test_data/graph.pb")).toURI())); + assertThat(redisAI.setModel("model1", new SetModelArgs() + .backEnd(Backend.TF) + .device(Device.CPU) + .inputs(Arrays.asList("a", "b")) + .tag("model1:1.0") + .batchSize(1024) + .minBatchSize(256) + .outputs(Collections.singletonList("mul")) + .blob(blob))).isTrue(); // Get Model Model model = redisAI.getModel("model1"); @@ -67,6 +77,12 @@ public void testModel() throws Exception { assertThat(model.getInputs()).containsExactly("a", "b"); assertThat(model.getOutputs()).containsExactly("mul"); assertThat(model.getBlob()).isEqualTo(blob); + assertThat(model.getBatchSize()).isEqualTo(1024); + assertThat(model.getMinBatchSize()).isEqualTo(256); + assertThat(model.getTag()).isEqualTo("model1:1.0"); + + // Delete Model + assertThat(redisAI.deleteModel("model1")).isTrue(); } @Test @@ -83,6 +99,8 @@ public void testScript() { assertThat(scriptInfo).isNotNull(); assertThat(scriptInfo.getDevice()).isEqualTo(Device.CPU); assertThat(scriptInfo.getSource()).isEqualTo(script); + + assertThat(redisAI.deleteScript(key)).isTrue(); } @Test @@ -136,4 +154,22 @@ public void testInfo() { redisAI.resetStat("not:exist"); }); } + + @Test + public void testStoreScript() { + RedisAI redisAI = getRedisAI(); + + String key = "myscript"; + String script = "def addtwo(tensors: List[Tensor], keys: List[str], args: List[str]):\n" + + " a = tensors[0]\n" + + " b = tensors[1]\n" + + " return a + b\n"; + assertThat(redisAI.storeScript(key, new StoreScriptArgs() + .script(script) + .device(Device.CPU) + .tag("myscript:v0.1") + .entryPoints(Collections.singletonList("addtwo")))).isTrue(); + + assertThat(redisAI.deleteScript(key)).isTrue(); + } } diff --git a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/CountMinSketch.java b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/CountMinSketch.java index 8e82508..ccdf4f2 100644 --- a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/CountMinSketch.java +++ b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/CountMinSketch.java @@ -123,21 +123,20 @@ public RFuture> queryAsync(String... items) { /** * Merges several sketches into one sketch. * - * @param keyNum Number of sketches to be merged * @param srcs Names of source sketches to be merged * @param weights Multiple of each sketch. Default =1 * @return True if executed correctly, or False reply otherwise */ - public boolean merge(int keyNum, String[] srcs, Integer[] weights) { + public boolean merge(String[] srcs, int[] weights) { RAssert.notEmpty(srcs, "Srcs must not be empty"); - return get(mergeAsync(keyNum, srcs, weights)); + return get(mergeAsync(srcs, weights)); } - public RFuture mergeAsync(int keyNum, String[] srcs, Integer[] weights) { + public RFuture mergeAsync(String[] srcs, int[] weights) { List params = new ArrayList<>(); params.add(getName()); - params.add(keyNum); + params.add(srcs.length); Collections.addAll(params, srcs); if (weights.length > 0) { params.add(Keywords.WEIGHTS); diff --git a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/BloomFilterInfo.java b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/BloomFilterInfo.java index 91f2634..d4e0587 100644 --- a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/BloomFilterInfo.java +++ b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/BloomFilterInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 dengliming. + * Copyright 2020-2022 dengliming. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,11 @@ * @author dengliming */ public class BloomFilterInfo { - private Integer capacity; - private Integer size; - private Integer filterNum; - private Integer insertedNum; - private Integer expansionRate; + private final Integer capacity; + private final Integer size; + private final Integer filterNum; + private final Integer insertedNum; + private final Integer expansionRate; public BloomFilterInfo(Integer capacity, Integer size, Integer filterNum, Integer insertedNum, Integer expansionRate) { this.capacity = capacity; @@ -38,39 +38,19 @@ public Integer getCapacity() { return capacity; } - public void setCapacity(Integer capacity) { - this.capacity = capacity; - } - public Integer getSize() { return size; } - public void setSize(Integer size) { - this.size = size; - } - public Integer getFilterNum() { return filterNum; } - public void setFilterNum(Integer filterNum) { - this.filterNum = filterNum; - } - public Integer getInsertedNum() { return insertedNum; } - public void setInsertedNum(Integer insertedNum) { - this.insertedNum = insertedNum; - } - public Integer getExpansionRate() { return expansionRate; } - - public void setExpansionRate(Integer expansionRate) { - this.expansionRate = expansionRate; - } } diff --git a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/CountMinSketchInfo.java b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/CountMinSketchInfo.java index 9430d99..96d8e2b 100644 --- a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/CountMinSketchInfo.java +++ b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/CountMinSketchInfo.java @@ -20,9 +20,9 @@ * @author dengliming */ public class CountMinSketchInfo { - private Integer width; - private Integer depth; - private Integer count; + private final Integer width; + private final Integer depth; + private final Integer count; public CountMinSketchInfo(Integer width, Integer depth, Integer count) { this.width = width; @@ -34,23 +34,11 @@ public Integer getWidth() { return width; } - public void setWidth(Integer width) { - this.width = width; - } - public Integer getDepth() { return depth; } - public void setDepth(Integer depth) { - this.depth = depth; - } - public Integer getCount() { return count; } - - public void setCount(Integer count) { - this.count = count; - } } diff --git a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/CuckooFilterInfo.java b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/CuckooFilterInfo.java index bc7c65d..4ce569e 100644 --- a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/CuckooFilterInfo.java +++ b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/CuckooFilterInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 dengliming. + * Copyright 2020-2022 dengliming. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,14 @@ * @author dengliming */ public class CuckooFilterInfo { - private Integer size; - private Integer bucketNum; - private Integer filterNum; - private Integer insertedNum; - private Integer deletedNum; - private Integer bucketSize; - private Integer expansionRate; - private Integer maxIteration; + private final Integer size; + private final Integer bucketNum; + private final Integer filterNum; + private final Integer insertedNum; + private final Integer deletedNum; + private final Integer bucketSize; + private final Integer expansionRate; + private final Integer maxIteration; public CuckooFilterInfo(Integer size, Integer bucketNum, Integer filterNum, Integer insertedNum, Integer deletedNum, Integer bucketSize, Integer expansionRate, Integer maxIteration) { @@ -45,63 +45,31 @@ public Integer getSize() { return size; } - public void setSize(Integer size) { - this.size = size; - } - public Integer getBucketNum() { return bucketNum; } - public void setBucketNum(Integer bucketNum) { - this.bucketNum = bucketNum; - } - public Integer getFilterNum() { return filterNum; } - public void setFilterNum(Integer filterNum) { - this.filterNum = filterNum; - } - public Integer getInsertedNum() { return insertedNum; } - public void setInsertedNum(Integer insertedNum) { - this.insertedNum = insertedNum; - } - public Integer getDeletedNum() { return deletedNum; } - public void setDeletedNum(Integer deletedNum) { - this.deletedNum = deletedNum; - } - public Integer getBucketSize() { return bucketSize; } - public void setBucketSize(Integer bucketSize) { - this.bucketSize = bucketSize; - } - public Integer getExpansionRate() { return expansionRate; } - public void setExpansionRate(Integer expansionRate) { - this.expansionRate = expansionRate; - } - public Integer getMaxIteration() { return maxIteration; } - - public void setMaxIteration(Integer maxIteration) { - this.maxIteration = maxIteration; - } } diff --git a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/InsertArgs.java b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/InsertArgs.java index b12972e..fef5178 100644 --- a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/InsertArgs.java +++ b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/InsertArgs.java @@ -46,12 +46,11 @@ public class InsertArgs { private boolean nonScaling; public InsertArgs() { + this(-1, 0, 0, false, false); } public InsertArgs(int capacity, double errorRatio, int expansion) { - this.capacity = capacity; - this.errorRatio = errorRatio; - this.expansion = expansion; + this(capacity, errorRatio, expansion, false, false); } public InsertArgs(int capacity, double errorRatio, int expansion, boolean noCreate, boolean nonScaling) { diff --git a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/TopKFilterInfo.java b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/TopKFilterInfo.java index 163af68..fee2ceb 100644 --- a/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/TopKFilterInfo.java +++ b/redisbloom/src/main/java/io/github/dengliming/redismodule/redisbloom/model/TopKFilterInfo.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 dengliming. + * Copyright 2020-2022 dengliming. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,10 @@ * @author dengliming */ public class TopKFilterInfo { - private Integer topK; - private Integer width; - private Integer depth; - private Double decay; + private final Integer topK; + private final Integer width; + private final Integer depth; + private final Double decay; public TopKFilterInfo(Integer topK, Integer width, Integer depth, Double decay) { this.topK = topK; @@ -36,31 +36,15 @@ public Integer getTopK() { return topK; } - public void setTopK(Integer topK) { - this.topK = topK; - } - public Integer getWidth() { return width; } - public void setWidth(Integer width) { - this.width = width; - } - public Integer getDepth() { return depth; } - public void setDepth(Integer depth) { - this.depth = depth; - } - public Double getDecay() { return decay; } - - public void setDecay(Double decay) { - this.decay = decay; - } } diff --git a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/BloomFilterTest.java b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/BloomFilterTest.java index 47a7f71..f43928b 100644 --- a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/BloomFilterTest.java +++ b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/BloomFilterTest.java @@ -61,6 +61,10 @@ public void testInfo() { assertThat(bloomFilter.create(0.1d, 100)).isTrue(); BloomFilterInfo bloomFilterInfo = bloomFilter.getInfo(); assertThat(bloomFilterInfo.getCapacity().intValue()).isEqualTo(100); + assertThat(bloomFilterInfo.getFilterNum().intValue()).isEqualTo(1); + assertThat(bloomFilterInfo.getExpansionRate().intValue()).isEqualTo(2); + assertThat(bloomFilterInfo.getInsertedNum().intValue()).isEqualTo(0); + assertThat(bloomFilterInfo.getSize().intValue()).isGreaterThan(0); } @Test diff --git a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/CountMinSketchTest.java b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/CountMinSketchTest.java index 16e012d..7d60baa 100644 --- a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/CountMinSketchTest.java +++ b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/CountMinSketchTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 dengliming. + * Copyright 2020-2022 dengliming. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,26 @@ public void testInfo() { assertThat(countMinSketch.create(5, 10)).isTrue(); CountMinSketchInfo countMinSketchInfo = countMinSketch.getInfo(); assertThat(countMinSketchInfo.getWidth()).isEqualTo(5); + assertThat(countMinSketchInfo.getDepth()).isEqualTo(10); + assertThat(countMinSketchInfo.getCount()).isEqualTo(0); } + @Test + public void testMerge() { + CountMinSketch a = getRedisBloomClient().getCountMinSketch("cms_a"); + CountMinSketch b = getRedisBloomClient().getCountMinSketch("cms_b"); + CountMinSketch c = getRedisBloomClient().getCountMinSketch("cms_c"); + c.create(1000, 5); + a.create(1000, 5); + b.create(1000, 5); + a.incrby(new String[]{"foo", "bar"}, new int[]{5, 3}); + b.incrby(new String[]{"foo", "bar"}, new int[]{2, 4}); + c.incrby(new String[]{"foo", "bar"}, new int[]{3, 6}); + assertThat(a.query("foo", "bar")).containsExactly(5, 3); + assertThat(b.query("foo", "bar")).containsExactly(2, 4); + assertThat(c.query("foo", "bar")).containsExactly(3, 6); + + assertThat(a.merge(new String[]{"cms_b", "cms_c"}, new int[]{})).isTrue(); + assertThat(a.query("foo", "bar")).containsExactly(5, 10); + } } diff --git a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/CuckooFilterTest.java b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/CuckooFilterTest.java index ddd7cc2..4df7e74 100644 --- a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/CuckooFilterTest.java +++ b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/CuckooFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 dengliming. + * Copyright 2020-2022 dengliming. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,32 @@ public class CuckooFilterTest extends AbstractTest { @Test public void testReserve() { CuckooFilter cuckooFilter = getRedisBloomClient().getCuckooFilter("cf_reserve"); - assertThat(cuckooFilter.reserve(100)).isTrue(); + assertThat(cuckooFilter.reserve(10)).isTrue(); + + CuckooFilterInfo cuckooFilterInfo = cuckooFilter.getInfo(); + assertThat(cuckooFilterInfo.getBucketSize()).isEqualTo(2); + assertThat(cuckooFilterInfo.getInsertedNum()).isEqualTo(0); + assertThat(cuckooFilterInfo.getSize()).isEqualTo(72); + assertThat(cuckooFilterInfo.getExpansionRate()).isEqualTo(1); + assertThat(cuckooFilterInfo.getFilterNum()).isEqualTo(1); + assertThat(cuckooFilterInfo.getBucketNum()).isEqualTo(8); + assertThat(cuckooFilterInfo.getMaxIteration()).isEqualTo(20); + assertThat(cuckooFilterInfo.getDeletedNum()).isEqualTo(0); + + // with BucketSize + cuckooFilter = getRedisBloomClient().getCuckooFilter("cf_reserve1"); + assertThat(cuckooFilter.reserve(200, 10)).isTrue(); + cuckooFilterInfo = cuckooFilter.getInfo(); + assertThat(cuckooFilterInfo.getSize()).isEqualTo(376); + assertThat(cuckooFilterInfo.getBucketSize()).isEqualTo(10); + + cuckooFilter = getRedisBloomClient().getCuckooFilter("cf_reserve2"); + assertThat(cuckooFilter.reserve(200, 10, 20, 4)).isTrue(); + cuckooFilterInfo = cuckooFilter.getInfo(); + assertThat(cuckooFilterInfo.getSize()).isEqualTo(376); + assertThat(cuckooFilterInfo.getBucketSize()).isEqualTo(10); + assertThat(cuckooFilterInfo.getMaxIteration()).isEqualTo(20); + assertThat(cuckooFilterInfo.getExpansionRate()).isEqualTo(4); } @Test @@ -55,14 +80,6 @@ public void testInsert() { assertThat(result.get(0)).isTrue(); } - @Test - public void testInfo() { - CuckooFilter cuckooFilter = getRedisBloomClient().getCuckooFilter("cf_info"); - assertThat(cuckooFilter.reserve(100, 50)).isTrue(); - CuckooFilterInfo cuckooFilterInfo = cuckooFilter.getInfo(); - assertThat(cuckooFilterInfo.getBucketSize()).isEqualTo(50); - } - @Test public void testScanDump() { CuckooFilter cuckooFilter = getRedisBloomClient().getCuckooFilter("bf_info"); diff --git a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/TDigestTest.java b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/TDigestTest.java index 016d172..c00e282 100644 --- a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/TDigestTest.java +++ b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/TDigestTest.java @@ -40,6 +40,10 @@ public void testCreate() { TDigestInfo tDigestInfo = tDigest.getInfo(); assertThat(tDigestInfo).isNotNull(); assertThat(tDigestInfo.getCompression()).isEqualTo(100); + assertThat(tDigestInfo.getCapacity()).isEqualTo(610); + assertThat(tDigestInfo.getTotalCompressions()).isEqualTo(0); + assertThat(tDigestInfo.getMergedNodes()).isEqualTo(0); + tDigest.delete(); // compression negative/zero value @@ -176,6 +180,6 @@ public void testRank() { assertThat(tDigest.rank(1, 3)).containsExactly(2, 6); assertThat(tDigest.revRank(1, 3)).containsExactly(4, 0); assertThat(tDigest.byRank(0, 1)).containsExactly(1.0d, 1.0d); - assertThat(tDigest.byRevRank(2, 3)).containsExactly(2.0d, 1.0d); + assertThat(tDigest.byRevRank(2, 3)).containsExactly(1.0d, 1.0d); } } diff --git a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/TopKFilterTest.java b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/TopKFilterTest.java index 5d0cb08..f7bdc8d 100644 --- a/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/TopKFilterTest.java +++ b/redisbloom/src/test/java/io/github/dengliming/redismodule/redisbloom/TopKFilterTest.java @@ -59,5 +59,16 @@ public void testInfo() { assertThat(topKFilter.reserve(10, 2000, 7, 0.925d)).isTrue(); TopKFilterInfo topKFilterInfo = topKFilter.getInfo(); assertThat(topKFilterInfo.getDepth()).isEqualTo(7); + assertThat(topKFilterInfo.getTopK()).isEqualTo(10); + assertThat(topKFilterInfo.getWidth()).isEqualTo(2000); + assertThat(topKFilterInfo.getDecay()).isEqualTo(0.925d); + } + + @Test + public void testCount() { + TopKFilter topKFilter = getRedisBloomClient().getTopKFilter("topk_c"); + assertThat(topKFilter.reserve(10, 2000, 7, 0.925d)).isTrue(); + topKFilter.add("test"); + assertThat(topKFilter.count("not_exist", "test")).containsExactly(0, 1); } } diff --git a/redisgraph/src/main/java/io/github/dengliming/redismodule/redisgraph/RedisGraph.java b/redisgraph/src/main/java/io/github/dengliming/redismodule/redisgraph/RedisGraph.java index c8139e0..602e9a9 100644 --- a/redisgraph/src/main/java/io/github/dengliming/redismodule/redisgraph/RedisGraph.java +++ b/redisgraph/src/main/java/io/github/dengliming/redismodule/redisgraph/RedisGraph.java @@ -155,7 +155,7 @@ public List explain(String graphName, String query) { } public RFuture> explainAsync(String graphName, String query) { - return commandExecutor.readAsync(graphName, codec, GRAPH_EXPLAIN, graphName, query); + return commandExecutor.readAsync(graphName, StringCodec.INSTANCE, GRAPH_EXPLAIN, graphName, query); } /** diff --git a/redisgraph/src/test/java/io/github/dengliming/redismodule/redisgraph/RedisGraphTest.java b/redisgraph/src/test/java/io/github/dengliming/redismodule/redisgraph/RedisGraphTest.java index a287dad..17cac6c 100644 --- a/redisgraph/src/test/java/io/github/dengliming/redismodule/redisgraph/RedisGraphTest.java +++ b/redisgraph/src/test/java/io/github/dengliming/redismodule/redisgraph/RedisGraphTest.java @@ -23,6 +23,7 @@ import io.github.dengliming.redismodule.redisgraph.model.SlowLogItem; import io.github.dengliming.redismodule.redisgraph.model.Statistics; import org.junit.jupiter.api.Test; +import org.redisson.api.BatchResult; import java.util.List; import java.util.Map; @@ -75,7 +76,7 @@ public void testSlowLog() { public void testQuery() { RedisGraph redisGraph = getRedisGraph(); assertThat(redisGraph.query("social", "CREATE (:person{name:'filipe',age:30})", 0L)).isNotNull(); - assertThat(redisGraph.query("social", "MATCH (a:person) WHERE (a.name = 'filipe') RETURN a.age", 0L)).isNotNull(); + assertThat(redisGraph.query("social", "MATCH (a:person) WHERE (a.name = 'filipe') RETURN a.age", 1000L)).isNotNull(); } @Test @@ -134,7 +135,26 @@ public void testRecord() { assertThat(record.getString("a.age")).isEqualTo("32"); resultSet = redisGraph.readOnlyQuery("social", "MATCH (a:person)-[r:knows]->(b:person) RETURN a,r, " - + "a.name, a.age, a.doubleValue, a.boolValue, " + "r.place, r.since, r.doubleValue, r.boolValue", -1); + + "a.name, a.age, a.doubleValue, a.boolValue, " + "r.place, r.since, r.doubleValue, r.boolValue", 500); assertThat(resultSet).isNotNull(); } + + @Test + public void testExplain() { + RedisGraph redisGraph = getRedisGraph(); + assertThat(redisGraph.query("social", "CREATE (:person{name:'filipe',age:30})", 0L)).isNotNull(); + assertThat(redisGraph.explain("social", "MATCH (a:person) WHERE (a.name = 'filipe') RETURN a.age")).isNotEmpty(); + } + + @Test + public void testPipelining() { + RedisGraphBatch batch = getRedisGraphBatch(); + RedisGraph redisGraph = batch.getRedisGraph(); + redisGraph.profileAsync("social", "CREATE (:person{name:'roi',age:32})", 0L); + redisGraph.listAsync(); + BatchResult res = batch.execute(); + assertThat(res.getResponses().size()).isEqualTo(2); + assertThat((List) res.getResponses().get(0)).isNotEmpty(); + assertThat((List) res.getResponses().get(1)).contains("social"); + } }