Skip to content

Commit

Permalink
test: simplified zscan
Browse files Browse the repository at this point in the history
Signed-off-by: Jeronimo Irazabal <jeronimo.irazabal@gmail.com>
  • Loading branch information
jeroiraz committed Nov 26, 2022
1 parent 16951ab commit 312855b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 42 deletions.
47 changes: 45 additions & 2 deletions src/test/java/io/codenotary/immudb4j/ScanTest.java
Expand Up @@ -29,8 +29,8 @@ public class ScanTest extends ImmuClientIntegrationTest {
public void t1() {
immuClient.openSession("defaultdb", "immudb", "immudb");

byte[] value1 = {0, 1, 2, 3};
byte[] value2 = {4, 5, 6, 7};
byte[] value1 = { 0, 1, 2, 3 };
byte[] value2 = { 4, 5, 6, 7 };

try {
immuClient.set("scan1", value1);
Expand All @@ -39,6 +39,23 @@ public void t1() {
Assert.fail("Failed at set.", e);
}

try {
immuClient.set("zadd1", value1);
immuClient.set("zadd2", value2);
} catch (CorruptedDataException e) {
Assert.fail("Failed at set.", e);
}

try {
immuClient.zAdd("set1", "zadd1", 1);
immuClient.zAdd("set1", "zadd2", 2);

immuClient.zAdd("set2", "zadd1", 2);
immuClient.zAdd("set2", "zadd2", 1);
} catch (CorruptedDataException e) {
Assert.fail("Failed to zAdd", e);
}

List<Entry> scanResult = immuClient.scanAll("scan");
System.out.println(scanResult.size());

Expand All @@ -63,6 +80,32 @@ public void t1() {

Assert.assertEquals(i, 2);

Assert.assertFalse(immuClient.scan("nonexistent-prefix").hasNext());

List<ZEntry> zScan1 = immuClient.zScanAll("set1", false, 5);
Assert.assertEquals(zScan1.size(), 2);

Assert.assertEquals(zScan1.get(0).getSet(), "set1".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(zScan1.get(0).getKey(), "zadd1".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(zScan1.get(0).getScore(), 1.0);
Assert.assertEquals(zScan1.get(0).getAtTx(), 0);
Assert.assertEquals(zScan1.get(0).getEntry().getValue(), value1);

List<ZEntry> zScan2 = immuClient.zScanAll("set2");
Assert.assertEquals(zScan2.size(), 2);

Iterator<ZEntry> zScan3 = immuClient.zScan("set2");
i = 0;

while (zScan3.hasNext()) {
Assert.assertEquals(zScan3.next().getKey(), zScan2.get(i).getKey());
i++;
}

Assert.assertEquals(i, 2);

Assert.assertFalse(immuClient.zScan("nonexistent-set").hasNext());

immuClient.closeSession();
}

Expand Down
42 changes: 2 additions & 40 deletions src/test/java/io/codenotary/immudb4j/ZScanTest.java
Expand Up @@ -29,47 +29,9 @@ public class ZScanTest extends ImmuClientIntegrationTest {
public void t1() {
immuClient.openSession("defaultdb", "immudb", "immudb");

byte[] value1 = {0, 1, 2, 3};
byte[] value2 = {4, 5, 6, 7};


try {
immuClient.set("zadd1", value1);
immuClient.set("zadd2", value2);
} catch (CorruptedDataException e) {
Assert.fail("Failed at set.", e);
}

try {
immuClient.zAdd("set1", "zadd1", 1);
immuClient.zAdd("set1", "zadd2", 2);

immuClient.zAdd("set2", "zadd1", 2);
immuClient.zAdd("set2", "zadd2", 1);
} catch (CorruptedDataException e) {
Assert.fail("Failed to zAdd", e);
}

List<ZEntry> zScan1 = immuClient.zScanAll("set1", false, 5);
Assert.assertEquals(zScan1.size(), 2);

Assert.assertEquals(zScan1.get(0).getSet(), "set1".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(zScan1.get(0).getKey(), "zadd1".getBytes(StandardCharsets.UTF_8));
Assert.assertEquals(zScan1.get(0).getScore(), 1.0);
Assert.assertEquals(zScan1.get(0).getAtTx(), 0);
Assert.assertEquals(zScan1.get(0).getEntry().getValue(), value1);

List<ZEntry> zScan2 = immuClient.zScanAll("set2");
Assert.assertEquals(zScan2.size(), 2);

Iterator<ZEntry> zScan3 = immuClient.zScan("set2");
int i = 0;

while (zScan3.hasNext()) {
Assert.assertEquals(zScan3.next().getKey(), zScan2.get(i).getKey());
i++;
}

Assert.assertEquals(i, 2);


immuClient.closeSession();
}
Expand Down

0 comments on commit 312855b

Please sign in to comment.