Search in sources :

Example 61 with StringFieldValue

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

the class DocumentProcessingHandlerAllMessageTypesTestCase method batchDocumentUpdate.

private void batchDocumentUpdate() throws InterruptedException {
    DocumentUpdate doc1 = new DocumentUpdate(getType(), new DocumentId("userdoc:test:12345:multi:1"));
    DocumentUpdate doc2 = new DocumentUpdate(getType(), new DocumentId("userdoc:test:12345:multi:2"));
    Field testField = getType().getField("blahblah");
    doc1.addFieldUpdate(FieldUpdate.createAssign(testField, new StringFieldValue("1 not yet processed")));
    doc2.addFieldUpdate(FieldUpdate.createAssign(testField, new StringFieldValue("2 not yet processed")));
    BatchDocumentUpdateMessage message = new BatchDocumentUpdateMessage(12345);
    message.addUpdate(doc1);
    message.addUpdate(doc2);
    assertTrue(sendMessage(FOOBAR, message));
    Message remote1 = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertTrue(remote1 instanceof UpdateDocumentMessage);
    remoteServer.ackMessage(remote1);
    assertNull(driver.client().awaitReply(100, TimeUnit.MILLISECONDS));
    Message remote2 = remoteServer.awaitMessage(60, TimeUnit.SECONDS);
    assertTrue(remote2 instanceof UpdateDocumentMessage);
    remoteServer.ackMessage(remote2);
    Reply reply = driver.client().awaitReply(60, TimeUnit.SECONDS);
    assertNotNull(reply);
    assertFalse(reply.hasErrors());
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) Message(com.yahoo.messagebus.Message) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) BatchDocumentUpdateMessage(com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) BatchDocumentUpdateMessage(com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage) Reply(com.yahoo.messagebus.Reply) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)

Example 62 with StringFieldValue

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

the class SplitterJoinerTestCase method testSplitJoin.

@Test
public void testSplitJoin() {
    ConfigGetter<SplitterJoinerDocumentProcessorConfig> getter = new ConfigGetter<>(SplitterJoinerDocumentProcessorConfig.class);
    ConfigGetter<DocumentmanagerConfig> docManGetter = new ConfigGetter<>(DocumentmanagerConfig.class);
    SplitterJoinerDocumentProcessorConfig cfg = getter.getConfig("file:src/test/java/com/yahoo/docproc/util/splitter-joiner-document-processor.cfg");
    DocumentmanagerConfig docManCfg = docManGetter.getConfig("file:src/test/java/com/yahoo/docproc/util/documentmanager.docindoc.cfg");
    SplitterDocumentProcessor splitter = new SplitterDocumentProcessor(cfg, docManCfg);
    DocumentTypeManager manager = splitter.manager;
    /**
     ** Create documents: ***
     */
    Document inner1 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:one");
    inner1.setFieldValue("name", new StringFieldValue("Donald Duck"));
    inner1.setFieldValue("content", new StringFieldValue("Lives in Duckburg"));
    Document inner2 = new Document(manager.getDocumentType("docindoc"), "doc:inner:number:two");
    inner2.setFieldValue("name", new StringFieldValue("Uncle Scrooge"));
    inner2.setFieldValue("content", new StringFieldValue("Lives in Duckburg, too."));
    Array<Document> innerArray = (Array<Document>) manager.getDocumentType("outerdoc").getField("innerdocuments").getDataType().createFieldValue();
    innerArray.add(inner1);
    innerArray.add(inner2);
    Document outer = new Document(manager.getDocumentType("outerdoc"), "doc:outer:the:only:one");
    outer.setFieldValue("innerdocuments", innerArray);
    /**
     ** End create documents ***
     */
    Processing p = Processing.of(new DocumentPut(outer));
    splitter.process(p);
    assertEquals(2, p.getDocumentOperations().size());
    assertThat(((DocumentPut) (p.getDocumentOperations().get(0))).getDocument(), sameInstance(inner1));
    assertThat(((DocumentPut) (p.getDocumentOperations().get(1))).getDocument(), sameInstance(inner2));
    assertThat(((DocumentPut) (p.getVariable(cfg.contextFieldName()))).getDocument(), sameInstance(outer));
    assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray));
    assertTrue(innerArray.isEmpty());
    JoinerDocumentProcessor joiner = new JoinerDocumentProcessor(cfg, docManCfg);
    joiner.process(p);
    assertThat(p.getDocumentOperations().size(), equalTo(1));
    assertThat(((DocumentPut) p.getDocumentOperations().get(0)).getDocument(), sameInstance(outer));
    assertThat(p.getVariable(cfg.contextFieldName()), nullValue());
    assertThat(outer.getFieldValue("innerdocuments"), sameInstance(innerArray));
    assertThat(innerArray.size(), equalTo(2));
    assertThat(innerArray.get(0), sameInstance(inner1));
    assertThat(innerArray.get(1), sameInstance(inner2));
}
Also used : ConfigGetter(com.yahoo.config.subscription.ConfigGetter) DocumentPut(com.yahoo.document.DocumentPut) SplitterJoinerDocumentProcessorConfig(com.yahoo.config.docproc.SplitterJoinerDocumentProcessorConfig) Document(com.yahoo.document.Document) Processing(com.yahoo.docproc.Processing) Array(com.yahoo.document.datatypes.Array) DocumentmanagerConfig(com.yahoo.document.config.DocumentmanagerConfig) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) Test(org.junit.Test)

Example 63 with StringFieldValue

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

