use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class TestTlogReplica method testOutOfOrderDBQWithInPlaceUpdates.
public void testOutOfOrderDBQWithInPlaceUpdates() throws Exception {
createAndWaitForCollection(1, 0, 2, 0);
assertFalse(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").indexed());
assertFalse(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").stored());
assertTrue(getSolrCore(true).get(0).getLatestSchema().getField("inplace_updatable_int").hasDocValues());
List<UpdateRequest> updates = new ArrayList<>();
// full update
updates.add(simulatedUpdateRequest(null, "id", 1, "title_s", "title0_new", "inplace_updatable_int", 5, "_version_", 1L));
updates.add(simulatedDBQ("inplace_updatable_int:5", 3L));
updates.add(simulatedUpdateRequest(1L, "id", 1, "inplace_updatable_int", 6, "_version_", 2L));
for (JettySolrRunner solrRunner : getSolrRunner(false)) {
try (SolrClient client = solrRunner.newClient()) {
for (UpdateRequest up : updates) {
up.process(client, collectionName);
}
}
}
JettySolrRunner oldLeaderJetty = getSolrRunner(true).get(0);
ChaosMonkey.kill(oldLeaderJetty);
waitForState("Replica not removed", collectionName, activeReplicaCount(0, 1, 0));
ChaosMonkey.start(oldLeaderJetty);
waitForState("Replica not added", collectionName, activeReplicaCount(0, 2, 0));
checkRTG(1, 1, cluster.getJettySolrRunners());
SolrDocument doc = cluster.getSolrClient().getById(collectionName, "1");
assertNotNull(doc.get("title_s"));
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class TopicStream method getPersistedCheckpoints.
private void getPersistedCheckpoints() throws IOException {
ZkStateReader zkStateReader = cloudSolrClient.getZkStateReader();
Collection<Slice> slices = CloudSolrStream.getSlices(checkpointCollection, zkStateReader, false);
ClusterState clusterState = zkStateReader.getClusterState();
Set<String> liveNodes = clusterState.getLiveNodes();
OUTER: for (Slice slice : slices) {
Collection<Replica> replicas = slice.getReplicas();
for (Replica replica : replicas) {
if (replica.getState() == Replica.State.ACTIVE && liveNodes.contains(replica.getNodeName())) {
HttpSolrClient httpClient = streamContext.getSolrClientCache().getHttpSolrClient(replica.getCoreUrl());
try {
SolrDocument doc = httpClient.getById(id);
if (doc != null) {
List<String> checkpoints = (List<String>) doc.getFieldValue("checkpoint_ss");
for (String checkpoint : checkpoints) {
String[] pair = checkpoint.split("~");
this.checkpoints.put(pair[0], Long.parseLong(pair[1]));
}
}
} catch (Exception e) {
throw new IOException(e);
}
break OUTER;
}
}
}
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class TestBinaryResponseWriter method testUUID.
/**
* Tests known types implementation by asserting correct encoding/decoding of UUIDField
*/
public void testUUID() throws Exception {
String s = UUID.randomUUID().toString().toLowerCase(Locale.ROOT);
assertU(adoc("id", "101", "uuid", s));
assertU(commit());
LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*");
SolrQueryResponse rsp = h.queryAndResponse(req.getParams().get(CommonParams.QT), req);
BinaryQueryResponseWriter writer = (BinaryQueryResponseWriter) h.getCore().getQueryResponseWriter("javabin");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.write(baos, req, rsp);
NamedList res = (NamedList) new JavaBinCodec().unmarshal(new ByteArrayInputStream(baos.toByteArray()));
SolrDocumentList docs = (SolrDocumentList) res.get("response");
for (Object doc : docs) {
SolrDocument document = (SolrDocument) doc;
assertEquals("Returned object must be a string", "java.lang.String", document.getFieldValue("uuid").getClass().getName());
assertEquals("Wrong UUID string returned", s, document.getFieldValue("uuid"));
}
req.close();
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class TestBinaryResponseWriter method testResolverSolrDocumentPartialFields.
public void testResolverSolrDocumentPartialFields() throws Exception {
LocalSolrQueryRequest req = lrf.makeRequest("q", "*:*", "fl", "id,xxx,ddd_s");
SolrDocument in = new SolrDocument();
in.addField("id", 345);
in.addField("aaa_s", "aaa");
in.addField("bbb_s", "bbb");
in.addField("ccc_s", "ccc");
in.addField("ddd_s", "ddd");
in.addField("eee_s", "eee");
Resolver r = new Resolver(req, new SolrReturnFields(req));
Object o = r.resolve(in, new JavaBinCodec());
assertNotNull("obj is null", o);
assertTrue("obj is not doc", o instanceof SolrDocument);
SolrDocument out = new SolrDocument();
for (Map.Entry<String, Object> e : in) {
if (r.isWritable(e.getKey()))
out.put(e.getKey(), e.getValue());
}
assertTrue("id not found", out.getFieldNames().contains("id"));
assertTrue("ddd_s not found", out.getFieldNames().contains("ddd_s"));
assertEquals("Wrong number of fields found", 2, out.getFieldNames().size());
req.close();
}
use of org.apache.solr.common.SolrDocument in project lucene-solr by apache.
the class TestJavabinTupleStreamParser method testSolrDocumentList.
public void testSolrDocumentList() throws IOException {
SolrQueryResponse response = new SolrQueryResponse();
SolrDocumentList l = constructSolrDocList(response);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new JavaBinCodec().marshal(response.getValues(), baos);
byte[] bytes = serialize(response.getValues());
Object o = new JavaBinCodec().unmarshal(new ByteArrayInputStream(bytes));
List list = new ArrayList<>();
Map m = null;
JavabinTupleStreamParser parser = new JavabinTupleStreamParser(new ByteArrayInputStream(bytes), false);
while ((m = parser.next()) != null) {
list.add(m);
}
assertEquals(l.size(), list.size());
for (int i = 0; i < list.size(); i++) {
compareSolrDocument(l.get(i), new SolrDocument((Map<String, Object>) list.get(i)));
}
}
Aggregations