SOLR-3089: RequestBuilder now exposes isDistrib() method

This commit is contained in:
Ishan Chattopadhyaya 2018-02-10 19:48:11 +05:30
parent 1fe34f1e89
commit 1f3d971a75
3 changed files with 56 additions and 0 deletions

View File

@ -274,6 +274,9 @@ Other Changes
* SOLR-11902: Clarify in bin/solr help text whether commands can be run remotely (Jason Gerlowski)
* SOLR-3089: RequestBuilder now exposes isDistrib() method. Using this, plugins can know whether a request is
distributed. (Rok Rejc, Frank Wesemann, Abhishek Kumar Singh, Mikhail Khludnev via Ishan Chattopadhyaya)
================== 7.2.1 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.

View File

@ -139,6 +139,13 @@ public class ResponseBuilder
public List<ShardRequest> finished; // requests that have received responses from all shards
public String shortCircuitedURL;
/**
* This function will return true if this was a distributed search request.
*/
public boolean isDistributed() {
return this.isDistrib;
}
public int getShardNum(String shard) {
for (int i = 0; i < shards.length; i++) {
if (shards[i] == shard || shards[i].equals(shard)) return i;

View File

@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.solr.handler;
import java.util.ArrayList;
import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.handler.component.ResponseBuilder;
import org.apache.solr.request.SolrQueryRequest;
import org.apache.solr.response.SolrQueryResponse;
import org.junit.BeforeClass;
public class ResponseBuilderTest extends SolrTestCaseJ4 {
@BeforeClass
public static void beforeClass() throws Exception {
initCore("solrconfig.xml", "schema.xml");
}
//This test is being added to verify responseBuilder.isDistributed() exists and is visible.
public void testIsDistrib(){
SolrQueryRequest req = req("q", "title:test");
SolrQueryResponse rsp = new SolrQueryResponse();
ResponseBuilder responseBuilder = new ResponseBuilder(req, rsp, new ArrayList<>(0));
assertFalse(responseBuilder.isDistributed());
}
}