Search in sources :

Example 36 with Error

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

the class RoutingTestCase method requireThatRetryCanBeDisabled.

@Test
public void requireThatRetryCanBeDisabled() {
    retryPolicy.setEnabled(false);
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
    Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
    assertNotNull(msg);
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err"));
    dstSession.reply(reply);
    assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
    System.out.println(reply.getTrace());
    assertEquals(1, reply.getNumErrors());
    assertEquals(ErrorCode.APP_TRANSIENT_ERROR, reply.getError(0).getCode());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Error(com.yahoo.messagebus.Error) Test(org.junit.Test)

Example 37 with Error

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

the class RoutingTestCase method requireThatTransientErrorsAreRetried.

@Test
public void requireThatTransientErrorsAreRetried() {
    assertTrue(srcSession.send(createMessage("msg"), Route.parse("dst/session")).isAccepted());
    Message msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60);
    assertNotNull(msg);
    Reply reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err1"));
    dstSession.reply(reply);
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    reply = new EmptyReply();
    reply.swapState(msg);
    reply.addError(new Error(ErrorCode.APP_TRANSIENT_ERROR, "err2"));
    dstSession.reply(reply);
    assertNotNull(msg = ((Receptor) dstSession.getMessageHandler()).getMessage(60));
    dstSession.acknowledge(msg);
    assertNotNull(reply = ((Receptor) srcSession.getReplyHandler()).getReply(60));
    System.out.println(reply.getTrace());
    assertFalse(reply.hasErrors());
    assertTrace(Arrays.asList("[APP_TRANSIENT_ERROR @ localhost]: err1", "-[APP_TRANSIENT_ERROR @ localhost]: err1", "[APP_TRANSIENT_ERROR @ localhost]: err2", "-[APP_TRANSIENT_ERROR @ localhost]: err2"), reply.getTrace());
}
Also used : SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Receptor(com.yahoo.messagebus.test.Receptor) Error(com.yahoo.messagebus.Error) Test(org.junit.Test)

Example 38 with Error

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

the class RPCSend method doInvoke.

private void doInvoke(Request request) {
    Params p = toParams(request.parameters());
    // allow garbage collection of request parameters
    request.discardParameters();
    // Make sure that the owner understands the protocol.
    Protocol protocol = net.getOwner().getProtocol(p.protocolName);
    if (protocol == null) {
        replyError(request, p.version, p.traceLevel, new Error(ErrorCode.UNKNOWN_PROTOCOL, "Protocol '" + p.protocolName + "' is not known by " + serverIdent + "."));
        return;
    }
    Routable routable = protocol.decode(p.version, p.payload);
    if (routable == null) {
        replyError(request, p.version, p.traceLevel, new Error(ErrorCode.DECODE_ERROR, "Protocol '" + protocol.getName() + "' failed to decode routable."));
        return;
    }
    if (routable instanceof Reply) {
        replyError(request, p.version, p.traceLevel, new Error(ErrorCode.DECODE_ERROR, "Payload decoded to a reply when expecting a message."));
        return;
    }
    Message msg = (Message) routable;
    if (p.route != null && p.route.length() > 0) {
        msg.setRoute(net.getRoute(p.route));
    }
    msg.setContext(new ReplyContext(request, p.version));
    msg.pushHandler(this);
    msg.setRetryEnabled(p.retryEnabled);
    msg.setRetry(p.retry);
    msg.setTimeReceivedNow();
    msg.setTimeRemaining(p.timeRemaining);
    msg.getTrace().setLevel(p.traceLevel);
    if (msg.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) {
        msg.getTrace().trace(TraceLevel.SEND_RECEIVE, "Message (type " + msg.getType() + ") received at " + serverIdent + " for session '" + p.session + "'.");
    }
    net.getOwner().deliverMessage(msg, p.session);
}
Also used : Message(com.yahoo.messagebus.Message) Error(com.yahoo.messagebus.Error) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) Protocol(com.yahoo.messagebus.Protocol) Routable(com.yahoo.messagebus.Routable)

Example 39 with Error

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

the class RPCSend method handleReply.

@Override
public final void handleReply(Reply reply) {
    ReplyContext ctx = (ReplyContext) reply.getContext();
    reply.setContext(null);
    // Add trace information.
    if (reply.getTrace().shouldTrace(TraceLevel.SEND_RECEIVE)) {
        reply.getTrace().trace(TraceLevel.SEND_RECEIVE, "Sending reply (version " + ctx.version + ") from " + serverIdent + ".");
    }
    // Encode and return the reply through the RPC request.
    byte[] payload = new byte[0];
    if (reply.getType() != 0) {
        Protocol protocol = net.getOwner().getProtocol(reply.getProtocol());
        if (protocol != null) {
            payload = protocol.encode(ctx.version, reply);
        }
        if (payload == null || payload.length == 0) {
            reply.addError(new Error(ErrorCode.ENCODE_ERROR, "An error occured while encoding the reply."));
        }
    }
    createResponse(ctx.request.returnValues(), reply, ctx.version, payload);
    ctx.request.returnRequest();
}
Also used : Error(com.yahoo.messagebus.Error) Protocol(com.yahoo.messagebus.Protocol)

Example 40 with Error

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

the class RPCSendV1 method createResponse.

@Override
protected void createResponse(Values ret, Reply reply, Version version, byte[] payload) {
    int[] eCodes = new int[reply.getNumErrors()];
    String[] eMessages = new String[reply.getNumErrors()];
    String[] eServices = new String[reply.getNumErrors()];
    for (int i = 0; i < reply.getNumErrors(); ++i) {
        Error error = reply.getError(i);
        eCodes[i] = error.getCode();
        eMessages[i] = error.getMessage();
        eServices[i] = error.getService() != null ? error.getService() : "";
    }
    ret.add(new StringValue(version.toString()));
    ret.add(new DoubleValue(reply.getRetryDelay()));
    ret.add(new Int32Array(eCodes));
    ret.add(new StringArray(eMessages));
    ret.add(new StringArray(eServices));
    ret.add(new StringValue(reply.getProtocol()));
    ret.add(new DataValue(payload));
    ret.add(new StringValue(reply.getTrace().getRoot() != null ? reply.getTrace().getRoot().encode() : ""));
}
Also used : Int32Array(com.yahoo.jrt.Int32Array) StringArray(com.yahoo.jrt.StringArray) DoubleValue(com.yahoo.jrt.DoubleValue) DataValue(com.yahoo.jrt.DataValue) Error(com.yahoo.messagebus.Error) StringValue(com.yahoo.jrt.StringValue)

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