|
28 | 28 | import org.apache.solr.common.params.ModifiableSolrParams; |
29 | 29 | import org.apache.solr.common.params.SolrParams; |
30 | 30 | import org.apache.solr.common.util.NamedList; |
| 31 | +import org.apache.solr.handler.component.QueryComponent; |
| 32 | +import org.apache.solr.handler.component.ResponseBuilder; |
| 33 | +import org.apache.solr.handler.component.ShardRequest; |
| 34 | +import org.apache.solr.request.SolrQueryRequest; |
| 35 | +import org.apache.solr.response.SolrQueryResponse; |
| 36 | +import org.apache.solr.search.grouping.distributed.requestfactory.TopGroupsShardRequestFactory; |
| 37 | +import org.junit.BeforeClass; |
31 | 38 | import org.junit.Test; |
32 | 39 |
|
33 | 40 | /** |
|
39 | 46 | @SuppressPointFields(bugUrl = "https://issues.apache.org/jira/browse/SOLR-10844") |
40 | 47 | public class TestDistributedGrouping extends BaseDistributedSearchTestCase { |
41 | 48 |
|
| 49 | + @BeforeClass |
| 50 | + public static void beforeClass() throws Exception { |
| 51 | + initCore("solrconfig-delaying-component.xml", "schema.xml"); |
| 52 | + } |
| 53 | + |
42 | 54 | public TestDistributedGrouping() { |
43 | 55 | // SOLR-10844: Even with points suppressed, this test breaks if we (randomize) docvalues="true" |
44 | 56 | // on trie fields?!?!?!!? |
@@ -1251,19 +1263,48 @@ public void test() throws Exception { |
1251 | 1263 | for (String rows : new String[] {"10", "0"}) { |
1252 | 1264 | simpleQuery( |
1253 | 1265 | "q", "*:*", "group", "true", "group.field", i1, "group.ngroups", ngroups, "rows", rows); |
1254 | | - simpleQuery( |
1255 | | - "q", |
1256 | | - "*:*", |
1257 | | - "group", |
1258 | | - "true", |
1259 | | - "group.field", |
1260 | | - i1, |
1261 | | - "group.ngroups", |
1262 | | - ngroups, |
1263 | | - "rows", |
1264 | | - rows, |
1265 | | - "timeAllowed", |
1266 | | - "123456"); |
| 1266 | + // delaying component introduces a delay longer than timeAllowed |
| 1267 | + QueryResponse rsp = |
| 1268 | + simpleQuery( |
| 1269 | + "q", |
| 1270 | + t1 + ":eggs", |
| 1271 | + "group", |
| 1272 | + "true", |
| 1273 | + "group.field", |
| 1274 | + i1, |
| 1275 | + "group.ngroups", |
| 1276 | + ngroups, |
| 1277 | + "rows", |
| 1278 | + rows, |
| 1279 | + "cache", |
| 1280 | + "false", |
| 1281 | + "timeAllowed", |
| 1282 | + "200", |
| 1283 | + "sleep", |
| 1284 | + "300"); |
| 1285 | + assertTrue( |
| 1286 | + "header: " + rsp.getHeader(), SolrQueryResponse.isPartialResults(rsp.getHeader())); |
| 1287 | + // |
| 1288 | + rsp = |
| 1289 | + simpleQuery( |
| 1290 | + "q", |
| 1291 | + t1 + ":eggs", |
| 1292 | + "group", |
| 1293 | + "true", |
| 1294 | + "group.field", |
| 1295 | + i1, |
| 1296 | + "group.ngroups", |
| 1297 | + ngroups, |
| 1298 | + "rows", |
| 1299 | + rows, |
| 1300 | + "cache", |
| 1301 | + "false", |
| 1302 | + "timeAllowed", |
| 1303 | + "200", |
| 1304 | + "sleep", |
| 1305 | + "10"); |
| 1306 | + assertFalse( |
| 1307 | + "header: " + rsp.getHeader(), SolrQueryResponse.isPartialResults(rsp.getHeader())); |
1267 | 1308 | } |
1268 | 1309 | } |
1269 | 1310 |
|
@@ -1650,13 +1691,51 @@ public void test() throws Exception { |
1650 | 1691 | "true"); |
1651 | 1692 | } |
1652 | 1693 |
|
1653 | | - private void simpleQuery(Object... queryParams) throws Exception { |
| 1694 | + @Test |
| 1695 | + public void testShardRequestFactory() throws Exception { |
| 1696 | + SolrQueryRequest req = |
| 1697 | + req( |
| 1698 | + "q", |
| 1699 | + "*:*", |
| 1700 | + "rows", |
| 1701 | + "100", |
| 1702 | + "fl", |
| 1703 | + "id," + i1, |
| 1704 | + "group", |
| 1705 | + "true", |
| 1706 | + "group.field", |
| 1707 | + i1, |
| 1708 | + "group.limit", |
| 1709 | + "-1", |
| 1710 | + "sort", |
| 1711 | + i1 + " asc, id asc", |
| 1712 | + "timeAllowed", |
| 1713 | + "200"); |
| 1714 | + try { |
| 1715 | + SolrQueryResponse rsp = new SolrQueryResponse(); |
| 1716 | + ResponseBuilder rb = new ResponseBuilder(req, rsp, List.of()); |
| 1717 | + new QueryComponent().prepare(rb); |
| 1718 | + rb.setNeedDocSet(true); |
| 1719 | + |
| 1720 | + TopGroupsShardRequestFactory f = new TopGroupsShardRequestFactory(); |
| 1721 | + ShardRequest[] sreq = f.constructRequest(rb); |
| 1722 | + assertTrue(sreq.length > 0); |
| 1723 | + |
| 1724 | + rb.firstPhaseElapsedTime = 200; // simulate timeout |
| 1725 | + sreq = f.constructRequest(rb); |
| 1726 | + assertEquals(0, sreq.length); |
| 1727 | + } finally { |
| 1728 | + req.close(); |
| 1729 | + } |
| 1730 | + } |
| 1731 | + |
| 1732 | + private QueryResponse simpleQuery(Object... queryParams) throws Exception { |
1654 | 1733 | ModifiableSolrParams params = new ModifiableSolrParams(); |
1655 | 1734 | for (int i = 0; i < queryParams.length; i += 2) { |
1656 | 1735 | params.add(queryParams[i].toString(), queryParams[i + 1].toString()); |
1657 | 1736 | } |
1658 | 1737 | params.set("shards", shards); |
1659 | | - queryRandomShard(params); |
| 1738 | + return queryRandomShard(params); |
1660 | 1739 | } |
1661 | 1740 |
|
1662 | 1741 | /** |
|
0 commit comments