use of com.yahoo.document.Document in project vespa by vespa-engine.
the class IndexingProcessorTestCase method requireThatIndexerProcessesDocuments.
@Test
public void requireThatIndexerProcessesDocuments() {
Document input = new Document(indexer.getDocumentTypeManager().getDocumentType("music"), "doc:scheme:");
input.setFieldValue("artist", new StringFieldValue("69"));
DocumentOperation op = process(new DocumentPut(input));
assertTrue(op instanceof DocumentPut);
Document output = ((DocumentPut) op).getDocument();
assertEquals(new StringFieldValue("69"), output.getFieldValue("title"));
assertEquals("music", output.getDataType().getName());
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class DocumentProcessingHandlerBasicTestCase method testPut.
@Test
public void testPut() throws InterruptedException {
Document document = new Document(getType(), "doc:yalla:balla");
document.setFieldValue("blahblah", new StringFieldValue("This is a test."));
PutDocumentMessage message = new PutDocumentMessage(new DocumentPut(document));
assertTrue(sendMessage("foobar", message));
Message msg = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
assertNotNull(msg);
remoteServer.ackMessage(msg);
Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
assertNotNull(reply);
assertThat((msg instanceof PutDocumentMessage), is(true));
PutDocumentMessage put = (PutDocumentMessage) msg;
Document outDoc = put.getDocumentPut().getDocument();
assertThat(document, equalTo(outDoc));
assertFalse(reply.hasErrors());
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class SplitterDocumentProcessor method doProcessOuterDocument.
static boolean doProcessOuterDocument(Object o, String documentTypeName) {
if (!(o instanceof DocumentOperation)) {
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, o + " is not a DocumentOperation.");
}
return false;
}
DocumentOperation outerDocOp = (DocumentOperation) o;
if (!(outerDocOp instanceof DocumentPut)) {
// this is not a put, return
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Given DocumentOperation is not a DocumentPut, returning. (Was given " + outerDocOp + ").");
}
return false;
}
Document outerDoc = ((DocumentPut) outerDocOp).getDocument();
DocumentType type = outerDoc.getDataType();
if (!type.getName().equalsIgnoreCase(documentTypeName)) {
// this is not the right document type
if (log.isLoggable(LogLevel.DEBUG)) {
log.log(LogLevel.DEBUG, "Given Document is of wrong type, returning. (Was given " + outerDoc + ").");
}
return false;
}
return true;
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class AccessesAnnotationTestCase method requireThatFieldsAreRestricted.
@Test
public void requireThatFieldsAreRestricted() {
DocumentType type = new DocumentType("album");
type.addField("title", DataType.STRING);
type.addField("artist", DataType.STRING);
type.addField("year", DataType.INT);
Document doc = new Document(type, new DocumentId("doc:map:test:1"));
MyDocProc docProc = new MyDocProc();
DocumentPut put = new DocumentPut(doc);
Document proxy = new Call(docProc).configDoc(docProc, put).getDocument();
proxy.setFieldValue("title", new StringFieldValue("foo"));
try {
proxy.setFieldValue("year", new IntegerFieldValue(69));
fail("Should have failed");
} catch (Exception e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().matches(".*not allowed.*"));
}
proxy.getFieldValue("title");
try {
proxy.getFieldValue("year");
fail("Should have failed");
} catch (Exception e) {
System.out.println(e.getMessage());
assertTrue(e.getMessage().matches(".*not allowed.*"));
}
}
use of com.yahoo.document.Document in project vespa by vespa-engine.
the class JoinerDocumentProcessor method process.
@Override
public Progress process(Processing processing) {
if (!doProcessOuterDocument(processing.getVariable(contextFieldName), documentTypeName)) {
return Progress.DONE;
}
DocumentPut outerDoc = (DocumentPut) processing.getVariable(contextFieldName);
@SuppressWarnings("unchecked") Array<Document> innerDocuments = (Array<Document>) outerDoc.getDocument().getFieldValue(arrayFieldName);
if (innerDocuments == null) {
@SuppressWarnings("unchecked") Array<Document> empty = (Array<Document>) outerDoc.getDocument().getDataType().getField(arrayFieldName).getDataType().createFieldValue();
innerDocuments = empty;
}
for (DocumentOperation op : processing.getDocumentOperations()) {
if (op instanceof DocumentPut) {
innerDocuments.add(((DocumentPut) op).getDocument());
} else {
log.log(LogLevel.DEBUG, "Skipping: " + op);
}
}
processing.getDocumentOperations().clear();
processing.getDocumentOperations().add(outerDoc);
processing.removeVariable(contextFieldName);
return Progress.DONE;
}
Aggregations