Skip to content

Commit

Permalink
DOC-4317 fixed flaky tests (#3984)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-stark-redis authored Oct 7, 2024
1 parent 9deb937 commit 801ec93
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
18 changes: 10 additions & 8 deletions src/test/java/io/redis/examples/QueryAggExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

// HIDE_START
import java.util.List;
import java.util.stream.Stream;
import java.util.ArrayList;
import redis.clients.jedis.UnifiedJedis;
import redis.clients.jedis.json.Path2;
Expand Down Expand Up @@ -233,11 +234,10 @@ public void run() {
// Tests for 'agg1' step.
// REMOVE_START
Assert.assertEquals(5, rows1.size());
Assert.assertEquals("{__key=bicycle:0, discounted=243, price=270}", rows1.get(0).toString());
Assert.assertEquals("{__key=bicycle:5, discounted=729, price=810}", rows1.get(1).toString());
Assert.assertEquals("{__key=bicycle:6, discounted=2070, price=2300}", rows1.get(2).toString());
Assert.assertEquals("{__key=bicycle:7, discounted=387, price=430}", rows1.get(3).toString());
Assert.assertEquals("{__key=bicycle:8, discounted=1080, price=1200}", rows1.get(4).toString());
Assert.assertArrayEquals(
new String[]{"bicycle:0", "bicycle:5", "bicycle:6", "bicycle:7", "bicycle:8"},
rows1.stream().map(e->e.get("__key")).sorted().toArray()
);
// REMOVE_END


Expand All @@ -264,9 +264,11 @@ public void run() {
// Tests for 'agg2' step.
// REMOVE_START
Assert.assertEquals(3, rows2.size());
Assert.assertEquals("{condition=refurbished, num_affordable=1}", rows2.get(0).toString());
Assert.assertEquals("{condition=used, num_affordable=1}", rows2.get(1).toString());
Assert.assertEquals("{condition=new, num_affordable=3}", rows2.get(2).toString());
Assert.assertArrayEquals(
new String[] { "new, 3", "refurbished, 1", "used, 1" },
rows2.stream().map(e->e.get("condition") + ", " + e.get("num_affordable"))
.sorted().toArray()
);
// REMOVE_END


Expand Down
11 changes: 6 additions & 5 deletions src/test/java/io/redis/examples/QueryEmExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

// HIDE_START
import java.util.List;
import java.util.stream.Stream;

import redis.clients.jedis.UnifiedJedis;
import redis.clients.jedis.json.Path2;
import redis.clients.jedis.search.*;
Expand Down Expand Up @@ -262,11 +264,10 @@ public void run() {
// Tests for 'em2' step.
// REMOVE_START
Assert.assertEquals(5, res3.getTotalResults());
Assert.assertEquals("bicycle:5", docs3.get(0).getId());
Assert.assertEquals("bicycle:0", docs3.get(1).getId());
Assert.assertEquals("bicycle:6", docs3.get(2).getId());
Assert.assertEquals("bicycle:7", docs3.get(3).getId());
Assert.assertEquals("bicycle:8", docs3.get(4).getId());
Assert.assertArrayEquals(
new String[] {"bicycle:0", "bicycle:5", "bicycle:6", "bicycle:7", "bicycle:8" },
docs3.stream().map(Document::getId).sorted().toArray()
);
// REMOVE_END


Expand Down
12 changes: 8 additions & 4 deletions src/test/java/io/redis/examples/QueryFtExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,10 @@ public void run() {
// Tests for 'ft1' step.
// REMOVE_START
Assert.assertEquals(2, res1.getTotalResults());
Assert.assertEquals("bicycle:2", docs1.get(0).getId());
Assert.assertEquals("bicycle:1", docs1.get(1).getId());
Assert.assertArrayEquals(
new String[] {"bicycle:1", "bicycle:2" },
docs1.stream().map(Document::getId).sorted().toArray()
);
// REMOVE_END


Expand Down Expand Up @@ -262,8 +264,10 @@ public void run() {
// Tests for 'ft3' step.
// REMOVE_START
Assert.assertEquals(2, res3.getTotalResults());
Assert.assertEquals("bicycle:6", docs3.get(0).getId());
Assert.assertEquals("bicycle:4", docs3.get(1).getId());
Assert.assertArrayEquals(
new String[] {"bicycle:4", "bicycle:6" },
docs3.stream().map(Document::getId).sorted().toArray()
);
// REMOVE_END


Expand Down
9 changes: 4 additions & 5 deletions src/test/java/io/redis/examples/QueryRangeExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,10 @@ public void run() {
// Tests for 'range4' step.
// REMOVE_START
Assert.assertEquals(7, res4.getTotalResults());
Assert.assertEquals("bicycle:0", docs4.get(0).getId());
Assert.assertEquals("bicycle:7", docs4.get(1).getId());
Assert.assertEquals("bicycle:5", docs4.get(2).getId());
Assert.assertEquals("bicycle:2", docs4.get(3).getId());
Assert.assertEquals("bicycle:9", docs4.get(4).getId());
Assert.assertArrayEquals(
new String[] {"bicycle:0", "bicycle:2", "bicycle:5", "bicycle:7", "bicycle:9" },
docs4.stream().map(Document::getId).sorted().toArray()
);
// REMOVE_END

// HIDE_START
Expand Down

0 comments on commit 801ec93

Please sign in to comment.