use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.
the class TestLBHttpSolrClient method waitForServer.
// wait maximum ms for serverName to come back up
private void waitForServer(int maxSeconds, LBHttpSolrClient client, int nServers, String serverName) throws Exception {
final TimeOut timeout = new TimeOut(maxSeconds, TimeUnit.SECONDS);
while (!timeout.hasTimedOut()) {
QueryResponse resp;
try {
resp = client.query(new SolrQuery("*:*"));
} catch (Exception e) {
log.warn("", e);
continue;
}
String name = resp.getResults().get(0).getFieldValue("name").toString();
if (name.equals(serverName))
return;
Thread.sleep(500);
}
}
use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.
the class TestDocumentObjectBinder method testSimple.
public void testSimple() throws Exception {
DocumentObjectBinder binder = new DocumentObjectBinder();
XMLResponseParser parser = new XMLResponseParser();
NamedList<Object> nl = parser.processResponse(new StringReader(xml));
QueryResponse res = new QueryResponse(nl, null);
SolrDocumentList solDocList = res.getResults();
List<Item> l = binder.getBeans(Item.class, res.getResults());
assertEquals(solDocList.size(), l.size());
assertEquals(solDocList.get(0).getFieldValue("features"), l.get(0).features);
Item item = new Item();
item.id = "aaa";
item.categories = new String[] { "aaa", "bbb", "ccc" };
SolrInputDocument out = binder.toSolrInputDocument(item);
assertEquals(item.id, out.getFieldValue("id"));
SolrInputField catfield = out.getField("cat");
assertEquals(3, catfield.getValueCount());
List<String> catValues = (List<String>) catfield.getValue();
assertEquals("aaa", catValues.get(0));
assertEquals("bbb", catValues.get(1));
assertEquals("ccc", catValues.get(2));
}
use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.
the class TestCoreAdmin method testCoreSwap.
@Test
public void testCoreSwap() throws Exception {
// index marker docs to core0
SolrClient cli0 = getSolrCore0();
SolrInputDocument d = new SolrInputDocument("id", "core0-0");
cli0.add(d);
d = new SolrInputDocument("id", "core0-1");
cli0.add(d);
cli0.commit();
// index a marker doc to core1
SolrClient cli1 = getSolrCore1();
d = new SolrInputDocument("id", "core1-0");
cli1.add(d);
cli1.commit();
// initial state assertions
SolrQuery q = new SolrQuery("*:*");
QueryResponse rsp = cli0.query(q);
SolrDocumentList docs = rsp.getResults();
assertEquals(2, docs.size());
docs.forEach(doc -> {
assertTrue(doc.toString(), doc.getFieldValue("id").toString().startsWith("core0-"));
});
rsp = cli1.query(q);
docs = rsp.getResults();
assertEquals(1, docs.size());
docs.forEach(doc -> {
assertTrue(doc.toString(), doc.getFieldValue("id").toString().startsWith("core1-"));
});
// assert initial metrics
SolrMetricManager metricManager = cores.getMetricManager();
String core0RegistryName = SolrCoreMetricManager.createRegistryName(false, null, null, null, "core0");
String core1RegistryName = SolrCoreMetricManager.createRegistryName(false, null, null, null, "core1");
MetricRegistry core0Registry = metricManager.registry(core0RegistryName);
MetricRegistry core1Registry = metricManager.registry(core1RegistryName);
// 2 docs + 1 commit
assertEquals(3, core0Registry.counter("UPDATE./update.requests").getCount());
// 1 doc + 1 commit
assertEquals(2, core1Registry.counter("UPDATE./update.requests").getCount());
// swap
CoreAdminRequest.swapCore("core0", "core1", getSolrAdmin());
// assert state after swap
cli0 = getSolrCore0();
cli1 = getSolrCore1();
rsp = cli0.query(q);
docs = rsp.getResults();
assertEquals(1, docs.size());
docs.forEach(doc -> {
assertTrue(doc.toString(), doc.getFieldValue("id").toString().startsWith("core1-"));
});
rsp = cli1.query(q);
docs = rsp.getResults();
assertEquals(2, docs.size());
docs.forEach(doc -> {
assertTrue(doc.toString(), doc.getFieldValue("id").toString().startsWith("core0-"));
});
core0Registry = metricManager.registry(core0RegistryName);
core1Registry = metricManager.registry(core1RegistryName);
assertEquals(2, core0Registry.counter("UPDATE./update.requests").getCount());
assertEquals(3, core1Registry.counter("UPDATE./update.requests").getCount());
}
use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.
the class FullSolrCloudDistribCmdsTest method testDeleteByIdImplicitRouter.
private void testDeleteByIdImplicitRouter() throws Exception {
SolrClient server = createNewSolrClient("", getBaseUrl((HttpSolrClient) clients.get(0)));
CollectionAdminResponse response;
Map<String, NamedList<Integer>> coresStatus;
CollectionAdminRequest.Create createCollectionRequest = CollectionAdminRequest.createCollectionWithImplicitRouter("implicit_collection_without_routerfield", "conf1", "shard1,shard2", 2);
response = createCollectionRequest.process(server);
assertEquals(0, response.getStatus());
assertTrue(response.isSuccess());
coresStatus = response.getCollectionCoresStatus();
assertEquals(4, coresStatus.size());
for (int i = 0; i < 4; i++) {
NamedList<Integer> status = coresStatus.get("implicit_collection_without_routerfield_shard" + (i / 2 + 1) + "_replica" + (i % 2 + 1));
assertEquals(0, (int) status.get("status"));
assertTrue(status.get("QTime") > 0);
}
waitForRecoveriesToFinish("implicit_collection_without_routerfield", true);
SolrClient shard1 = createNewSolrClient("implicit_collection_without_routerfield_shard1_replica1", getBaseUrl((HttpSolrClient) clients.get(0)));
SolrClient shard2 = createNewSolrClient("implicit_collection_without_routerfield_shard2_replica1", getBaseUrl((HttpSolrClient) clients.get(0)));
SolrInputDocument doc = new SolrInputDocument();
int docCounts1, docCounts2;
// Add three documents to shard1
doc.clear();
doc.addField("id", "1");
doc.addField("title", "s1 one");
shard1.add(doc);
shard1.commit();
doc.clear();
doc.addField("id", "2");
doc.addField("title", "s1 two");
shard1.add(doc);
shard1.commit();
doc.clear();
doc.addField("id", "3");
doc.addField("title", "s1 three");
shard1.add(doc);
shard1.commit();
// Three documents in shard1
docCounts1 = 3;
// Add two documents to shard2
doc.clear();
doc.addField("id", "4");
doc.addField("title", "s2 four");
shard2.add(doc);
shard2.commit();
doc.clear();
doc.addField("id", "5");
doc.addField("title", "s2 five");
shard2.add(doc);
shard2.commit();
// Two documents in shard2
docCounts2 = 2;
// Verify the documents were added to correct shards
ModifiableSolrParams query = new ModifiableSolrParams();
query.set("q", "*:*");
QueryResponse respAll = shard1.query(query);
assertEquals(docCounts1 + docCounts2, respAll.getResults().getNumFound());
query.set("shards", "shard1");
QueryResponse resp1 = shard1.query(query);
assertEquals(docCounts1, resp1.getResults().getNumFound());
query.set("shards", "shard2");
QueryResponse resp2 = shard2.query(query);
assertEquals(docCounts2, resp2.getResults().getNumFound());
// Delete a document in shard2 with update to shard1, with _route_ param
// Should delete.
UpdateRequest deleteRequest = new UpdateRequest();
deleteRequest.deleteById("4", "shard2");
shard1.request(deleteRequest);
shard1.commit();
query.set("shards", "shard2");
resp2 = shard2.query(query);
assertEquals(--docCounts2, resp2.getResults().getNumFound());
// Delete a document in shard2 with update to shard1, without _route_ param
// Shouldn't delete, since deleteById requests are not broadcast to all shard leaders.
deleteRequest = new UpdateRequest();
deleteRequest.deleteById("5");
shard1.request(deleteRequest);
shard1.commit();
query.set("shards", "shard2");
resp2 = shard2.query(query);
assertEquals(docCounts2, resp2.getResults().getNumFound());
// Multiple deleteById commands in a single request
deleteRequest.clear();
deleteRequest.deleteById("2", "shard1");
deleteRequest.deleteById("3", "shard1");
deleteRequest.setCommitWithin(1);
query.set("shards", "shard1");
shard2.request(deleteRequest);
resp1 = shard1.query(query);
--docCounts1;
--docCounts1;
assertEquals(docCounts1, resp1.getResults().getNumFound());
// Test commitWithin, update to shard2, document deleted in shard1
deleteRequest.clear();
deleteRequest.deleteById("1", "shard1");
deleteRequest.setCommitWithin(1);
shard2.request(deleteRequest);
Thread.sleep(1000);
query.set("shards", "shard1");
resp1 = shard1.query(query);
assertEquals(--docCounts1, resp1.getResults().getNumFound());
}
use of org.apache.solr.client.solrj.response.QueryResponse in project lucene-solr by apache.
the class FullSolrCloudDistribCmdsTest method addTwoDocsInOneRequest.
private long addTwoDocsInOneRequest(long docId) throws Exception {
QueryResponse results;
UpdateRequest uReq;
uReq = new UpdateRequest();
docId = addDoc(docId, uReq);
docId = addDoc(docId, uReq);
uReq.process(cloudClient);
uReq.process(controlClient);
commit();
checkShardConsistency();
assertDocCounts(VERBOSE);
results = query(cloudClient);
assertEquals(2, results.getResults().getNumFound());
return docId;
}
Aggregations