Search in sources :

Example 11 with AMQConnection

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);
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) AMQConnection(com.rabbitmq.client.impl.AMQConnection) IOException(java.io.IOException) ConnectionParams(com.rabbitmq.client.impl.ConnectionParams) Test(org.junit.Test)

Example 12 with AMQConnection

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());
}
Also used : AMQConnection(com.rabbitmq.client.impl.AMQConnection) IOException(java.io.IOException) ConnectionParams(com.rabbitmq.client.impl.ConnectionParams) TimeoutException(java.util.concurrent.TimeoutException) SocketTimeoutException(java.net.SocketTimeoutException) Test(org.junit.Test)

Example 13 with AMQConnection

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();
    }
}
Also used : AMQConnection(com.rabbitmq.client.impl.AMQConnection) Method(com.rabbitmq.client.Method) ChannelContinuationTimeoutException(com.rabbitmq.client.ChannelContinuationTimeoutException) Test(org.junit.Test)

Example 14 with AMQConnection

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");
}
Also used : Frame(com.rabbitmq.client.impl.Frame) AMQConnection(com.rabbitmq.client.impl.AMQConnection) ArrayList(java.util.ArrayList) UnexpectedFrameError(com.rabbitmq.client.UnexpectedFrameError) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

AMQConnection (com.rabbitmq.client.impl.AMQConnection)14 Test (org.junit.Test)9 IOException (java.io.IOException)6 ChannelContinuationTimeoutException (com.rabbitmq.client.ChannelContinuationTimeoutException)3 Connection (com.rabbitmq.client.Connection)3 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)3 Method (com.rabbitmq.client.Method)3 ConnectionParams (com.rabbitmq.client.impl.ConnectionParams)3 FrameHandler (com.rabbitmq.client.impl.FrameHandler)3 ArrayList (java.util.ArrayList)3 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)2 RemoteAddressAccessor (com.navercorp.pinpoint.plugin.rabbitmq.client.field.accessor.RemoteAddressAccessor)2 UnexpectedFrameError (com.rabbitmq.client.UnexpectedFrameError)2 AMQCommand (com.rabbitmq.client.impl.AMQCommand)2 Frame (com.rabbitmq.client.impl.Frame)2 SocketTimeoutException (java.net.SocketTimeoutException)2 TimeoutException (java.util.concurrent.TimeoutException)2 BrokerAddresses (com.meltwater.rxrabbit.BrokerAddresses)1 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)1 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)1