SOLR-13719: introducing SolrClient.ping(collection)

This commit is contained in:
Mikhail Khludnev 2019-10-06 23:35:17 +03:00
parent af2fe8febc
commit 67de998cb7
4 changed files with 41 additions and 1 deletions

View File

@ -125,6 +125,8 @@ Improvements
* SOLR-13795: Managed schema operations should do a core reload in Solr standalone mode.
(Thomas Wöckinger via David Smiley)
* SOLR-13719: Introducing SolrClient.ping(collection) in SolrJ (Geza Nagy via Mikhail Khludnev)
Bug Fixes
----------------------

View File

@ -69,7 +69,7 @@ This command will ping all replicas of the given collection name for a response:
Both API calls have the same output. A status=OK indicates that the nodes are responding.
*SolrJ Example*
*SolrJ Example with SolrPing*
[source,java]
----
@ -78,3 +78,12 @@ ping.getParams().add("distrib", "true"); //To make it a distributed request agai
rsp = ping.process(solrClient, collectionName);
int status = rsp.getStatus();
----
*SolrJ Example with SolrClient*
[source,java]
----
SolrClient client = new HttpSolrClient.Builder(solrUrl).build();
SolrPingResponse pingResponse = client.ping(collectionName);
int status = pingResponse.getStatus();
----

View File

@ -958,6 +958,21 @@ public abstract class SolrClient implements Serializable, Closeable {
return deleteByQuery(null, query, commitWithinMs);
}
/**
* Issues a ping request to check if the collection's replicas are alive
*
* @param collection collection to ping
*
* @return a {@link org.apache.solr.client.solrj.response.SolrPingResponse} containing the response
* from the server
*
* @throws IOException If there is a low-level I/O error.
* @throws SolrServerException if there is an error on the server
*/
public SolrPingResponse ping(String collection) throws SolrServerException, IOException {
return new SolrPing().process(this, collection);
}
/**
* Issues a ping request to check if the server is alive
*
@ -971,6 +986,7 @@ public abstract class SolrClient implements Serializable, Closeable {
return new SolrPing().process(this, null);
}
/**
* Performs a query to the Solr server
*

View File

@ -49,6 +49,7 @@ import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.RequestStatusState;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.client.solrj.response.SolrPingResponse;
import org.apache.solr.cloud.AbstractDistribZkTestBase;
import org.apache.solr.cloud.SolrCloudTestCase;
import org.apache.solr.common.SolrDocument;
@ -951,4 +952,16 @@ public class CloudSolrClientTest extends SolrCloudTestCase {
log.info("Shards giving the response: " + Arrays.toString(shardAddresses.toArray()));
}
@Test
public void testPing() throws Exception {
final String testCollection = "ping_test";
CollectionAdminRequest.createCollection(testCollection, "conf", 2, 1).process(cluster.getSolrClient());
cluster.waitForActiveCollection(testCollection, 2, 2);
final SolrClient clientUnderTest = getRandomClient();
final SolrPingResponse response = clientUnderTest.ping(testCollection);
assertEquals("This should be OK", 0, response.getStatus());
}
}