use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class BaseCdcrDistributedZkTest method createCollection.
private CollectionAdminResponse createCollection(Map<String, List<Integer>> collectionInfos, String collectionName, Map<String, Object> collectionProps, SolrClient client, String confSetName) throws SolrServerException, IOException {
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("action", CollectionParams.CollectionAction.CREATE.toString());
for (Map.Entry<String, Object> entry : collectionProps.entrySet()) {
if (entry.getValue() != null)
params.set(entry.getKey(), String.valueOf(entry.getValue()));
}
Integer numShards = (Integer) collectionProps.get(NUM_SLICES);
if (numShards == null) {
String shardNames = (String) collectionProps.get(SHARDS_PROP);
numShards = StrUtils.splitSmart(shardNames, ',').size();
}
Integer replicationFactor = (Integer) collectionProps.get(REPLICATION_FACTOR);
if (replicationFactor == null) {
replicationFactor = (Integer) OverseerCollectionMessageHandler.COLL_PROPS.get(REPLICATION_FACTOR);
}
if (confSetName != null) {
params.set("collection.configName", confSetName);
}
List<Integer> list = new ArrayList<>();
list.add(numShards);
list.add(replicationFactor);
if (collectionInfos != null) {
collectionInfos.put(collectionName, list);
}
params.set("name", collectionName);
SolrRequest request = new QueryRequest(params);
request.setPath("/admin/collections");
CollectionAdminResponse res = new CollectionAdminResponse();
res.setResponse(client.request(request));
return res;
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class BasicDistributedZkTest method doOptimisticLockingAndUpdating.
// cloud level test mainly needed just to make sure that versions and errors are propagated correctly
private void doOptimisticLockingAndUpdating() throws Exception {
log.info("### STARTING doOptimisticLockingAndUpdating");
printLayout();
SolrInputDocument sd = sdoc("id", 1000, "_version_", -1);
indexDoc(sd);
ignoreException("version conflict");
for (SolrClient client : clients) {
try {
client.add(sd);
fail();
} catch (SolrException e) {
assertEquals(409, e.code());
}
}
unIgnoreException("version conflict");
// TODO: test deletes. SolrJ needs a good way to pass version for delete...
sd = sdoc("id", 1000, "foo_i", 5);
clients.get(0).add(sd);
List<Integer> expected = new ArrayList<>();
int val = 0;
for (SolrClient client : clients) {
val += 10;
client.add(sdoc("id", 1000, "val_i", map("add", val), "foo_i", val));
expected.add(val);
}
QueryRequest qr = new QueryRequest(params("qt", "/get", "id", "1000"));
for (SolrClient client : clients) {
val += 10;
NamedList rsp = client.request(qr);
String match = JSONTestUtil.matchObj("/val_i", rsp.get("doc"), expected);
if (match != null)
throw new RuntimeException(match);
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class BasicDistributedZkTest method getNumCommits.
private Long getNumCommits(HttpSolrClient sourceClient) throws SolrServerException, IOException {
// construct the /admin/metrics URL
URL url = new URL(sourceClient.getBaseURL());
String path = url.getPath().substring(1);
String[] elements = path.split("/");
String collection = elements[elements.length - 1];
String urlString = url.toString();
urlString = urlString.substring(0, urlString.length() - collection.length() - 1);
try (HttpSolrClient client = getHttpSolrClient(urlString)) {
client.setConnectionTimeout(15000);
client.setSoTimeout(60000);
ModifiableSolrParams params = new ModifiableSolrParams();
//params.set("qt", "/admin/metrics?prefix=UPDATE.updateHandler®istry=solr.core." + collection);
params.set("qt", "/admin/metrics");
params.set("prefix", "UPDATE.updateHandler");
params.set("registry", "solr.core." + collection);
// use generic request to avoid extra processing of queries
QueryRequest req = new QueryRequest(params);
NamedList<Object> resp = client.request(req);
NamedList metrics = (NamedList) resp.get("metrics");
NamedList uhandlerCat = (NamedList) metrics.getVal(0);
Map<String, Object> commits = (Map<String, Object>) uhandlerCat.get("UPDATE.updateHandler.commits");
return (Long) commits.get("count");
}
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class ShowFileRequestHandlerTest method testDirList.
public void testDirList() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
//assertQ(req("qt", "/admin/file")); TODO file bug that SolrJettyTestBase extends SolrTestCaseJ4
QueryRequest request = new QueryRequest();
request.setPath("/admin/file");
QueryResponse resp = request.process(client);
assertEquals(0, resp.getStatus());
//some files
assertTrue(((NamedList) resp.getResponse().get("files")).size() > 0);
}
use of org.apache.solr.client.solrj.request.QueryRequest in project lucene-solr by apache.
the class ShowFileRequestHandlerTest method test404ViaHttp.
public void test404ViaHttp() throws SolrServerException, IOException {
SolrClient client = getSolrClient();
QueryRequest request = new QueryRequest(params("file", "does-not-exist-404.txt"));
request.setPath("/admin/file");
try {
QueryResponse resp = request.process(client);
fail("didn't get 404 exception");
} catch (SolrException e) {
assertEquals(404, e.code());
}
}
Aggregations