Search in sources :

Example 1 with ChannelContinuationTimeoutException

use of com.rabbitmq.client.ChannelContinuationTimeoutException in project rabbitmq-java-client by rabbitmq.

the class AMQChannelTest method testRpcTimeoutReplyComesDuringNexRpc.

@Test
public void testRpcTimeoutReplyComesDuringNexRpc() throws Exception {
    int rpcTimeout = 100;
    AMQConnection connection = mock(AMQConnection.class);
    when(connection.getChannelRpcTimeout()).thenReturn(rpcTimeout);
    when(connection.willCheckRpcResponseType()).thenReturn(Boolean.TRUE);
    final DummyAmqChannel channel = new DummyAmqChannel(connection, 1);
    Method method = new AMQImpl.Queue.Declare.Builder().queue("123").durable(false).exclusive(true).autoDelete(true).arguments(null).build();
    try {
        channel.rpc(method);
        fail("Should time out and throw an exception");
    } catch (final ChannelContinuationTimeoutException e) {
        // OK
        assertThat((DummyAmqChannel) e.getChannel(), is(channel));
        assertThat(e.getChannelNumber(), is(channel.getChannelNumber()));
        assertThat(e.getMethod(), is(method));
        assertNull("outstanding RPC should have been cleaned", channel.nextOutstandingRpc());
    }
    // now do a basic.consume request and have the queue.declareok returned instead
    method = new AMQImpl.Basic.Consume.Builder().queue("123").consumerTag("").arguments(null).build();
    final Method response1 = new AMQImpl.Queue.DeclareOk.Builder().queue("123").consumerCount(0).messageCount(0).build();
    final Method response2 = new AMQImpl.Basic.ConsumeOk.Builder().consumerTag("456").build();
    scheduler.schedule(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            channel.handleCompleteInboundCommand(new AMQCommand(response1));
            Thread.sleep(10);
            channel.handleCompleteInboundCommand(new AMQCommand(response2));
            return null;
        }
    }, (long) (rpcTimeout / 2.0), TimeUnit.MILLISECONDS);
    AMQCommand rpcResponse = channel.rpc(method);
    assertThat(rpcResponse.getMethod(), is(response2));
}
Also used : AMQConnection(com.rabbitmq.client.impl.AMQConnection) Method(com.rabbitmq.client.Method) ChannelContinuationTimeoutException(com.rabbitmq.client.ChannelContinuationTimeoutException) ChannelContinuationTimeoutException(com.rabbitmq.client.ChannelContinuationTimeoutException) IOException(java.io.IOException) AMQImpl(com.rabbitmq.client.impl.AMQImpl) AMQCommand(com.rabbitmq.client.impl.AMQCommand) Test(org.junit.Test)

Example 2 with ChannelContinuationTimeoutException

use of com.rabbitmq.client.ChannelContinuationTimeoutException 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);
    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(), is(channel));
        assertThat(e.getChannelNumber(), is(channel.getChannelNumber()));
        assertThat(e.getMethod(), is(method));
        assertNull("outstanding RPC should have been cleaned", channel.nextOutstandingRpc());
    }
}
Also used : AMQConnection(com.rabbitmq.client.impl.AMQConnection) Method(com.rabbitmq.client.Method) ChannelContinuationTimeoutException(com.rabbitmq.client.ChannelContinuationTimeoutException) Test(org.junit.Test)

Aggregations

ChannelContinuationTimeoutException (com.rabbitmq.client.ChannelContinuationTimeoutException)2 Method (com.rabbitmq.client.Method)2 AMQConnection (com.rabbitmq.client.impl.AMQConnection)2 Test (org.junit.Test)2 AMQCommand (com.rabbitmq.client.impl.AMQCommand)1 AMQImpl (com.rabbitmq.client.impl.AMQImpl)1 IOException (java.io.IOException)1