Search in sources :

Example 11 with Error

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

the class ResenderTestCase method replyFromDestination.

private void replyFromDestination(Message msg, int errorCode, double retryDelay) {
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    if (errorCode != ErrorCode.NONE) {
        reply.addError(new Error(errorCode, "err"));
    }
    reply.setRetryDelay(retryDelay);
    dstSession.reply(reply);
}
Also used : Error(com.yahoo.messagebus.Error)

Example 12 with Error

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

the class AdvancedRoutingTestCase method testAdvanced.

// //////////////////////////////////////////////////////////////////////////////
// 
// Tests
// 
// //////////////////////////////////////////////////////////////////////////////
public void testAdvanced() {
    SimpleProtocol protocol = new SimpleProtocol();
    protocol.addPolicyFactory("Custom", new CustomPolicyFactory(false, ErrorCode.NO_ADDRESS_FOR_SERVICE));
    srcServer.mb.putProtocol(protocol);
    srcServer.setupRouting(new RoutingTableSpec(SimpleProtocol.NAME).addHop(new HopSpec("bar", "dst/bar")).addHop(new HopSpec("baz", "dst/baz")).addRoute(new RouteSpec("baz").addHop("baz")));
    Message msg = new SimpleMessage("msg");
    msg.getTrace().setLevel(9);
    assertTrue(srcSession.send(msg, Route.parse("[Custom:" + dstFoo.getConnectionSpec() + ",bar,route:baz,dst/cox,?dst/unknown]")).isAccepted());
    // Initial send.
    assertNotNull(msg = ((Receptor) dstFoo.getMessageHandler()).getMessage(60));
    dstFoo.acknowledge(msg);
    assertNotNull(msg = ((Receptor) dstBar.getMessageHandler()).getMessage(60));
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "bar"));
    dstBar.reply(reply);
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "baz1"));
    dstBaz.reply(reply);
    // First retry.
    assertNull(((Receptor) dstFoo.getMessageHandler()).getMessage(0));
    assertNotNull(msg = ((Receptor) dstBar.getMessageHandler()).getMessage(60));
    dstBar.acknowledge(msg);
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.TRANSIENT_ERROR, "baz2"));
    dstBaz.reply(reply);
    // Second retry.
    assertNull(((Receptor) dstFoo.getMessageHandler()).getMessage(0));
    assertNull(((Receptor) dstBar.getMessageHandler()).getMessage(0));
    assertNotNull(msg = ((Receptor) dstBaz.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.FATAL_ERROR, "baz3"));
    dstBaz.reply(reply);
    // Done.
    reply = ((Receptor) srcSession.getReplyHandler()).getReply(60);
    assertNotNull(reply);
    System.out.println(reply.getTrace());
    assertEquals(2, reply.getNumErrors());
    assertEquals(ErrorCode.FATAL_ERROR, reply.getError(0).getCode());
    assertEquals(ErrorCode.NO_ADDRESS_FOR_SERVICE, reply.getError(1).getCode());
}
Also used : SimpleProtocol(com.yahoo.messagebus.test.SimpleProtocol) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Error(com.yahoo.messagebus.Error) CustomPolicyFactory(com.yahoo.messagebus.routing.test.CustomPolicyFactory)

Example 13 with Error

use of com.yahoo.messagebus.Error 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 14 with Error

use of com.yahoo.messagebus.Error 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 15 with Error

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

the class MbusServerTestCase method assertError.

private static void assertError(List<Integer> expectedErrors, int responseStatus, int... responseErrors) {
    MyRequestHandler requestHandler = MyRequestHandler.newInstance();
    ServerTestDriver driver = ServerTestDriver.newInstance(requestHandler);
    assertTrue(driver.sendMessage(new SimpleMessage("foo")));
    assertNotNull(requestHandler.awaitRequest());
    Reply reply = new SimpleReply("bar");
    reply.swapState(((MbusRequest) requestHandler.request).getMessage());
    for (int err : responseErrors) {
        reply.addError(new Error(err, "err"));
    }
    assertTrue(requestHandler.sendResponse(new MbusResponse(responseStatus, reply)));
    assertNotNull(reply = driver.awaitReply());
    List<Integer> actual = new LinkedList<>();
    for (int i = 0; i < reply.getNumErrors(); ++i) {
        actual.add(reply.getError(i).getCode());
    }
    assertEquals(expectedErrors, actual);
    assertTrue(driver.close());
}
Also used : SimpleReply(com.yahoo.messagebus.test.SimpleReply) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Error(com.yahoo.messagebus.Error) ServerTestDriver(com.yahoo.messagebus.jdisc.test.ServerTestDriver) LinkedList(java.util.LinkedList)

Aggregations

Error (com.yahoo.messagebus.Error)51 Test (org.junit.Test)22 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)10 EmptyReply (com.yahoo.messagebus.EmptyReply)9 Reply (com.yahoo.messagebus.Reply)9 Receptor (com.yahoo.messagebus.test.Receptor)9 SimpleProtocol (com.yahoo.messagebus.test.SimpleProtocol)5 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)5 ParseException (com.yahoo.document.select.parser.ParseException)4 CustomPolicyFactory (com.yahoo.messagebus.routing.test.CustomPolicyFactory)4 BucketId (com.yahoo.document.BucketId)3 Message (com.yahoo.messagebus.Message)3 Version (com.yahoo.component.Version)2 DataValue (com.yahoo.jrt.DataValue)2 Protocol (com.yahoo.messagebus.Protocol)2 Hop (com.yahoo.messagebus.routing.Hop)2 Slime (com.yahoo.slime.Slime)2 Utf8Array (com.yahoo.text.Utf8Array)2 Utf8String (com.yahoo.text.Utf8String)2 IOException (java.io.IOException)2