use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class CloudSolrClientTest method testCollectionDoesntExist.
@Test
public void testCollectionDoesntExist() throws Exception {
CloudSolrClient client = getRandomClient();
SolrInputDocument doc = new SolrInputDocument("id", "1", "title_s", "my doc");
try {
client.add("boguscollectionname", doc);
fail();
} catch (SolrException ex) {
if (ex.getMessage().equals("Collection not found: boguscollectionname")) {
// pass
} else {
throw ex;
}
}
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class SolrExampleStreamingTest method testWaitOptions.
public void testWaitOptions() throws Exception {
// SOLR-3903
final List<Throwable> failures = new ArrayList<>();
final String serverUrl = jetty.getBaseUrl().toString() + "/collection1";
try (ConcurrentUpdateSolrClient concurrentClient = new FailureRecordingConcurrentUpdateSolrClient(serverUrl, 2, 2)) {
int docId = 42;
for (UpdateRequest.ACTION action : EnumSet.allOf(UpdateRequest.ACTION.class)) {
for (boolean waitSearch : Arrays.asList(true, false)) {
for (boolean waitFlush : Arrays.asList(true, false)) {
UpdateRequest updateRequest = new UpdateRequest();
SolrInputDocument document = new SolrInputDocument();
document.addField("id", docId++);
updateRequest.add(document);
updateRequest.setAction(action, waitSearch, waitFlush);
concurrentClient.request(updateRequest);
}
}
}
concurrentClient.commit();
concurrentClient.blockUntilFinished();
}
if (0 != failures.size()) {
assertEquals(failures.size() + " Unexpected Exception, starting with...", null, failures.get(0));
}
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class TestSolrProperties method testProperties.
@Test
public void testProperties() throws Exception {
UpdateRequest up = new UpdateRequest();
up.setAction(ACTION.COMMIT, true, true);
up.deleteByQuery("*:*");
up.process(getSolrCore0());
up.process(getSolrCore1());
up.clear();
// Add something to each core
SolrInputDocument doc = new SolrInputDocument();
doc.setField("id", "AAA");
doc.setField("core0", "yup stopfra stopfrb stopena stopenb");
// Add to core0
up.add(doc);
up.process(getSolrCore0());
SolrTestCaseJ4.ignoreException("unknown field");
// You can't add it to core1
try {
up.process(getSolrCore1());
fail("Can't add core0 field to core1!");
} catch (Exception ex) {
}
// Add to core1
doc.setField("id", "BBB");
doc.setField("core1", "yup stopfra stopfrb stopena stopenb");
doc.removeField("core0");
up.add(doc);
up.process(getSolrCore1());
// You can't add it to core1
try {
SolrTestCaseJ4.ignoreException("core0");
up.process(getSolrCore0());
fail("Can't add core1 field to core0!");
} catch (Exception ex) {
}
SolrTestCaseJ4.resetExceptionIgnores();
// now Make sure AAA is in 0 and BBB in 1
SolrQuery q = new SolrQuery();
QueryRequest r = new QueryRequest(q);
q.setQuery("id:AAA");
assertEquals(1, r.process(getSolrCore0()).getResults().size());
assertEquals(0, r.process(getSolrCore1()).getResults().size());
// Now test Changing the default core
assertEquals(1, getSolrCore0().query(new SolrQuery("id:AAA")).getResults().size());
assertEquals(0, getSolrCore0().query(new SolrQuery("id:BBB")).getResults().size());
assertEquals(0, getSolrCore1().query(new SolrQuery("id:AAA")).getResults().size());
assertEquals(1, getSolrCore1().query(new SolrQuery("id:BBB")).getResults().size());
// Now test reloading it should have a newer open time
String name = "core0";
SolrClient coreadmin = getSolrAdmin();
CoreAdminResponse mcr = CoreAdminRequest.getStatus(name, coreadmin);
long before = mcr.getStartTime(name).getTime();
CoreAdminRequest.reloadCore(name, coreadmin);
mcr = CoreAdminRequest.getStatus(name, coreadmin);
long after = mcr.getStartTime(name).getTime();
assertTrue("should have more recent time: " + after + "," + before, after > before);
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class BasicHttpSolrClientTest method testCollectionParameters.
@Test
public void testCollectionParameters() throws IOException, SolrServerException {
try (HttpSolrClient client = getHttpSolrClient(jetty.getBaseUrl().toString())) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", "collection");
client.add("collection1", doc);
client.commit("collection1");
assertEquals(1, client.query("collection1", new SolrQuery("id:collection")).getResults().getNumFound());
}
final String collection1Url = jetty.getBaseUrl().toString() + "/collection1";
try (HttpSolrClient client = getHttpSolrClient(collection1Url)) {
assertEquals(1, client.query(new SolrQuery("id:collection")).getResults().getNumFound());
}
}
use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.
the class TestLBHttpSolrClient method addDocs.
private void addDocs(SolrInstance solrInstance) throws IOException, SolrServerException {
List<SolrInputDocument> docs = new ArrayList<>();
for (int i = 0; i < 10; i++) {
SolrInputDocument doc = new SolrInputDocument();
doc.addField("id", i);
doc.addField("name", solrInstance.name);
docs.add(doc);
}
SolrResponseBase resp;
try (HttpSolrClient client = getHttpSolrClient(solrInstance.getUrl(), httpClient)) {
resp = client.add(docs);
assertEquals(0, resp.getStatus());
resp = client.commit();
assertEquals(0, resp.getStatus());
}
}
Aggregations