use of com.rabbitmq.client.impl.AMQConnection in project rabbitmq-java-client by rabbitmq.
the class AMQConnectionTest method connectionSendsSingleHeaderAndTimesOut.
/**
* Check the AMQConnection does send exactly 1 initial header, and deal correctly with
* the frame handler throwing an exception when we try to read data
*/
@Test
public void connectionSendsSingleHeaderAndTimesOut() throws TimeoutException {
IOException exception = new SocketTimeoutException();
_mockFrameHandler.setExceptionOnReadingFrames(exception);
assertEquals(0, _mockFrameHandler.countHeadersSent());
try {
ConnectionParams params = factory.params(Executors.newFixedThreadPool(1));
new AMQConnection(params, _mockFrameHandler).start();
fail("Connection should have thrown exception");
} catch (IOException signal) {
// As expected
}
assertEquals(1, _mockFrameHandler.countHeadersSent());
// _connection.close(0, CLOSE_MESSAGE);
List<Throwable> exceptionList = exceptionHandler.getHandledExceptions();
assertEquals(Collections.<Throwable>singletonList(exception), exceptionList);
}
use of com.rabbitmq.client.impl.AMQConnection in project rabbitmq-java-client by rabbitmq.
the class AMQConnectionTest method connectionHangInNegotiation.
/**
* Check we can open a connection once, but not twice.
* @throws IOException
*/
// public void testCanOpenConnectionOnceOnly() throws IOException {
// AMQConnection connection = new AMQConnection(_mockFrameHandler);
// connection.open();
// try {
// connection.open();
// fail("We shouldn't have been able to open this connection more than once.");
// } catch(IOException ex) {
// // as expected
// }
// }
/**
* Test that we catch timeout between connect and negotiation of the connection being finished.
*/
@Test
public void connectionHangInNegotiation() {
// to limit hang
this._mockFrameHandler.setTimeoutCount(10);
assertEquals(0, this._mockFrameHandler.countHeadersSent());
try {
ConnectionParams params = factory.params(Executors.newFixedThreadPool(1));
new AMQConnection(params, this._mockFrameHandler).start();
fail("Connection should have thrown exception");
} catch (IOException signal) {
// expected
} catch (TimeoutException te) {
// also fine: continuation timed out first
}
assertEquals(1, this._mockFrameHandler.countHeadersSent());
List<Throwable> exceptionList = exceptionHandler.getHandledExceptions();
assertEquals("Only one exception expected", 1, exceptionList.size());
assertEquals("Wrong type of exception returned.", SocketTimeoutException.class, exceptionList.get(0).getClass());
}
use of com.rabbitmq.client.impl.AMQConnection in project rabbitmq-java-client by rabbitmq.
the class AMQChannelTest method rpcTimesOutWhenResponseDoesNotCome.
@Test
public void rpcTimesOutWhenResponseDoesNotCome() throws IOException {
int rpcTimeout = 100;
AMQConnection connection = mock(AMQConnection.class);
when(connection.getChannelRpcTimeout()).thenReturn(rpcTimeout);
when(connection.getTrafficListener()).thenReturn(TrafficListener.NO_OP);
DummyAmqChannel channel = new DummyAmqChannel(connection, 1);
Method method = new AMQImpl.Queue.Declare.Builder().queue("").durable(false).exclusive(true).autoDelete(true).arguments(null).build();
try {
channel.rpc(method);
fail("Should time out and throw an exception");
} catch (ChannelContinuationTimeoutException e) {
// OK
assertThat((DummyAmqChannel) e.getChannel()).isEqualTo(channel);
assertThat(e.getChannelNumber()).isEqualTo(channel.getChannelNumber());
assertThat(e.getMethod()).isEqualTo(method);
assertThat(channel.nextOutstandingRpc()).as("outstanding RPC should have been cleaned").isNull();
}
}
use of com.rabbitmq.client.impl.AMQConnection in project rabbitmq-java-client by rabbitmq.
the class BrokenFramesTest method noMethod.
@Test
public void noMethod() throws Exception {
List<Frame> frames = new ArrayList<Frame>();
frames.add(new Frame(AMQP.FRAME_HEADER, 0));
myFrameHandler.setFrames(frames.iterator());
try {
new AMQConnection(factory.params(Executors.newFixedThreadPool(1)), myFrameHandler).start();
} catch (IOException e) {
UnexpectedFrameError unexpectedFrameError = findUnexpectedFrameError(e);
assertNotNull(unexpectedFrameError);
assertEquals(AMQP.FRAME_HEADER, unexpectedFrameError.getReceivedFrame().getType());
assertEquals(AMQP.FRAME_METHOD, unexpectedFrameError.getExpectedFrameType());
return;
}
fail("No UnexpectedFrameError thrown");
}
Aggregations