Search in sources :

Example 51 with DocumentId

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

the class ReferenceFieldValueTestCase method can_explicitly_set_new_id_for_existing_reference.

@Test
public void can_explicitly_set_new_id_for_existing_reference() {
    ReferenceFieldValue value = new ReferenceFieldValue(referenceTypeFoo());
    DocumentId newId = docId("id:ns:foo::wario-time");
    value.setDocumentId(newId);
    assertTrue(value.getDocumentId().isPresent());
    assertEquals(newId, value.getDocumentId().get());
}
Also used : DocumentId(com.yahoo.document.DocumentId) Test(org.junit.Test)

Example 52 with DocumentId

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

the class StoragePolicyTestEnvironment method createMessage.

protected static Message createMessage(String id) {
    Message msg = new RemoveDocumentMessage(new DocumentId(id));
    msg.getTrace().setLevel(9);
    return msg;
}
Also used : Message(com.yahoo.messagebus.Message) DocumentId(com.yahoo.document.DocumentId)

Example 53 with DocumentId

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

the class JsonReader method readSingleDocument.

/**
 * Reads a single operation. The operation is not expected to be part of an array.
 * @param operationType the type of operation (update or put)
 * @param docIdString document ID.
 * @return the document
 */
public DocumentOperation readSingleDocument(DocumentParser.SupportedOperation operationType, String docIdString) {
    DocumentId docId = new DocumentId(docIdString);
    final DocumentParseInfo documentParseInfo;
    try {
        DocumentParser documentParser = new DocumentParser(parser);
        documentParseInfo = documentParser.parse(Optional.of(docId)).get();
    } catch (IOException e) {
        state = END_OF_FEED;
        throw new RuntimeException(e);
    }
    documentParseInfo.operationType = operationType;
    VespaJsonDocumentReader vespaJsonDocumentReader = new VespaJsonDocumentReader();
    DocumentOperation operation = vespaJsonDocumentReader.createDocumentOperation(getDocumentTypeFromString(documentParseInfo.documentId.getDocType(), typeManager), documentParseInfo);
    operation.setCondition(TestAndSetCondition.fromConditionString(documentParseInfo.condition));
    return operation;
}
Also used : DocumentParser(com.yahoo.document.json.document.DocumentParser) DocumentOperation(com.yahoo.document.DocumentOperation) DocumentId(com.yahoo.document.DocumentId) IOException(java.io.IOException) DocumentParseInfo(com.yahoo.document.json.readers.DocumentParseInfo) VespaJsonDocumentReader(com.yahoo.document.json.readers.VespaJsonDocumentReader)

Example 54 with DocumentId

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

the class MessageBusVisitorSessionTestCase method testFailureOnUnknownReplyType.

/**
 * Test branch where we don't know how to handle a certain reply type.
 * This should never happen (since we only get replies for messages we've
 * already sent) but deal with it anyway!
 */
@Test
public void testFailureOnUnknownReplyType() {
    MockComponents mc = createDefaultMock("id.user==1234");
    mc.visitorSession.start();
    mc.controlHandler.resetMock();
    mc.executor.expectAndProcessTasks(1);
    mc.sender.getAndRemoveMessage(0);
    // Make a bogus reply that we never asked for
    RemoveDocumentMessage msg = new RemoveDocumentMessage(new DocumentId("doc:foo:bar"));
    DocumentReply reply = msg.createReply();
    mc.sender.reply(reply);
    // reply
    mc.executor.expectAndProcessTasks(1);
    mc.executor.expectNoTasks();
    assertEquals(0, mc.sender.getMessageCount());
    assertTrue(mc.visitorSession.isDone());
    assertEquals("onDone : FAILURE - 'Received reply we do not know how to " + "handle: com.yahoo.documentapi.messagebus.protocol.RemoveDocumentReply'\n", mc.controlHandler.toString());
}
Also used : DocumentId(com.yahoo.document.DocumentId) Test(org.junit.Test)

Example 55 with DocumentId

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

the class MessageBusVisitorSessionTestCase method testSkipBucketOnFatalMessageProcessingError.

@Test
public void testSkipBucketOnFatalMessageProcessingError() {
    VisitorParameters visitorParameters = createVisitorParameters("id.user==1234");
    visitorParameters.skipBucketsOnFatalErrors(true);
    MockComponents mc = createDefaultMock(visitorParameters);
    mc.controlHandler.resetMock();
    mc.dataHandler.resetMock();
    mc.dataHandler.setExceptionOnMessage(new IllegalArgumentException("oh no"));
    mc.visitorSession.start();
    mc.executor.expectAndProcessTasks(1);
    mc.receiver.send(new RemoveDocumentMessage(new DocumentId("doc:foo:bar")));
    mc.executor.expectAndProcessTasks(1);
    assertEquals(1, mc.dataHandler.getMessages().size());
    // NOTE: current behavior does _not_ fail the session at the end of
    // visiting if the CreateVisitor replies do not also return with failure
    // since this is tied to the ProgressToken and its failed buckets list.
    // We make the simplifying assumption that failing a visitor _message_
    // will subsequently cause its reply to fail back to us, allowing us to
    // handle this as a regular skippable bucket.
    // TODO: reconsider this?
    replyErrorToCreateVisitor(mc.sender, new Error(DocumentProtocol.ERROR_INTERNAL_FAILURE, "The Borkening"));
    mc.executor.expectAndProcessTasks(1);
    mc.executor.expectNoTasks();
    assertTrue(mc.controlHandler.isDone());
    // Get UNPARSEABLE rather than APP_FATAL_ERROR if skip buckets is set
    assertEquals("RemoveDocumentReply(UNPARSEABLE: Got exception of type java.lang.IllegalArgumentException " + "with message 'oh no' while processing DocumentMessage)\n", mc.receiver.repliesToString());
    assertEquals("onVisitorError : INTERNAL_FAILURE: The Borkening\n" + "onDone : FAILURE - 'INTERNAL_FAILURE: The Borkening'\n", mc.controlHandler.toString());
    assertEquals("FAILURE: INTERNAL_FAILURE: The Borkening", mc.controlHandler.getResult().toString());
}
Also used : DocumentId(com.yahoo.document.DocumentId) Error(com.yahoo.messagebus.Error) Test(org.junit.Test)

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