Search in sources :

Example 41 with DocumentPut

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());
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) Message(com.yahoo.messagebus.Message) PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) Reply(com.yahoo.messagebus.Reply) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 42 with DocumentPut

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;
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document)

Example 43 with DocumentPut

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.*"));
    }
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentId(com.yahoo.document.DocumentId) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 44 with DocumentPut

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")));
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType)

Example 45 with DocumentPut

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"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut)

Aggregations

DocumentPut (com.yahoo.document.DocumentPut)67 Document (com.yahoo.document.Document)40 DocumentType (com.yahoo.document.DocumentType)35 Test (org.junit.Test)30 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)23 ByteArrayInputStream (java.io.ByteArrayInputStream)21 InputStream (java.io.InputStream)21 DocumentParseInfo (com.yahoo.document.json.readers.DocumentParseInfo)16 VespaJsonDocumentReader (com.yahoo.document.json.readers.VespaJsonDocumentReader)16 DocumentOperation (com.yahoo.document.DocumentOperation)13 DocumentId (com.yahoo.document.DocumentId)12 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)11 FieldValue (com.yahoo.document.datatypes.FieldValue)10 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)10 TensorFieldValue (com.yahoo.document.datatypes.TensorFieldValue)10 DocumentRemove (com.yahoo.document.DocumentRemove)8 DocumentUpdate (com.yahoo.document.DocumentUpdate)7 Array (com.yahoo.document.datatypes.Array)7 DocumentProcessor (com.yahoo.docproc.DocumentProcessor)6 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)5