use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class DocumentRetrieverTest method testHandlingErrorFromMessageBus.
@Test
public void testHandlingErrorFromMessageBus() throws DocumentRetrieverException {
ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).build();
Reply r = new GetDocumentReply(null);
r.addError(new Error(0, "Error message"));
when(mockedSession.syncSend(any())).thenReturn(r);
DocumentRetriever documentRetriever = createDocumentRetriever(params);
documentRetriever.retrieveDocuments();
assertTrue(errContent.toString().contains("Request failed"));
}
use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class Destination method handleMessage.
public void handleMessage(Message msg) {
Reply reply = ((DocumentMessage) msg).createReply();
try {
switch(msg.getType()) {
case DocumentProtocol.MESSAGE_GETDOCUMENT:
reply = new GetDocumentReply(local.get(((GetDocumentMessage) msg).getDocumentId()));
break;
case DocumentProtocol.MESSAGE_PUTDOCUMENT:
local.put(((PutDocumentMessage) msg).getDocumentPut());
break;
case DocumentProtocol.MESSAGE_REMOVEDOCUMENT:
local.remove(new DocumentRemove(((RemoveDocumentMessage) msg).getDocumentId()));
break;
case DocumentProtocol.MESSAGE_UPDATEDOCUMENT:
local.update(((UpdateDocumentMessage) msg).getDocumentUpdate());
break;
default:
throw new UnsupportedOperationException("Unsupported message type '" + msg.getType() + "'.");
}
} catch (Exception e) {
reply = new EmptyReply();
reply.addError(new Error(ErrorCode.APP_FATAL_ERROR, e.toString()));
}
msg.swapState(reply);
session.reply(reply);
}
use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class MessageBusVisitorSessionTestCase method testRetryVisitorOnTransientError.
@Test
public void testRetryVisitorOnTransientError() {
MockComponents mc = createDefaultMock("id.user==1234");
mc.visitorSession.start();
mc.controlHandler.resetMock();
mc.executor.expectAndProcessTasks(1);
replyToCreateVisitor(mc.sender, (reply) -> {
reply.addError(new Error(DocumentProtocol.ERROR_ABORTED, "bucket fell down a well"));
});
// reply
mc.executor.expectAndProcessTasks(1);
// Must have a 100ms delay
// send
mc.executor.expectAndProcessTasks(1, new long[] { 100 });
assertEquals("CreateVisitorMessage(buckets=[\n" + "BucketId(0x80000000000004d2)\n" + "BucketId(0x0000000000000000)\n" + "]\n" + "selection='id.user==1234'\n)", replyToCreateVisitor(mc.sender, ProgressToken.FINISHED_BUCKET));
mc.executor.expectAndProcessTasks(1);
mc.executor.expectNoTasks();
assertTrue(mc.visitorSession.isDone());
assertEquals("onVisitorError : ABORTED: bucket fell down a well\n" + "onProgress : 0 active, 0 pending, 1 finished, 1 total\n" + "onVisitorStatistics : 0 buckets visited, 0 docs returned\n" + "onDone : SUCCESS - ''\n", mc.controlHandler.toString());
}
use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class MessageBusVisitorSessionTestCase method testSkipBucketOnFatalErrorReply.
@Test
public void testSkipBucketOnFatalErrorReply() {
VisitorParameters visitorParameters = createVisitorParameters("");
visitorParameters.skipBucketsOnFatalErrors(true);
MockComponents mc = createDefaultMock(visitorParameters);
mc.controlHandler.resetMock();
mc.visitorSession.start();
// create visitors
mc.executor.expectAndProcessTasks(1);
assertEquals(2, mc.sender.getMessageCount());
replyErrorToCreateVisitor(mc.sender, new Error(DocumentProtocol.ERROR_INTERNAL_FAILURE, "borked"));
mc.executor.expectAndProcessTasks(1);
// no more buckets to send for--all either failed or active
mc.executor.expectNoTasks();
assertEquals(1, mc.sender.getMessageCount());
assertFalse(mc.controlHandler.isDone());
// partial bucket progress which must be remembered
assertEquals("CreateVisitorMessage(buckets=[\n" + "BucketId(0x0400000000000001)\n" + "BucketId(0x0000000000000000)\n" + "]\n)", replyToCreateVisitor(mc.sender, new BucketId(33, 1L | (1L << 32))));
// reply
mc.executor.expectAndProcessTasks(1);
// create visitors
mc.executor.expectAndProcessTasks(1);
assertEquals(1, mc.sender.getMessageCount());
assertFalse(mc.controlHandler.isDone());
// then fail bucket #2
replyErrorToCreateVisitor(mc.sender, new Error(DocumentProtocol.ERROR_INTERNAL_FAILURE, "more borked"));
// reply
mc.executor.expectAndProcessTasks(1);
mc.executor.expectNoTasks();
assertEquals(0, mc.sender.getMessageCount());
assertTrue(mc.controlHandler.isDone());
// make sure progress token was updated with bad buckets and
// remembers the initial error message
assertNotNull(mc.controlHandler.getProgress());
assertTrue(mc.controlHandler.getProgress().containsFailedBuckets());
assertEquals("INTERNAL_FAILURE: borked", mc.controlHandler.getProgress().getFirstErrorMsg());
assertEquals("#total: 2\n" + "#finished: 2\n" + "failed:\n" + "BucketId(0x0400000000000000) : BucketId(0x0000000000000000)\n" + "BucketId(0x0400000000000001) : BucketId(0x8400000100000001)\n", dumpProgressToken(mc.controlHandler.getProgress()));
assertEquals("onVisitorError : INTERNAL_FAILURE: borked\n" + "onProgress : 0 active, 1 pending, 1 finished, 2 total\n" + "onVisitorStatistics : 0 buckets visited, 0 docs returned\n" + "onVisitorError : INTERNAL_FAILURE: more borked\n" + "onDone : FAILURE - 'INTERNAL_FAILURE: borked'\n", mc.controlHandler.toString());
}
use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class MessageBusVisitorSessionTestCase method testNoRaceConditionForPendingReplyTasks.
/**
* Test that there is no race condition between a reply is handed off
* to the executor service via a task (thus decrementing the pending count
* for the sender) and the session checking for completion early, e.g.
* because of an error transitioning it into a failure state.
*/
@Test
public void testNoRaceConditionForPendingReplyTasks() {
MockComponents mc = createDefaultMock();
mc.visitorSession.start();
// clear messages
mc.controlHandler.resetMock();
mc.executor.expectAndProcessTasks(1);
assertEquals(2, mc.sender.getMessageCount());
replyToCreateVisitor(mc.sender, (reply) -> {
reply.addError(new Error(DocumentProtocol.ERROR_INTERNAL_FAILURE, "node fell down a well"));
});
replyToCreateVisitor(mc.sender, (reply) -> {
reply.addError(new Error(DocumentProtocol.ERROR_INTERNAL_FAILURE, "node got hit by a falling brick"));
});
// Now 2 pending reply tasks, but 0 pending messages. Ergo, using
// the sender as a ground truth to determine whether or not we have
// completed will cause a race condition.
mc.executor.expectAndProcessTasks(2);
mc.executor.expectNoTasks();
// no resending
assertEquals(0, mc.sender.getMessageCount());
assertTrue(mc.visitorSession.isDone());
// should get first received failure message as completion failure message
assertEquals("onVisitorError : INTERNAL_FAILURE: node fell down a well\n" + "onVisitorError : INTERNAL_FAILURE: node got hit by a falling brick\n" + "onDone : FAILURE - 'INTERNAL_FAILURE: node fell down a well'\n", mc.controlHandler.toString());
}
Aggregations