Search in sources :

Example 26 with DocumentPut

use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.

the class JsonReaderTestCase method createPutWithTensor.

private DocumentPut createPutWithTensor(String inputTensor, String tensorFieldName) {
    InputStream rawDoc = new ByteArrayInputStream(Utf8.toBytes("[" + "  { \"put\": \"" + TENSOR_DOC_ID + "\", \"fields\": { \"" + tensorFieldName + "\": " + inputTensor + "  }}" + "]"));
    JsonReader reader = new JsonReader(types, rawDoc, parserFactory);
    return (DocumentPut) reader.next();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut)

Example 27 with DocumentPut

use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.

the class JsonWriterTestCase method readDocumentFromJson.

private Document readDocumentFromJson(String docId, String fields) throws IOException {
    InputStream rawDoc = new ByteArrayInputStream(asFeed(docId, fields));
    JsonReader r = new JsonReader(types, rawDoc, parserFactory);
    DocumentParseInfo raw = r.parseDocument().get();
    DocumentType docType = r.readDocumentType(raw.documentId);
    DocumentPut put = new DocumentPut(new Document(docType, raw.documentId));
    new VespaJsonDocumentReader().readPut(raw.fieldsBuffer, put);
    return put.getDocument();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader)

Example 28 with DocumentPut

use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.

the class AbstractDocumentApiTestCase method requireThatSyncSessionWorks.

@Test
public void requireThatSyncSessionWorks() {
    SyncSession session = access().createSyncSession(new SyncParameters());
    DocumentType type = access().getDocumentTypeManager().getDocumentType("music");
    Document doc1 = new Document(type, new DocumentId("doc:music:1"));
    Document doc2 = new Document(type, new DocumentId("doc:music:2"));
    session.put(new DocumentPut(doc1));
    session.put(new DocumentPut(doc2));
    assertEquals(doc1, session.get(new DocumentId("doc:music:1")));
    assertEquals(doc2, session.get(new DocumentId("doc:music:2")));
    session.remove(new DocumentRemove(new DocumentId("doc:music:1")));
    assertNull(session.get(new DocumentId("doc:music:1")));
    assertEquals(doc2, session.get(new DocumentId("doc:music:2")));
    session.remove(new DocumentRemove(new DocumentId("doc:music:2")));
    assertNull(session.get(new DocumentId("doc:music:1")));
    assertNull(session.get(new DocumentId("doc:music:2")));
    session.destroy();
}
Also used : DocumentRemove(com.yahoo.document.DocumentRemove) DocumentId(com.yahoo.document.DocumentId) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 29 with DocumentPut

use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.

the class ApplicationTest method client.

@Test
public void client() throws Exception {
    try (ApplicationFacade app = new ApplicationFacade(Application.fromBuilder(new Application.Builder().documentType("test", IOUtils.toString(this.getClass().getResourceAsStream("/test.sd"))).container("default", new Application.Builder.Container().client("mbus://*/*", MockClient.class).documentProcessor(MockDispatchDocproc.class))))) {
        Map<String, DocumentType> typeMap = app.application().getJDisc("jdisc").documentProcessing().getDocumentTypes();
        assertNotNull(typeMap);
        DocumentType docType = typeMap.get("test");
        Document doc = new Document(docType, "id:foo:test::bar");
        doc.setFieldValue("title", "hello");
        assertEquals(DocumentProcessor.Progress.DONE, app.process(new DocumentPut(doc)));
        MockClient client = (MockClient) app.getClientById(MockClient.class.getName());
        assertNotNull(client);
        assertEquals(1, client.getCounter());
        MockDispatchDocproc docproc = (MockDispatchDocproc) app.getComponentById(MockDispatchDocproc.class.getName() + "@default");
        assertNotNull(docproc);
        assertEquals(1, docproc.getResponses().size());
        assertEquals(200, docproc.getResponses().get(0).getStatus());
    }
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) MockDispatchDocproc(com.yahoo.application.container.docprocs.MockDispatchDocproc) Document(com.yahoo.document.Document) MockClient(com.yahoo.application.container.MockClient) Test(org.junit.Test)

Example 30 with DocumentPut

use of com.yahoo.document.DocumentPut in project vespa by vespa-engine.

the class JDiscContainerDocprocTest method requireThatBasicDocumentProcessingWorks.

@Test
public void requireThatBasicDocumentProcessingWorks() throws Exception {
    try (Application app = new ApplicationBuilder().servicesXml(getXML(CHAIN_NAME, Rot13DocumentProcessor.class.getCanonicalName())).documentType("music", DOCUMENT).build()) {
        JDisc container = app.getJDisc("container");
        DocumentProcessing docProc = container.documentProcessing();
        DocumentType type = docProc.getDocumentTypes().get("music");
        ChainRegistry<DocumentProcessor> chains = docProc.getChains();
        assertTrue(chains.allComponentsById().containsKey(new ComponentId(CHAIN_NAME)));
        Document doc = new Document(type, "doc:this:is:a:great:album");
        doc.setFieldValue("title", "Great Album!");
        com.yahoo.docproc.Processing processing;
        DocumentProcessor.Progress progress;
        DocumentPut put = new DocumentPut(doc);
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Terng Nyohz!"));
        processing = com.yahoo.docproc.Processing.of(put);
        progress = docProc.process(ComponentSpecification.fromString(CHAIN_NAME), processing);
        assertThat(progress, sameInstance(DocumentProcessor.Progress.DONE));
        assertThat(doc.getFieldValue("title").toString(), equalTo("Great Album!"));
    }
}
Also used : Rot13DocumentProcessor(com.yahoo.application.container.docprocs.Rot13DocumentProcessor) DocumentProcessor(com.yahoo.docproc.DocumentProcessor) DocumentPut(com.yahoo.document.DocumentPut) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) ApplicationBuilder(com.yahoo.application.ApplicationBuilder) Application(com.yahoo.application.Application) ComponentId(com.yahoo.component.ComponentId) Test(org.junit.Test)

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