the class FailingDocumentProcessingWithoutExceptionTestCase method assertProcessingWorks.

protected void assertProcessingWorks(DocprocService service) {
    // Create documents
    DocumentType type = new DocumentType("test");
    type.addField("test", DataType.STRING);
    DocumentPut put1 = new DocumentPut(type, new DocumentId("doc:woexception:test:1"));
    DocumentPut put2 = new DocumentPut(type, new DocumentId("doc:woexception:test:2"));
    DocumentPut put3 = new DocumentPut(type, new DocumentId("doc:woexception:test:3"));
    // Process them
    service.process(put1);
    service.process(put2);
    service.process(put3);
    while (service.doWork()) {
    }
    // Verify
    assertEquals(new StringFieldValue("done 3"), put1.getDocument().getFieldValue("test"));
    // Due to PROCESSING_FAILED in 2
    assertEquals(new StringFieldValue("done 2"), put2.getDocument().getFieldValue("test"));
    assertEquals(new StringFieldValue("done 3"), put3.getDocument().getFieldValue("test"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType)

Example 64 with StringFieldValue

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

the class ProcessingUpdateTestCase method testProcessingUpdates.

public void testProcessingUpdates() {
    DocumentType articleType = new DocumentType("article");
    articleType.addField(new Field("body", DataType.STRING, true));
    articleType.addField(new Field("title", DataType.STRING, true));
    dtm = new DocumentTypeManager();
    dtm.registerDocumentType(articleType);
    put = new DocumentPut(articleType, "doc:banana:apple");
    put.getDocument().setFieldValue("body", "this is the body of the article, blah blah blah");
    FieldUpdate upd = FieldUpdate.createAssign(articleType.getField("body"), new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"));
    update = new DocumentUpdate(articleType, new DocumentId("doc:grape:orange"));
    update.addFieldUpdate(upd);
    DocprocService service = new DocprocService("update");
    DocumentProcessor firstP = new TitleDocumentProcessor();
    service.setCallStack(new CallStack().addLast(firstP));
    service.setInService(true);
    Processing p = new Processing();
    p.addDocumentOperation(put);
    p.addDocumentOperation(update);
    service.process(p);
    while (service.doWork()) {
    }
    List<DocumentOperation> operations = p.getDocumentOperations();
    Document first = ((DocumentPut) operations.get(0)).getDocument();
    assertEquals(new StringFieldValue("this is the body of the article, blah blah blah"), first.getFieldValue("body"));
    assertEquals(new StringFieldValue("body blah blah blah "), first.getFieldValue("title"));
    DocumentUpdate second = (DocumentUpdate) operations.get(1);
    FieldUpdate firstUpd = second.getFieldUpdate(0);
    assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, firstUpd.getValueUpdate(0).getValueUpdateClassID());
    assertEquals(new StringFieldValue("this is the updated body of the article, blahdi blahdi blahdi"), firstUpd.getValueUpdate(0).getValue());
    FieldUpdate secondUpd = second.getFieldUpdate(1);
    assertEquals(ValueUpdate.ValueUpdateClassID.ASSIGN, secondUpd.getValueUpdate(0).getValueUpdateClassID());
    assertEquals(new StringFieldValue("body blahdi blahdi blahdi "), secondUpd.getValueUpdate(0).getValue());
}
Also used : DocumentOperation(com.yahoo.document.DocumentOperation) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType) Document(com.yahoo.document.Document) Field(com.yahoo.document.Field) DocumentUpdate(com.yahoo.document.DocumentUpdate) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentTypeManager(com.yahoo.document.DocumentTypeManager) FieldUpdate(com.yahoo.document.update.FieldUpdate)

Example 65 with StringFieldValue

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

the class DocumentProcessingAbstractTestCase method assertProcessingWorks.

/**
 * Asserts that a document processing service works
 */
protected void assertProcessingWorks(DocprocService service) {
    // Create documents
    DocumentType type = new DocumentType("test");
    type.addField("test", DataType.STRING);
    DocumentPut put1 = new DocumentPut(type, new DocumentId("doc:test:test:1"));
    DocumentPut put2 = new DocumentPut(type, new DocumentId("doc:test:test:2"));
    DocumentPut put3 = new DocumentPut(type, new DocumentId("doc:test:test:3"));
    // Process them
    service.process(put1);
    service.process(put2);
    service.process(put3);
    while (service.doWork()) {
    }
    // Verify
    assertEquals(new StringFieldValue("done"), put1.getDocument().getFieldValue("test"));
    assertEquals(new StringFieldValue("done"), put2.getDocument().getFieldValue("test"));
    assertEquals(new StringFieldValue("done"), put3.getDocument().getFieldValue("test"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType)

Aggregations

StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)210 Test (org.junit.Test)136 FieldValue (com.yahoo.document.datatypes.FieldValue)49 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)40 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)37 Document (com.yahoo.document.Document)30 Array (com.yahoo.document.datatypes.Array)25 DocumentType (com.yahoo.document.DocumentType)21 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)21 Struct (com.yahoo.document.datatypes.Struct)21 DocumentPut (com.yahoo.document.DocumentPut)20 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)20 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)18 SpanTree (com.yahoo.document.annotation.SpanTree)15 FieldUpdate (com.yahoo.document.update.FieldUpdate)15 DocumentUpdate (com.yahoo.document.DocumentUpdate)12 Field (com.yahoo.document.Field)12 Annotation (com.yahoo.document.annotation.Annotation)12 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)12 HashMap (java.util.HashMap)12