use of com.yahoo.document.Document in project vespa by vespa-engine.
the class DocumentRetriever method printReply.
private void printReply(Reply reply) {
Trace trace = reply.getTrace();
if (!trace.getRoot().isEmpty()) {
System.out.println(trace);
}
if (reply.hasErrors()) {
System.err.print("Request failed: ");
for (int i = 0; i < reply.getNumErrors(); i++) {
System.err.printf("\n %s", reply.getError(i));
}
System.err.println();
return;
}
if (!(reply instanceof GetDocumentReply)) {
System.err.printf("Unexpected reply %s: '%s'\n", reply.getType(), reply.toString());
return;
}
GetDocumentReply documentReply = (GetDocumentReply) reply;
Document document = documentReply.getDocument();
if (document == null) {
System.out.println("Document not found.");
return;
}
if (params.showDocSize) {
System.out.printf("Document size: %d bytes.\n", document.getSerializedSize());
}
if (params.printIdsOnly) {
System.out.println(document.getId());
} else {
if (params.jsonOutput) {
System.out.print(Utf8.toString(JsonWriter.toByteArray(document)));
} else {
System.out.print(document.toXML(" "));
}
}
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class DocumentRetrieverTest method testShowDocSize.
@Test
public void testShowDocSize() throws DocumentRetrieverException {
ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).setShowDocSize(true).build();
Document document = new Document(DataType.DOCUMENT, new DocumentId(DOC_ID_1));
when(mockedSession.syncSend(any())).thenReturn(new GetDocumentReply(document));
DocumentRetriever documentRetriever = createDocumentRetriever(params);
documentRetriever.retrieveDocuments();
assertTrue(outContent.toString().contains(String.format("Document size: %d bytes", document.getSerializedSize())));
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class DocumentRetrieverTest method testTrace.
@Test
public void testTrace() throws DocumentRetrieverException {
final int traceLevel = 9;
ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).setTraceLevel(traceLevel).build();
GetDocumentReply reply = new GetDocumentReply(new Document(DataType.DOCUMENT, new DocumentId(DOC_ID_1)));
reply.getTrace().getRoot().addChild("childnode");
when(mockedSession.syncSend(any())).thenReturn(reply);
DocumentRetriever documentRetriever = createDocumentRetriever(params);
documentRetriever.retrieveDocuments();
verify(mockedSession, times(1)).setTraceLevel(traceLevel);
assertTrue(outContent.toString().contains("<trace>"));
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class SchemaMappingAndAccessesTest method testMappingSpanTrees.
public void testMappingSpanTrees() {
Document doc = getDoc();
Map<String, String> fieldMap = new HashMap<>();
fieldMap.put("t", "title");
fieldMap.put("a", "artist");
fieldMap.put("g", "guitarist");
ProxyDocument mapped = new ProxyDocument(new TestDocumentProcessor1(), doc, fieldMap);
Iterator<SpanTree> itSpanTreesDoc = ((StringFieldValue) doc.getFieldValue("artist")).getSpanTrees().iterator();
Iterator<Annotation> itAnnotDoc = itSpanTreesDoc.next().iterator();
Iterator<SpanTree> itSpanTreesMapped = ((StringFieldValue) mapped.getFieldValue("artist")).getSpanTrees().iterator();
Iterator<Annotation> itAnnotMapped = itSpanTreesMapped.next().iterator();
assertEquals(itAnnotDoc.next().getType().getName(), "person");
assertFalse(itAnnotDoc.hasNext());
assertEquals(itAnnotMapped.next().getType().getName(), "person");
assertFalse(itAnnotMapped.hasNext());
AnnotationType guitaristType = new AnnotationType("guitarist");
Annotation guitarist = new Annotation(guitaristType);
StringFieldValue bona = new StringFieldValue("Bonamassa");
bona.setSpanTree(new SpanTree("mytree").annotate(guitarist));
StringFieldValue clapton = new StringFieldValue("Clapton");
mapped.setFieldValue("a", bona);
mapped.setFieldValue("g", clapton);
itSpanTreesDoc = ((StringFieldValue) doc.getFieldValue("artist")).getSpanTrees().iterator();
itAnnotDoc = itSpanTreesDoc.next().iterator();
itSpanTreesMapped = ((StringFieldValue) mapped.getFieldValue("artist")).getSpanTrees().iterator();
itAnnotMapped = itSpanTreesMapped.next().iterator();
assertEquals(itAnnotDoc.next().getType().getName(), "guitarist");
assertFalse(itAnnotDoc.hasNext());
assertEquals(itAnnotMapped.next().getType().getName(), "guitarist");
assertFalse(itAnnotMapped.hasNext());
assertSame(((StringFieldValue) doc.getFieldValue("artist")).getSpanTrees().iterator().next(), ((StringFieldValue) mapped.getFieldValue("a")).getSpanTrees().iterator().next());
// assertSame(clapton, mapped.getFieldValue("g"));
// assertSame(bona, mapped.getFieldValue("a"));
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class SchemaMappingAndAccessesTest method testProxyAndSecureSecureFailing.
public void testProxyAndSecureSecureFailing() {
DocumentProcessor procInsecure = new TestDPInsecure();
Map<Pair<String, String>, String> fieldMap = new HashMap<>();
fieldMap.put(new Pair<>("album", "titleMapped"), "title");
procInsecure.setFieldMap(fieldMap);
DocumentPut put = new DocumentPut(getDoc());
Document doc = new Call(procInsecure).configDoc(procInsecure, put).getDocument();
try {
procInsecure.process(Processing.of(new DocumentPut(doc)));
fail("Insecure docproc went through");
} catch (Exception e) {
assertTrue(e.getMessage().matches(".*allowed.*"));
}
// assertEquals(doc.get("title"), "MyTitle");
}
Aggregations