Search in sources :

Example 1 with ChannelN

use of com.rabbitmq.client.impl.ChannelN in project rabbitmq-java-client by rabbitmq.

the class ChannelLimitNegotiation method openingTooManyChannels.

@Test
public void openingTooManyChannels() throws Exception {
    int n = 48;
    try {
        Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, " + n + ").'");
        ConnectionFactory cf = TestUtils.connectionFactory();
        Connection conn = cf.newConnection();
        assertEquals(n, conn.getChannelMax());
        for (int i = 1; i <= n; i++) {
            assertNotNull(conn.createChannel(i));
        }
        // ChannelManager guards against channel.open being sent
        assertNull(conn.createChannel(n + 1));
        // Construct a channel directly
        final ChannelN ch = new ChannelN(((AutorecoveringConnection) conn).getDelegate(), n + 1, new ConsumerWorkService(Executors.newSingleThreadExecutor(), Executors.defaultThreadFactory(), ConnectionFactory.DEFAULT_SHUTDOWN_TIMEOUT));
        conn.addShutdownListener(new ShutdownListener() {

            public void shutdownCompleted(ShutdownSignalException cause) {
                // make sure channel.open continuation is released
                ch.processShutdownSignal(cause, true, true);
            }
        });
        ch.open();
        fail("expected channel.open to cause a connection exception");
    } catch (IOException e) {
        checkShutdownSignal(530, e);
    } finally {
        Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'");
    }
}
Also used : ShutdownListener(com.rabbitmq.client.ShutdownListener) ConnectionFactory(com.rabbitmq.client.ConnectionFactory) ShutdownSignalException(com.rabbitmq.client.ShutdownSignalException) ChannelN(com.rabbitmq.client.impl.ChannelN) AMQConnection(com.rabbitmq.client.impl.AMQConnection) Connection(com.rabbitmq.client.Connection) AutorecoveringConnection(com.rabbitmq.client.impl.recovery.AutorecoveringConnection) ConsumerWorkService(com.rabbitmq.client.impl.ConsumerWorkService) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

Connection (com.rabbitmq.client.Connection)1 ConnectionFactory (com.rabbitmq.client.ConnectionFactory)1 ShutdownListener (com.rabbitmq.client.ShutdownListener)1 ShutdownSignalException (com.rabbitmq.client.ShutdownSignalException)1 AMQConnection (com.rabbitmq.client.impl.AMQConnection)1 ChannelN (com.rabbitmq.client.impl.ChannelN)1 ConsumerWorkService (com.rabbitmq.client.impl.ConsumerWorkService)1 AutorecoveringConnection (com.rabbitmq.client.impl.recovery.AutorecoveringConnection)1 IOException (java.io.IOException)1 Test (org.junit.Test)1