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);
}
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());
}
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;
}
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());
}
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());
}
Aggregations