Search in sources :

Example 11 with EmptyReply

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

the class ProgressPrinterTest method testSimple.

public void testSimple() {
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    DummyTimer timer = new DummyTimer();
    timer.ms = 0;
    ProgressPrinter printer = new ProgressPrinter(timer, new PrintStream(output));
    RouteMetricSet metrics = new RouteMetricSet("foobar", printer);
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(PutDocumentMessage.createEmpty().setTimeReceived(1));
        metrics.addReply(reply);
    }
    timer.ms = 1200;
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(PutDocumentMessage.createEmpty().setTimeReceived(2));
        metrics.addReply(reply);
    }
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(3));
        metrics.addReply(reply);
    }
    timer.ms = 2400;
    {
        DocumentIgnoredReply reply = new DocumentIgnoredReply();
        reply.setMessage(PutDocumentMessage.createEmpty().setTimeReceived(0));
        metrics.addReply(reply);
    }
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(5));
        reply.addError(new com.yahoo.messagebus.Error(32, "foo"));
        metrics.addReply(reply);
    }
    timer.ms = 62000;
    {
        EmptyReply reply = new EmptyReply();
        reply.setMessage(UpdateDocumentMessage.createEmpty().setTimeReceived(6));
        reply.addError(new com.yahoo.messagebus.Error(64, "bar"));
        metrics.addReply(reply);
    }
    String val = output.toString().replaceAll("latency\\(min, max, avg\\): .*", "latency(min, max, avg): 0, 0, 0");
    String correct = "\rSuccessfully sent 2 messages so far" + "\rSuccessfully sent 3 messages so far" + "\n\n" + "Messages sent to vespa (route foobar) :\n" + "---------------------------------------\n" + "PutDocument:\tok: 2 msgs/sec: 0.03 failed: 0 ignored: 1 latency(min, max, avg): 0, 0, 0\n" + "UpdateDocument:\tok: 1 msgs/sec: 0.02 failed: 2 ignored: 0 latency(min, max, avg): 0, 0, 0\n";
    assertEquals(correct, val);
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet) EmptyReply(com.yahoo.messagebus.EmptyReply) DocumentIgnoredReply(com.yahoo.documentapi.messagebus.protocol.DocumentIgnoredReply)

Example 12 with EmptyReply

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

the class DummyReceiver method handleMessage.

public void handleMessage(Message message) {
    messageCount++;
    if (silentNum == 0) {
        System.out.println("Received message " + message + ". Received " + messageCount + " messages so far. In queue size " + queue.size());
        if (verbose) {
            if (message instanceof PutDocumentMessage) {
                System.out.println("  Document:\n" + ((PutDocumentMessage) message).getDocumentPut().getDocument().toXML("  "));
            } else if (message instanceof RemoveDocumentMessage) {
                System.out.println("  Document id: " + ((RemoveDocumentMessage) message).getDocumentId());
            } else if (message instanceof UpdateDocumentMessage) {
                System.out.println("  Update:\n  " + ((UpdateDocumentMessage) message).getDocumentUpdate().toString());
            }
        }
    } else {
        if ((messageCount % silentNum) == 0) {
            System.out.println("Received " + messageCount + " messages so far. In queue size " + queue.size());
        }
    }
    EmptyReply reply = new EmptyReply();
    message.swapState(reply);
    if (!instant) {
        try {
            executor.execute(new Task(reply));
        } catch (RejectedExecutionException e) {
            reply.addError(new Error(ErrorCode.SESSION_BUSY, "Session " + name + "/default is busy"));
            session.reply(reply);
        }
    } else {
        session.reply(reply);
    }
}
Also used : PutDocumentMessage(com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage) RemoveDocumentMessage(com.yahoo.documentapi.messagebus.protocol.RemoveDocumentMessage) Error(com.yahoo.messagebus.Error) UpdateDocumentMessage(com.yahoo.documentapi.messagebus.protocol.UpdateDocumentMessage) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 13 with EmptyReply

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

the class SharedSender method send.

