use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class FeedResponse method handleReply.
public boolean handleReply(Reply reply) {
metrics.addReply(reply);
if (reply.getTrace().getLevel() > 0) {
String str = reply.getTrace().toString();
traces.append(str);
System.out.println(str);
}
if (containsFatalErrors(reply.getErrors())) {
for (int i = 0; i < reply.getNumErrors(); ++i) {
Error err = reply.getError(i);
StringBuilder out = new StringBuilder(prettyPrint(reply.getMessage()));
out.append("[").append(DocumentProtocol.getErrorName(err.getCode())).append("] ");
if (err.getService() != null) {
out.append("(").append(err.getService()).append(") ");
}
out.append(err.getMessage());
String str = out.toString();
log.finest(str);
addError(convertErrorCode(err.getCode()), str);
}
if (abortOnError) {
isAborted = true;
return false;
}
}
return true;
}
use of com.yahoo.messagebus.Error 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);
}
}
use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class BucketStatsRetrieverTest method testShouldFailOnReplyError.
@Test(expected = BucketStatsException.class)
public void testShouldFailOnReplyError() throws BucketStatsException {
GetBucketListReply reply = new GetBucketListReply();
reply.addError(new Error(0, "errormsg"));
when(mockedSession.syncSend(any())).thenReturn(reply);
createRetriever().retrieveBucketList(new BucketId(1), bucketSpace);
}
use of com.yahoo.messagebus.Error in project vespa by vespa-engine.
the class PolicyTestCase method testSubsetService.
@Test
public void testSubsetService() {
PolicyTestFrame frame = new PolicyTestFrame("docproc/cluster.default", manager);
frame.setMessage(new PutDocumentMessage(new DocumentPut(new DocumentPut(new Document(manager.getDocumentType("testdoc"), new DocumentId("doc:scheme:"))))));
// Test requerying for adding nodes.
frame.setHop(new HopSpec("test", "docproc/cluster.default/[SubsetService:2]/chain.default"));
Set<String> lst = new HashSet<>();
for (int i = 1; i <= 10; ++i) {
frame.getNetwork().registerSession(i + "/chain.default");
assertTrue(frame.waitSlobrok("docproc/cluster.default/*/chain.default", i));
RoutingNode leaf = frame.select(1).get(0);
lst.add(leaf.getRoute().toString());
leaf.handleReply(new EmptyReply());
assertNotNull(frame.getReceptor().getReply(TIMEOUT));
}
// must have requeried
assertTrue(lst.size() > 1);
// Test load balancing.
String prev = null;
for (int i = 1; i <= 10; ++i) {
RoutingNode leaf = frame.select(1).get(0);
String next = leaf.getRoute().toString();
if (prev == null) {
assertNotNull(next);
} else {
assertFalse(prev.equals(next));
}
prev = next;
leaf.handleReply(new EmptyReply());
assertNotNull(frame.getReceptor().getReply(TIMEOUT));
}
// Test requerying for dropping nodes.
lst.clear();
for (int i = 1; i <= 10; ++i) {
RoutingNode leaf = frame.select(1).get(0);
String route = leaf.getRoute().toString();
lst.add(route);
frame.getNetwork().unregisterSession(route.substring(frame.getIdentity().length() + 1));
assertTrue(frame.waitSlobrok("docproc/cluster.default/*/chain.default", 10 - i));
Reply reply = new EmptyReply();
reply.addError(new Error(ErrorCode.NO_ADDRESS_FOR_SERVICE, route));
leaf.handleReply(reply);
assertNotNull(frame.getReceptor().getReply(TIMEOUT));
}
assertEquals(10, lst.size());
// Test merge behavior.
frame.setHop(new HopSpec("test", "[SubsetService]"));
frame.assertMergeOneReply("*");
frame.destroy();
}
use of com.yahoo.messagebus.Error 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;
}
Aggregations