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();
}
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();
}
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();
}
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());
}
}
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!"));
}
}
Aggregations