Search in sources :

Example 1 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class QueueAdapterTestCase method requireThatAccessorsWork.

@Test
public void requireThatAccessorsWork() {
    QueueAdapter queue = new QueueAdapter();
    assertTrue(queue.isEmpty());
    assertEquals(0, queue.size());
    Message msg = new MyMessage();
    queue.handleMessage(msg);
    assertFalse(queue.isEmpty());
    assertEquals(1, queue.size());
    MyReply reply = new MyReply();
    queue.handleReply(reply);
    assertFalse(queue.isEmpty());
    assertEquals(2, queue.size());
    assertSame(msg, queue.dequeue());
    assertSame(reply, queue.dequeue());
}
Also used : Message(com.yahoo.messagebus.Message) Test(org.junit.Test)

Example 2 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class ReceptorTestCase method requireThatAccessorsWork.

@Test
public void requireThatAccessorsWork() {
    Receptor receptor = new Receptor();
    assertNull(receptor.getMessage(0));
    Message msg = new MyMessage();
    receptor.handleMessage(msg);
    assertSame(msg, receptor.getMessage(0));
    Reply reply = new MyReply();
    receptor.handleReply(reply);
    assertSame(reply, receptor.getReply(0));
}
Also used : Message(com.yahoo.messagebus.Message) Reply(com.yahoo.messagebus.Reply) Test(org.junit.Test)

Example 3 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class SimpleFeeder method run.

public SimpleFeeder run() throws Throwable {
    VespaXMLFeedReader reader = new VespaXMLFeedReader(in, docTypeMgr);
    VespaXMLFeedReader.Operation op = new VespaXMLFeedReader.Operation();
    printHeader();
    while (failure == null) {
        reader.read(op);
        if (op.getType() == VespaXMLFeedReader.OperationType.INVALID) {
            break;
        }
        Message msg = newMessage(op);
        if (msg == null) {
            err.println("ignoring operation; " + op.getType());
            // ignore
            continue;
        }
        msg.setContext(System.currentTimeMillis());
        msg.setRoute(route);
        Error err = session.sendBlocking(msg).getError();
        if (err != null) {
            throw new IOException(err.toString());
        }
        ++numMessages;
    }
    while (failure == null && numReplies < numMessages) {
        Thread.sleep(100);
    }
    if (failure != null) {
        throw failure;
    }
    printReport();
    return this;
}
Also used : VespaXMLFeedReader(com.yahoo.vespaxmlparser.VespaXMLFeedReader) Message(com.yahoo.messagebus.Message) Error(com.yahoo.messagebus.Error) IOException(java.io.IOException)

Example 4 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class SimpleFeederTest method requireThatAsyncFailuresThrowInMainThread.

@Test
public void requireThatAsyncFailuresThrowInMainThread() throws Throwable {
    TestDriver driver = new TestDriver(new FeederParams(), "<vespafeed><document documenttype='simple' documentid='doc:scheme:0'/></vespafeed>", new MessageHandler() {

        @Override
        public void handleMessage(Message msg) {
            Reply reply = new EmptyReply();
            reply.swapState(msg);
            reply.addError(new Error(ErrorCode.APP_FATAL_ERROR + 6, "foo"));
            reply.addError(new Error(ErrorCode.APP_FATAL_ERROR + 9, "bar"));
            reply.popHandler().handleReply(reply);
        }
    });
    try {
        driver.run();
        fail();
    } catch (IOException e) {
        assertMatches("com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage@.+\n" + "\\[UNKNOWN\\(250006\\) @ .+\\]: foo\n" + "\\[UNKNOWN\\(250009\\) @ .+\\]: bar\n", e.getMessage());
    }
    assertTrue(driver.close());
}
Also used : MessageHandler(com.yahoo.messagebus.MessageHandler) Message(com.yahoo.messagebus.Message) DocumentMessage(com.yahoo.documentapi.messagebus.protocol.DocumentMessage) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Error(com.yahoo.messagebus.Error) IOException(java.io.IOException) EmptyReply(com.yahoo.messagebus.EmptyReply) Test(org.junit.Test)

Example 5 with Message

use of com.yahoo.messagebus.Message in project vespa by vespa-engine.

the class SharedSourceSessionTestCase method requireThatSessionCanSendMessage.

@Test
public void requireThatSessionCanSendMessage() throws InterruptedException {
    RemoteServer server = RemoteServer.newInstanceWithInternSlobrok();
    SharedSourceSession session = newSourceSession(server.slobrokId(), new SourceSessionParams());
    ReplyQueue queue = new ReplyQueue();
    Message msg = new SimpleMessage("foo").setRoute(Route.parse(server.connectionSpec()));
    msg.pushHandler(queue);
    assertTrue(session.sendMessage(msg).isAccepted());
    assertNotNull(msg = server.awaitMessage(60, TimeUnit.SECONDS));
    server.ackMessage(msg);
    assertNotNull(queue.awaitReply(60, TimeUnit.SECONDS));
    session.release();
    server.close();
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Message(com.yahoo.messagebus.Message) ReplyQueue(com.yahoo.messagebus.jdisc.test.ReplyQueue) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SourceSessionParams(com.yahoo.messagebus.SourceSessionParams) RemoteServer(com.yahoo.messagebus.jdisc.test.RemoteServer) Test(org.junit.Test)

Aggregations

Message (com.yahoo.messagebus.Message)39 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)17 RemoveDocumentMessage (com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage)15 UpdateDocumentMessage (com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage)15 Reply (com.yahoo.messagebus.Reply)14 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)13 Test (org.junit.Test)13 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)9 Chain (com.yahoo.component.chain.Chain)7 FeedContext (com.yahoo.feedapi.FeedContext)7 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)7 NullFeedMetric (com.yahoo.feedhandler.NullFeedMetric)7 Searcher (com.yahoo.search.Searcher)7 Execution (com.yahoo.search.searchchain.Execution)7 ClusterList (com.yahoo.vespaclient.ClusterList)7 Result (com.yahoo.search.Result)6 Utf8String (com.yahoo.text.Utf8String)6 BatchDocumentUpdateMessage (com.yahoo.documentapi.messagebus.protocol.BatchDocumentUpdateMessage)5 Tuple2 (com.yahoo.collections.Tuple2)4 EmptyReply (com.yahoo.messagebus.EmptyReply)4