use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method listCollection.
private void listCollection() throws IOException, SolrServerException {
try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.LIST.toString());
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
List<String> collections = (List<String>) rsp.get("collections");
assertTrue("control_collection was not found in list", collections.contains("control_collection"));
assertTrue(DEFAULT_COLLECTION + " was not found in list", collections.contains(DEFAULT_COLLECTION));
assertTrue(COLLECTION_NAME + " was not found in list", collections.contains(COLLECTION_NAME));
assertTrue(COLLECTION_NAME1 + " was not found in list", collections.contains(COLLECTION_NAME1));
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method missingParamsError.
private void missingParamsError(CloudSolrClient client, ModifiableSolrParams origParams) throws IOException, SolrServerException {
SolrRequest request;
try {
request = new QueryRequest(origParams);
request.setPath("/admin/collections");
client.request(request);
fail("Should have thrown a SolrException due to lack of a required parameter.");
} catch (SolrException se) {
assertTrue("Should have gotten a specific message back mentioning 'missing required parameter'. Got: " + se.getMessage(), se.getMessage().toLowerCase(Locale.ROOT).contains("missing required parameter:"));
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method clusterStatusWithRouteKey.
private void clusterStatusWithRouteKey() throws IOException, SolrServerException {
try (CloudSolrClient client = createCloudClient(DEFAULT_COLLECTION)) {
SolrInputDocument doc = new SolrInputDocument();
// goes to shard2. see ShardRoutingTest for details
doc.addField("id", "a!123");
client.add(doc);
client.commit();
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", DEFAULT_COLLECTION);
params.set(ShardParams._ROUTE_, "a!");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
NamedList<Object> rsp = client.request(request);
NamedList<Object> cluster = (NamedList<Object>) rsp.get("cluster");
assertNotNull("Cluster state should not be null", cluster);
NamedList<Object> collections = (NamedList<Object>) cluster.get("collections");
assertNotNull("Collections should not be null in cluster state", collections);
assertNotNull(collections.get(DEFAULT_COLLECTION));
assertEquals(1, collections.size());
Map<String, Object> collection = (Map<String, Object>) collections.get(DEFAULT_COLLECTION);
assertEquals("conf1", collection.get("configName"));
Map<String, Object> shardStatus = (Map<String, Object>) collection.get("shards");
assertEquals(1, shardStatus.size());
Map<String, Object> selectedShardStatus = (Map<String, Object>) shardStatus.get(SHARD2);
assertNotNull(selectedShardStatus);
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method clusterStatusBadCollectionTest.
private void clusterStatusBadCollectionTest() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CLUSTERSTATUS.toString());
params.set("collection", "bad_collection_name");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
try {
client.request(request);
fail("Collection does not exist. An exception should be thrown");
} catch (SolrException e) {
//expected
assertTrue(e.getMessage().contains("Collection: bad_collection_name not found"));
}
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class TestCollectionAPI method testShardCreationNameValidation.
private void testShardCreationNameValidation() throws Exception {
try (CloudSolrClient client = createCloudClient(null)) {
client.connect();
// Create a collection w/ implicit router
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CREATE.toString());
params.set("name", "valid_collection_name");
params.set("shards", "a");
params.set("router.name", "implicit");
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
client.request(request);
params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CREATESHARD.toString());
params.set("collection", "valid_collection_name");
params.set("shard", "invalid@name#with$weird%characters");
request = new QueryRequest(params);
request.setPath("/admin/collections");
try {
client.request(request);
fail();
} catch (RemoteSolrException e) {
final String errorMessage = e.getMessage();
assertTrue(errorMessage.contains("Invalid shard"));
assertTrue(errorMessage.contains("invalid@name#with$weird%characters"));
assertTrue(errorMessage.contains("shard names must consist entirely of"));
}
}
}
Aggregations