Skip to content

Commit 90f5d09

Browse files
committed
Some clean ups, and updates for merges.
1 parent a195a36 commit 90f5d09

File tree

4 files changed

+25
-34
lines changed

4 files changed

+25
-34
lines changed

gradle/testing/randomization/policies/solr-tests.policy

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ grant {
3636
permission java.io.FilePermission "/path/to/solr/home/lib", "read";
3737

3838
// Needed by org.apache.solr.handler.component.UBIComponentTest
39-
permission java.io.FilePermission "${common-solr.dir}/core/build/resources/test/solr/userfiles/ubi_queries.jsonl", "write";
40-
permission java.io.FilePermission "/tmp/src/solr/solr/core/build/resources/test/solr/userfiles${/}-", "write";
41-
permission java.io.FilePermission "/tmp/src/solr/solr/core/build/resources/test/solr/userfiles", "write";
39+
permission java.io.FilePermission "${common-solr.dir}/core/build/resources/test/solr/userfiles", "read,write";
40+
permission java.io.FilePermission "${common-solr.dir}/core/build/resources/test/solr/userfiles${/}-", "read,write,delete";
4241

4342
permission java.nio.file.LinkPermission "hard";
4443

solr/core/src/java/org/apache/solr/handler/component/UBIComponent.java

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
*
8181
* <p>You provide a streaming expression that is parsed and loaded by the component to stream query
8282
* data to a target of your choice. If you do not, then the default expression of
83-
* 'logging(ubi_queries.jsonl,ubiQuery())"' is used which logs data to
83+
* 'logging(ubi_queries.jsonl,ubiQuery())' is used which logs data to
8484
* $SOLR_HOME/userfiles/ubi_queries.jsonl file.
8585
*
8686
* <p>You must source your streaming events using the 'ubiQuery()' streaming expression to retrieve
@@ -94,12 +94,9 @@
9494
*
9595
* <pre class="prettyprint">
9696
* &lt;searchComponent name="ubi" class="solr.UBIComponent"/&gt;
97-
*
9897
* &lt;requestHandler name="/select" class="solr.SearchHandler"&gt;
9998
* &lt;lst name="defaults"&gt;
100-
*
10199
* ...
102-
*
103100
* &lt;/lst&gt;
104101
* &lt;arr name="components"&gt;
105102
* &lt;str&gt;ubi&lt;/str&gt;
@@ -270,11 +267,11 @@ public int distributedProcess(ResponseBuilder rb) throws IOException {
270267

271268
// Wait until STAGE_GET_FIELDS when rb.resultIds contains the merged document IDs
272269
// from all shards, representing the final result set returned to the user
273-
if (rb.stage < ResponseBuilder.STAGE_GET_FIELDS) {
270+
if (rb.getStage() < ResponseBuilder.STAGE_GET_FIELDS) {
274271
return ResponseBuilder.STAGE_GET_FIELDS;
275272
}
276273

277-
if (rb.stage == ResponseBuilder.STAGE_GET_FIELDS) {
274+
if (rb.getStage() == ResponseBuilder.STAGE_GET_FIELDS) {
278275
// In distributed mode, rb.resultIds.keySet() contains the unique key values
279276
// from all shards, merged and sorted by the coordinator
280277
storeUbiDetails(
@@ -330,13 +327,13 @@ private static UBIQuery getUbiQuery(ResponseBuilder rb) {
330327
if (ubiQuery.getApplication() == null) {
331328
ubiQuery.setApplication(
332329
rb.isDistrib
333-
? rb.req.getCloudDescriptor().getCollectionName()
330+
? rb.req.getCore().getCoreDescriptor().getCollectionName()
334331
: searcher.getCore().getName());
335332
}
336333

337334
String queryAttributes = params.get(QUERY_ATTRIBUTES);
338335

339-
if (queryAttributes != null && queryAttributes.toString().startsWith("{")) {
336+
if (queryAttributes != null && queryAttributes.startsWith("{")) {
340337
// Look up the original nested JSON format, typically passed in
341338
// via the JSON formatted query.
342339
@SuppressWarnings("rawtypes")
@@ -490,15 +487,15 @@ public String getDescription() {
490487
/**
491488
* Handles all the data required for tracking a query using User Behavior Insights.
492489
*
493-
* <p>Compatible with the
494-
* https://github.com/o19s/ubi/blob/main/schema/1.2.0/query.request.schema.json.
490+
* <p>Compatible with the <a
491+
* href="https://github.com/o19s/ubi/blob/main/schema/1.2.0/query.request.schema.json">...</a>.
495492
*/
496493
public static class UBIQuery {
497494

498495
private String application;
499496
private String queryId;
500497
private String userQuery;
501-
private Date timestamp;
498+
private final Date timestamp;
502499

503500
@SuppressWarnings("rawtypes")
504501
private Map queryAttributes;
@@ -530,10 +527,6 @@ public String getQueryId() {
530527
return queryId;
531528
}
532529

533-
public void setQueryId(String queryId) {
534-
this.queryId = queryId;
535-
}
536-
537530
public String getUserQuery() {
538531
return userQuery;
539532
}
@@ -542,11 +535,6 @@ public void setUserQuery(String userQuery) {
542535
this.userQuery = userQuery;
543536
}
544537

545-
@SuppressWarnings("rawtypes")
546-
public Map getQueryAttributes() {
547-
return queryAttributes;
548-
}
549-
550538
@SuppressWarnings("rawtypes")
551539
public void setQueryAttributes(Map queryAttributes) {
552540
this.queryAttributes = queryAttributes;
@@ -562,7 +550,7 @@ public void setDocIds(String docIds) {
562550

563551
@SuppressWarnings({"rawtypes", "unchecked"})
564552
public Map toMap() {
565-
@SuppressWarnings({"rawtypes", "unchecked"})
553+
@SuppressWarnings({"rawtypes"})
566554
Map map = new HashMap();
567555
map.put(QUERY_ID, this.queryId);
568556
map.put(
@@ -596,8 +584,8 @@ public Map toMap() {
596584
* and returns it.
597585
*
598586
* <p>I suspect that if I had the right magic with a LetStream or a GetStream, I could somehow
599-
* just use that to say "pluck the 'ubi-query' object out of the StreamContext and call .toTuple
600-
* or make a map of it and that would be my tuple'.
587+
* just use that to "pluck" the 'ubi-query' object out of the StreamContext and call .toTuple or
588+
* make a map of it and that would be my tuple.
601589
*/
602590
public static class UBIQueryStream extends TupleStream implements Expressible {
603591

solr/core/src/test/org/apache/solr/handler/component/UBIComponentDistrQueriesTest.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
2323
import org.apache.solr.client.solrj.request.UpdateRequest;
2424
import org.apache.solr.client.solrj.response.QueryResponse;
25-
import org.apache.solr.cloud.AbstractDistribZkTestBase;
25+
import org.apache.solr.cloud.BasicDistributedZkTest;
2626
import org.apache.solr.cloud.SolrCloudTestCase;
27-
import org.apache.solr.cluster.api.SimpleMap;
2827
import org.apache.solr.common.SolrInputDocument;
2928
import org.apache.solr.common.params.MapSolrParams;
29+
import org.apache.solr.common.util.NamedList;
3030
import org.junit.Before;
3131
import org.junit.BeforeClass;
3232
import org.junit.Test;
@@ -59,7 +59,7 @@ public static void setupCluster() throws Exception {
5959

6060
cluster.waitForActiveCollection(collection, 2, 2);
6161

62-
AbstractDistribZkTestBase.waitForRecoveriesToFinish(
62+
BasicDistributedZkTest.waitForRecoveriesToFinish(
6363
collection, cluster.getZkStateReader(), false, true, TIMEOUT);
6464
if (useAlias) {
6565
CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection)
@@ -77,7 +77,7 @@ public static void setupCluster() throws Exception {
7777

7878
cluster.waitForActiveCollection("ubi_queries", 1, 1);
7979

80-
AbstractDistribZkTestBase.waitForRecoveriesToFinish(
80+
BasicDistributedZkTest.waitForRecoveriesToFinish(
8181
"ubi_queries", cluster.getZkStateReader(), false, true, TIMEOUT);
8282
}
8383

@@ -106,7 +106,9 @@ public void testUBIQueryStream() throws Exception {
106106
new MapSolrParams(Map.of("q", "aa", "df", "subject", "rows", "2", "ubi", "true")));
107107

108108
// Verify UBI response was added
109-
String qid = (String) ((SimpleMap<?>) queryResponse.getResponse().get("ubi")).get("query_id");
109+
@SuppressWarnings("unchecked")
110+
NamedList<Object> ubiResponse = (NamedList<Object>) queryResponse.getResponse().get("ubi");
111+
String qid = (String) ubiResponse.get("query_id");
110112
assertNotNull("Query ID should be present", qid);
111113
assertTrue("Query ID should be a valid UUID", qid.length() > 10);
112114

@@ -194,7 +196,9 @@ public void testUBIInDistributedMode_MultipleShards() throws Exception {
194196
// Verify we got results
195197
assertTrue("Should get results from distributed query", queryResponse.getResults().size() > 0);
196198

197-
String qid = (String) ((SimpleMap<?>) queryResponse.getResponse().get("ubi")).get("query_id");
199+
@SuppressWarnings("unchecked")
200+
NamedList<Object> ubiResponse = (NamedList<Object>) queryResponse.getResponse().get("ubi");
201+
String qid = (String) ubiResponse.get("query_id");
198202
assertNotNull("Query ID should be present in distributed mode", qid);
199203

200204
// Force commit and wait for record

solr/core/src/test/org/apache/solr/handler/component/UBIComponentStreamingQueriesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import org.apache.solr.client.solrj.io.stream.expr.StreamFactory;
4242
import org.apache.solr.client.solrj.request.CollectionAdminRequest;
4343
import org.apache.solr.client.solrj.request.UpdateRequest;
44-
import org.apache.solr.cloud.AbstractDistribZkTestBase;
44+
import org.apache.solr.cloud.BasicDistributedZkTest;
4545
import org.apache.solr.cloud.SolrCloudTestCase;
4646
import org.apache.solr.core.SolrCore;
4747
import org.apache.solr.embedded.JettySolrRunner;
@@ -76,7 +76,7 @@ public static void setupCluster() throws Exception {
7676

7777
cluster.waitForActiveCollection(collection, 2, 2);
7878

79-
AbstractDistribZkTestBase.waitForRecoveriesToFinish(
79+
BasicDistributedZkTest.waitForRecoveriesToFinish(
8080
collection, cluster.getZkStateReader(), false, true, TIMEOUT);
8181
if (useAlias) {
8282
CollectionAdminRequest.createAlias(COLLECTIONORALIAS, collection)

0 commit comments

Comments
 (0)