private static final String EXCHANGE_NAME = "NewExchangeNametoFailLookup";
public void test() throws Exception
{
AMQConnection connection = (AMQConnection) getConnection();
AMQSession session = (AMQSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Set no wait true so that we block the connection
// Also set a different exchange class string so the attempt to declare
// the exchange causes an exchange.
ExchangeDeclareBody body = session.getMethodRegistry().createExchangeDeclareBody(session.getTicket(), new AMQShortString(EXCHANGE_NAME), null,
true, false, false, false, true, null);
AMQFrame exchangeDeclare = body.generateFrame(session.getChannelId());
try
{
// block our thread so that can times out
connection.getProtocolHandler().syncWrite(exchangeDeclare, ExchangeDeclareOkBody.class);
}
catch (Exception e)
{
assertTrue("Exception should say the exchange is not known.", e.getMessage().contains("Unknown exchange: " + EXCHANGE_NAME));
}
try
{
// Depending on if the notification thread has closed the connection
// or not we may get an exception here when we attempt to close the
// connection. If we do get one then it should be the same as above
// an AMQAuthenticationException.
connection.close();
}
catch (Exception e)
{
assertTrue("Exception should say the exchange is not known.", e.getMessage().contains("Unknown exchange: " + EXCHANGE_NAME));
}