use of com.yahoo.document.DocumentPut 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.DocumentPut 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.DocumentPut 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.DocumentPut in project vespa by vespa-engine.
the class CallbackTestCase method setUp.
public void setUp() {
service = new DocprocService("callback");
service.setCallStack(new CallStack().addNext(new TestCallbackDp()));
service.setInService(true);
// Create documents
DocumentType type = new DocumentType("test");
type.addField("status", DataType.STRING);
put1 = new DocumentPut(type, new DocumentId("doc:callback:test:1"));
put2 = new DocumentPut(type, new DocumentId("doc:callback:test:2"));
operations.add(new DocumentPut(type, new DocumentId("doc:callback:test:3")));
operations.add(new DocumentPut(type, new DocumentId("doc:callback:test:4")));
}
use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.
the class CallbackTestCase method testProcessingWithCallbackMultipleDocs.
public void testProcessingWithCallbackMultipleDocs() {
ProcessingEndpoint drecv = new TestProcessingEndpoint();
service.process(toProcessing(operations), drecv);
while (service.doWork()) {
}
assertEquals(new StringFieldValue("received"), ((DocumentPut) operations.get(0)).getDocument().getFieldValue("status"));
assertEquals(new StringFieldValue("received"), ((DocumentPut) operations.get(1)).getDocument().getFieldValue("status"));
}
Aggregations