Search in sources :

Example 16 with DocumentId

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

the class TransientFailureTestCase method testTransientFailures.

public void testTransientFailures() {
    DocprocService service = new DocprocService("transfail");
    CallStack stack = new CallStack();
    stack.addNext(new OkDocProc()).addNext(new TransientFailDocProc());
    service.setCallStack(stack);
    service.setInService(true);
    EndpointSupportingTransientFailures endpoint = new EndpointSupportingTransientFailures();
    DocumentPut put;
    put = new DocumentPut(type, new DocumentId("doc:transfail:bad"));
    service.process(put, endpoint);
    while (service.doWork()) {
    }
    assertEquals(0, endpoint.numOk);
    assertEquals(1, endpoint.numTransientFail);
    assertEquals(0, endpoint.numFail);
    put = new DocumentPut(type, new DocumentId("doc:transfail:verybad"));
    service.process(put, endpoint);
    while (service.doWork()) {
    }
    assertEquals(0, endpoint.numOk);
    assertEquals(1, endpoint.numTransientFail);
    assertEquals(1, endpoint.numFail);
    put = new DocumentPut(type, new DocumentId("doc:transfail:good"));
    service.process(put, endpoint);
    while (service.doWork()) {
    }
    assertEquals(1, endpoint.numOk);
    assertEquals(1, endpoint.numTransientFail);
    assertEquals(1, endpoint.numFail);
    put = new DocumentPut(type, new DocumentId("doc:transfail:veryverybad"));
    service.process(put, endpoint);
    while (service.doWork()) {
    }
    assertEquals(1, endpoint.numOk);
    assertEquals(1, endpoint.numTransientFail);
    assertEquals(2, endpoint.numFail);
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId)

Example 17 with DocumentId

use of com.yahoo.document.DocumentId 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 18 with DocumentId

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

the class FailingWithErrorTestCase method testErrors.

public void testErrors() {
    DocprocService service = new DocprocService("failing");
    DocumentProcessor first = new ErrorThrowingProcessor();
    service.setCallStack(new CallStack().addLast(first));
    service.setInService(true);
    DocumentType type = new DocumentType("test");
    type.addField("test", DataType.STRING);
    DocumentPut put = new DocumentPut(type, new DocumentId("doc:failing:test:1"));
    put.getDocument().setFieldValue("test", "foobar");
    service.process(put);
    assertEquals(1, service.getQueueSize());
    try {
        while (service.doWork()) {
        }
        fail("Should have gotten OOME here");
    } catch (Throwable t) {
        // we don't want a finally block in doWork()!
        assertEquals(0, service.getQueueSize());
    }
    assertEquals(0, service.getQueueSize());
}
Also used : DocumentPut(com.yahoo.document.DocumentPut) DocumentId(com.yahoo.document.DocumentId) DocumentType(com.yahoo.document.DocumentType)

Example 19 with DocumentId

use of com.yahoo.document.DocumentId 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 20 with DocumentId

use of com.yahoo.document.DocumentId 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

DocumentId (com.yahoo.document.DocumentId)61 Test (org.junit.Test)28 DocumentType (com.yahoo.document.DocumentType)20 Document (com.yahoo.document.Document)16 DocumentPut (com.yahoo.document.DocumentPut)12 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)9 BucketId (com.yahoo.document.BucketId)7 DocumentRemove (com.yahoo.document.DocumentRemove)5 DocumentUpdate (com.yahoo.document.DocumentUpdate)5 BucketIdFactory (com.yahoo.document.BucketIdFactory)4 FieldUpdate (com.yahoo.document.update.FieldUpdate)4 DocumentOperation (com.yahoo.document.DocumentOperation)3 FastHit (com.yahoo.prelude.fastsearch.FastHit)3 Hit (com.yahoo.search.result.Hit)3 HashMap (java.util.HashMap)3 TestDocumentProcessor1 (com.yahoo.docproc.DocumentProcessingAbstractTestCase.TestDocumentProcessor1)2 Field (com.yahoo.document.Field)2 GlobalId (com.yahoo.document.GlobalId)2 StructDataType (com.yahoo.document.StructDataType)2 Struct (com.yahoo.document.datatypes.Struct)2