use of com.thoughtworks.go.server.messaging.GoMessage in project gocd by gocd.
the class JMSMessageListenerAdapterTest method shouldNotKillTheThreadWhenThereIsAnException.
@Test
public void shouldNotKillTheThreadWhenThereIsAnException() throws Exception {
MessageConsumer consumer = mock(MessageConsumer.class);
when(consumer.receive()).thenThrow(new RuntimeException("should swallow me"));
GoMessageListener mockListener = new GoMessageListener() {
public void onMessage(GoMessage message) {
throw new UnsupportedOperationException("not implemented yet");
}
@Override
public String toString() {
return "test-listener";
}
};
JMSMessageListenerAdapter listenerAdapter = JMSMessageListenerAdapter.startListening(consumer, mockListener, mock(DaemonThreadStatsCollector.class));
try {
listenerAdapter.runImpl();
} catch (Exception e) {
e.printStackTrace();
fail("expected no exception get: " + e);
}
}
use of com.thoughtworks.go.server.messaging.GoMessage in project gocd by gocd.
the class JMSMessageListenerAdapter method runImpl.
protected boolean runImpl() {
try {
Message message = consumer.receive();
if (message == null) {
LOG.debug("Message consumer was closed.");
return true;
}
ObjectMessage omessage = (ObjectMessage) message;
daemonThreadStatsCollector.captureStats(thread.getId());
listener.onMessage((GoMessage) omessage.getObject());
} catch (JMSException e) {
LOG.warn("Error receiving message. Message receiving will continue despite this error.", e);
} catch (Exception e) {
LOG.error("Exception thrown in message handling by listener " + listener, e);
} finally {
daemonThreadStatsCollector.clearStats(thread.getId());
}
return false;
}
Aggregations