|
1 | 1 | package redis.clients.jedis.modules.search;
|
2 | 2 |
|
| 3 | +import static org.hamcrest.MatcherAssert.assertThat; |
3 | 4 | import static org.junit.Assert.*;
|
4 | 5 | import static redis.clients.jedis.util.AssertUtil.assertOK;
|
5 | 6 |
|
6 | 7 | import java.util.*;
|
| 8 | +import java.util.concurrent.atomic.AtomicInteger; |
7 | 9 | import java.util.stream.Collectors;
|
8 | 10 | import org.hamcrest.Matchers;
|
9 | 11 | import org.junit.BeforeClass;
|
@@ -1190,28 +1192,31 @@ public void deepReplySearchProfile() {
|
1190 | 1192 | ? (Map<String, Object>) profile.getValue().get("Iterators profile")
|
1191 | 1193 | : ((List<Map<String, Object>>) profile.getValue().get("Iterators profile")).get(0);
|
1192 | 1194 |
|
1193 |
| - assertEquals("INTERSECT", depth0.get("Type")); |
1194 |
| - List<Map<String, Object>> depth0_children = (List<Map<String, Object>>) depth0.get("Child iterators"); |
1195 |
| - assertEquals("TEXT", depth0_children.get(0).get("Type")); |
1196 |
| - Map<String, Object> depth1 = depth0_children.get(1); |
1197 |
| - assertEquals("INTERSECT", depth1.get("Type")); |
1198 |
| - List<Map<String, Object>> depth1_children = (List<Map<String, Object>>) depth1.get("Child iterators"); |
1199 |
| - assertEquals("TEXT", depth1_children.get(0).get("Type")); |
1200 |
| - Map<String, Object> depth2 = depth1_children.get(1); |
1201 |
| - assertEquals("INTERSECT", depth2.get("Type")); |
1202 |
| - List<Map<String, Object>> depth2_children = (List<Map<String, Object>>) depth2.get("Child iterators"); |
1203 |
| - assertEquals("TEXT", depth2_children.get(0).get("Type")); |
1204 |
| - Map<String, Object> depth3 = depth2_children.get(1); |
1205 |
| - assertEquals("INTERSECT", depth3.get("Type")); |
1206 |
| - List<Map<String, Object>> depth3_children = (List<Map<String, Object>>) depth3.get("Child iterators"); |
1207 |
| - assertEquals("TEXT", depth3_children.get(0).get("Type")); |
1208 |
| - Map<String, Object> depth4 = depth3_children.get(1); |
1209 |
| - assertEquals("INTERSECT", depth4.get("Type")); |
1210 |
| - List<Map<String, Object>> depth4_children = (List<Map<String, Object>>) depth4.get("Child iterators"); |
1211 |
| - assertEquals("TEXT", depth4_children.get(0).get("Type")); |
1212 |
| - Map<String, Object> depth5 = depth4_children.get(1); |
1213 |
| - assertEquals("TEXT", depth5.get("Type")); |
1214 |
| - assertNull(depth5.get("Child iterators")); |
| 1195 | + AtomicInteger intersectLevelCount = new AtomicInteger(); |
| 1196 | + AtomicInteger textLevelCount = new AtomicInteger(); |
| 1197 | + deepReplySearchProfile_assertProfile(depth0, intersectLevelCount, textLevelCount); |
| 1198 | + assertThat(intersectLevelCount.get(), Matchers.greaterThan(0)); |
| 1199 | + assertThat(textLevelCount.get(), Matchers.greaterThan(0)); |
| 1200 | + } |
| 1201 | + |
| 1202 | + private void deepReplySearchProfile_assertProfile(Map<String, Object> attr, |
| 1203 | + AtomicInteger intersectLevelCount, AtomicInteger textLevelCount) { |
| 1204 | + |
| 1205 | + String type = (String) attr.get("Type"); |
| 1206 | + assertThat(type, Matchers.not(Matchers.blankOrNullString())); |
| 1207 | + |
| 1208 | + switch (type) { |
| 1209 | + case "INTERSECT": |
| 1210 | + assertThat(attr, Matchers.hasKey("Child iterators")); |
| 1211 | + intersectLevelCount.incrementAndGet(); |
| 1212 | + deepReplySearchProfile_assertProfile((Map) ((List) attr.get("Child iterators")).get(0), |
| 1213 | + intersectLevelCount, textLevelCount); |
| 1214 | + break; |
| 1215 | + case "TEXT": |
| 1216 | + assertThat(attr, Matchers.hasKey("Term")); |
| 1217 | + textLevelCount.incrementAndGet(); |
| 1218 | + break; |
| 1219 | + } |
1215 | 1220 | }
|
1216 | 1221 |
|
1217 | 1222 | @Test
|
|
0 commit comments