use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class TestDocumentObjectBinder method testSingleVal4Array.
public void testSingleVal4Array() {
DocumentObjectBinder binder = new DocumentObjectBinder();
SolrDocumentList solDocList = new SolrDocumentList();
SolrDocument d = new SolrDocument();
solDocList.add(d);
d.setField("cat", "hello");
List<Item> l = binder.getBeans(Item.class, solDocList);
assertEquals("hello", l.get(0).categories[0]);
}
use of org.apache.solr.common.SolrDocumentList 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.common.SolrDocumentList 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.common.SolrDocumentList in project lucene-solr by apache.
the class TestReplicationHandler method doTestIndexFetchWithMasterUrl.
@Test
public void doTestIndexFetchWithMasterUrl() throws Exception {
//change solrconfig on slave
//this has no entry for pollinginterval
slave.copyConfigFile(CONF_DIR + "solrconfig-slave1.xml", "solrconfig.xml");
slaveJetty.stop();
slaveJetty = createJetty(slave);
slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
masterClient.deleteByQuery("*:*");
slaveClient.deleteByQuery("*:*");
slaveClient.commit();
nDocs--;
for (int i = 0; i < nDocs; i++) index(masterClient, "id", i, "name", "name = " + i);
// make sure prepareCommit doesn't mess up commit (SOLR-3938)
// todo: make SolrJ easier to pass arbitrary params to
// TODO: precommit WILL screw with the rest of this test
masterClient.commit();
NamedList masterQueryRsp = rQuery(nDocs, "*:*", masterClient);
SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
assertEquals(nDocs, masterQueryResult.getNumFound());
// index fetch
String masterUrl = buildUrl(slaveJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH + "?command=fetchindex&masterUrl=";
masterUrl += buildUrl(masterJetty.getLocalPort()) + "/" + DEFAULT_TEST_CORENAME + ReplicationHandler.PATH;
URL url = new URL(masterUrl);
InputStream stream = url.openStream();
stream.close();
//get docs from slave and check if number is equal to master
NamedList slaveQueryRsp = rQuery(nDocs, "*:*", slaveClient);
SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
assertEquals(nDocs, slaveQueryResult.getNumFound());
//compare results
String cmp = BaseDistributedSearchTestCase.compare(masterQueryResult, slaveQueryResult, 0, null);
assertEquals(null, cmp);
for (int i = nDocs; i < nDocs + 3; i++) index(slaveClient, "id", i, "name", "name = " + i);
slaveClient.commit();
pullFromSlaveToMaster();
rQuery(nDocs + 3, "*:*", masterClient);
//get docs from slave and check if number is equal to master
slaveQueryRsp = rQuery(nDocs + 3, "*:*", slaveClient);
slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
assertEquals(nDocs + 3, slaveQueryResult.getNumFound());
//compare results
masterQueryRsp = rQuery(nDocs + 3, "*:*", masterClient);
masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
cmp = BaseDistributedSearchTestCase.compare(masterQueryResult, slaveQueryResult, 0, null);
assertEquals(null, cmp);
assertVersions(masterClient, slaveClient);
pullFromSlaveToMaster();
//get docs from slave and check if number is equal to master
slaveQueryRsp = rQuery(nDocs + 3, "*:*", slaveClient);
slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
assertEquals(nDocs + 3, slaveQueryResult.getNumFound());
//compare results
masterQueryRsp = rQuery(nDocs + 3, "*:*", masterClient);
masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
cmp = BaseDistributedSearchTestCase.compare(masterQueryResult, slaveQueryResult, 0, null);
assertEquals(null, cmp);
assertVersions(masterClient, slaveClient);
// now force a new index directory
for (int i = nDocs + 3; i < nDocs + 7; i++) index(masterClient, "id", i, "name", "name = " + i);
masterClient.commit();
pullFromSlaveToMaster();
rQuery((int) slaveQueryResult.getNumFound(), "*:*", masterClient);
//get docs from slave and check if number is equal to master
slaveQueryRsp = rQuery(nDocs + 3, "*:*", slaveClient);
slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
assertEquals(nDocs + 3, slaveQueryResult.getNumFound());
//compare results
masterQueryRsp = rQuery(nDocs + 3, "*:*", masterClient);
masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
cmp = BaseDistributedSearchTestCase.compare(masterQueryResult, slaveQueryResult, 0, null);
assertEquals(null, cmp);
assertVersions(masterClient, slaveClient);
pullFromSlaveToMaster();
//get docs from slave and check if number is equal to master
slaveQueryRsp = rQuery(nDocs + 3, "*:*", slaveClient);
slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
assertEquals(nDocs + 3, slaveQueryResult.getNumFound());
//compare results
masterQueryRsp = rQuery(nDocs + 3, "*:*", masterClient);
masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
cmp = BaseDistributedSearchTestCase.compare(masterQueryResult, slaveQueryResult, 0, null);
assertEquals(null, cmp);
assertVersions(masterClient, slaveClient);
NamedList<Object> details = getDetails(masterClient);
details = getDetails(slaveClient);
checkForSingleIndex(masterJetty);
checkForSingleIndex(slaveJetty);
}
use of org.apache.solr.common.SolrDocumentList in project lucene-solr by apache.
the class TestReplicationHandler method doTestIndexAndConfigReplication.
@Test
public void doTestIndexAndConfigReplication() throws Exception {
clearIndexWithReplication();
nDocs--;
for (int i = 0; i < nDocs; i++) index(masterClient, "id", i, "name", "name = " + i);
masterClient.commit();
NamedList masterQueryRsp = rQuery(nDocs, "*:*", masterClient);
SolrDocumentList masterQueryResult = (SolrDocumentList) masterQueryRsp.get("response");
assertEquals(nDocs, numFound(masterQueryRsp));
//get docs from slave and check if number is equal to master
NamedList slaveQueryRsp = rQuery(nDocs, "*:*", slaveClient);
SolrDocumentList slaveQueryResult = (SolrDocumentList) slaveQueryRsp.get("response");
assertEquals(nDocs, numFound(slaveQueryRsp));
//compare results
String cmp = BaseDistributedSearchTestCase.compare(masterQueryResult, slaveQueryResult, 0, null);
assertEquals(null, cmp);
assertVersions(masterClient, slaveClient);
//start config files replication test
masterClient.deleteByQuery("*:*");
masterClient.commit();
//change the schema on master
master.copyConfigFile(CONF_DIR + "schema-replication2.xml", "schema.xml");
masterJetty.stop();
masterJetty = createJetty(master);
masterClient.close();
masterClient = createNewSolrClient(masterJetty.getLocalPort());
slave.setTestPort(masterJetty.getLocalPort());
slave.copyConfigFile(slave.getSolrConfigFile(), "solrconfig.xml");
slaveJetty.stop();
// setup an xslt dir to force subdir file replication
File masterXsltDir = new File(master.getConfDir() + File.separator + "xslt");
File masterXsl = new File(masterXsltDir, "dummy.xsl");
assertTrue("could not make dir " + masterXsltDir, masterXsltDir.mkdirs());
assertTrue(masterXsl.createNewFile());
File slaveXsltDir = new File(slave.getConfDir() + File.separator + "xslt");
File slaveXsl = new File(slaveXsltDir, "dummy.xsl");
assertFalse(slaveXsltDir.exists());
slaveJetty = createJetty(slave);
slaveClient.close();
slaveClient = createNewSolrClient(slaveJetty.getLocalPort());
//add a doc with new field and commit on master to trigger index fetch from slave.
index(masterClient, "id", "2000", "name", "name = " + 2000, "newname", "newname = " + 2000);
masterClient.commit();
assertEquals(1, numFound(rQuery(1, "*:*", masterClient)));
slaveQueryRsp = rQuery(1, "*:*", slaveClient);
assertVersions(masterClient, slaveClient);
SolrDocument d = ((SolrDocumentList) slaveQueryRsp.get("response")).get(0);
assertEquals("newname = 2000", (String) d.getFieldValue("newname"));
assertTrue(slaveXsltDir.isDirectory());
assertTrue(slaveXsl.exists());
checkForSingleIndex(masterJetty);
checkForSingleIndex(slaveJetty, true);
}
Aggregations