/**
 * Sends a message. Waits until the number of pending messages for this owner has
 * become lower than the specified limit if necessary.
 *
 * @param msg                The message to send
 * @param owner              The callback to send replies to when received from messagebus
 * @param blockingQueue      If true, block until the message bus queue is available.
 */
public void send(Message msg, ResultCallback owner, boolean blockingQueue) {
    // Silently fail messages that are attempted sent after the callback aborted.
    if (owner.isAborted()) {
        return;
    }
    msg.setContext(owner);
    owner.getPending().inc();
    globalPending.inc();
    com.yahoo.messagebus.Result r;
    try {
        r = sender.send(msg, blockingQueue);
    } catch (InterruptedException e) {
        r = null;
    }
    if (r == null || !r.isAccepted()) {
        // pretend we sent OK but got this error reply:
        EmptyReply reply = new EmptyReply();
        msg.swapState(reply);
        reply.setMessage(msg);
        if (r != null) {
            reply.addError(r.getError());
        }
        handleReply(reply);
    }
}
Also used : EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 14 with EmptyReply

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

the class StoragePolicyTestEnvironment method sendToCorrectNode.

protected void sendToCorrectNode(String cluster, int correctNode) {
    RoutingNode target = select();
    target.handleReply(new EmptyReply());
    Reply reply = frame.getReceptor().getReply(60);
    assertNotNull(reply);
    assertFalse(reply.hasErrors());
    assertEquals(reply.getTrace().toString(), "storage/cluster." + cluster + "/distributor/" + correctNode, target.getRoute().getHop(0).toString());
}
Also used : RoutingNode(com.yahoo.messagebus.routing.RoutingNode) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) EmptyReply(com.yahoo.messagebus.EmptyReply)

Example 15 with EmptyReply

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

the class MbusClient method sendMessage.

private boolean sendMessage(final MbusRequest request) {
    Error error;
    final Long millis = request.timeRemaining(TimeUnit.MILLISECONDS);
    if (millis != null && millis <= 0) {
        error = new Error(ErrorCode.TIMEOUT, request.getTimeout(TimeUnit.MILLISECONDS) + " millis");
    } else if (request.isCancelled()) {
        error = new Error(ErrorCode.APP_FATAL_ERROR, "request cancelled");
    } else {
        try {
            error = session.sendMessage(request.getMessage()).getError();
        } catch (final Exception e) {
            error = new Error(ErrorCode.FATAL_ERROR, e.toString());
        }
    }
    if (error == null) {
        return true;
    }
    if (error.isFatal()) {
        final Reply reply = new EmptyReply();
        reply.swapState(request.getMessage());
        reply.addError(error);
        reply.popHandler().handleReply(reply);
        return true;
    }
    return false;
}
Also used : Error(com.yahoo.messagebus.Error) Reply(com.yahoo.messagebus.Reply) EmptyReply(com.yahoo.messagebus.EmptyReply) RequestDeniedException(com.yahoo.jdisc.handler.RequestDeniedException) EmptyReply(com.yahoo.messagebus.EmptyReply)

Aggregations

EmptyReply (com.yahoo.messagebus.EmptyReply)21 Reply (com.yahoo.messagebus.Reply)15 Error (com.yahoo.messagebus.Error)8 Test (org.junit.Test)3 RouteMetricSet (com.yahoo.clientmetrics.RouteMetricSet)2 Version (com.yahoo.component.Version)2 Response (com.yahoo.jdisc.Response)2 TestDriver (com.yahoo.jdisc.test.TestDriver)2 Message (com.yahoo.messagebus.Message)2 Hop (com.yahoo.messagebus.routing.Hop)2 Route (com.yahoo.messagebus.routing.Route)2 RoutingNode (com.yahoo.messagebus.routing.RoutingNode)2 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)2 Utf8Array (com.yahoo.text.Utf8Array)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 CompressionType (com.yahoo.compress.CompressionType)1 DocumentIgnoredReply (com.yahoo.documentapi.messagebus.protocol.DocumentIgnoredReply)1 DocumentMessage (com.yahoo.documentapi.messagebus.protocol.DocumentMessage)1 PutDocumentMessage (com.yahoo.documentapi.messagebus.protocol.PutDocumentMessage)1