Skip to content

Commit

Permalink
Merge branch 'master' into get-reducer-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 authored Nov 28, 2023
2 parents bddfe76 + ede6319 commit f835033
Showing 1 changed file with 27 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package redis.clients.jedis.modules.search;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static redis.clients.jedis.util.AssertUtil.assertOK;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.hamcrest.Matchers;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -1190,28 +1192,31 @@ public void deepReplySearchProfile() {
? (Map<String, Object>) profile.getValue().get("Iterators profile")
: ((List<Map<String, Object>>) profile.getValue().get("Iterators profile")).get(0);

assertEquals("INTERSECT", depth0.get("Type"));
List<Map<String, Object>> depth0_children = (List<Map<String, Object>>) depth0.get("Child iterators");
assertEquals("TEXT", depth0_children.get(0).get("Type"));
Map<String, Object> depth1 = depth0_children.get(1);
assertEquals("INTERSECT", depth1.get("Type"));
List<Map<String, Object>> depth1_children = (List<Map<String, Object>>) depth1.get("Child iterators");
assertEquals("TEXT", depth1_children.get(0).get("Type"));
Map<String, Object> depth2 = depth1_children.get(1);
assertEquals("INTERSECT", depth2.get("Type"));
List<Map<String, Object>> depth2_children = (List<Map<String, Object>>) depth2.get("Child iterators");
assertEquals("TEXT", depth2_children.get(0).get("Type"));
Map<String, Object> depth3 = depth2_children.get(1);
assertEquals("INTERSECT", depth3.get("Type"));
List<Map<String, Object>> depth3_children = (List<Map<String, Object>>) depth3.get("Child iterators");
assertEquals("TEXT", depth3_children.get(0).get("Type"));
Map<String, Object> depth4 = depth3_children.get(1);
assertEquals("INTERSECT", depth4.get("Type"));
List<Map<String, Object>> depth4_children = (List<Map<String, Object>>) depth4.get("Child iterators");
assertEquals("TEXT", depth4_children.get(0).get("Type"));
Map<String, Object> depth5 = depth4_children.get(1);
assertEquals("TEXT", depth5.get("Type"));
assertNull(depth5.get("Child iterators"));
AtomicInteger intersectLevelCount = new AtomicInteger();
AtomicInteger textLevelCount = new AtomicInteger();
deepReplySearchProfile_assertProfile(depth0, intersectLevelCount, textLevelCount);
assertThat(intersectLevelCount.get(), Matchers.greaterThan(0));
assertThat(textLevelCount.get(), Matchers.greaterThan(0));
}

private void deepReplySearchProfile_assertProfile(Map<String, Object> attr,
AtomicInteger intersectLevelCount, AtomicInteger textLevelCount) {

String type = (String) attr.get("Type");
assertThat(type, Matchers.not(Matchers.blankOrNullString()));

switch (type) {
case "INTERSECT":
assertThat(attr, Matchers.hasKey("Child iterators"));
intersectLevelCount.incrementAndGet();
deepReplySearchProfile_assertProfile((Map) ((List) attr.get("Child iterators")).get(0),
intersectLevelCount, textLevelCount);
break;
case "TEXT":
assertThat(attr, Matchers.hasKey("Term"));
textLevelCount.incrementAndGet();
break;
}
}

@Test
Expand Down

0 comments on commit f835033

Please sign in to comment.