|
1 | 1 | package com.rabbitmq.client.test.server; |
2 | 2 |
|
3 | | -import com.rabbitmq.client.AMQP; |
4 | | -import com.rabbitmq.client.Connection; |
5 | | -import com.rabbitmq.client.ConnectionFactory; |
| 3 | +import com.rabbitmq.client.*; |
6 | 4 | import com.rabbitmq.client.impl.*; |
7 | 5 | import com.rabbitmq.client.test.BrokerTestCase; |
8 | 6 | import com.rabbitmq.tools.Host; |
@@ -72,14 +70,32 @@ public void testChannelMaxGreaterThanServerValue() throws Exception { |
72 | 70 | public void testOpeningChannelWithIdGreaterThanChannelMaxFails() throws Exception { |
73 | 71 | int n = 48; |
74 | 72 |
|
75 | | - ConnectionFactory cf = new ConnectionFactory(); |
76 | | - Connection conn = cf.newConnection(); |
77 | | - assertEquals(n, conn.getChannelMax()); |
| 73 | + try { |
| 74 | + Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, " + n + ").'"); |
| 75 | + ConnectionFactory cf = new ConnectionFactory(); |
| 76 | + Connection conn = cf.newConnection(); |
| 77 | + assertEquals(n, conn.getChannelMax()); |
78 | 78 |
|
79 | | - for(int i = 1; i <= n; i++) { |
80 | | - assertNotNull(conn.createChannel(i)); |
| 79 | + for(int i = 1; i <= n; i++) { |
| 80 | + assertNotNull(conn.createChannel(i)); |
| 81 | + } |
| 82 | + // ChannelManager guards against channel.open being sent |
| 83 | + assertNull(conn.createChannel(n + 1)); |
| 84 | + |
| 85 | + // Construct a channel directly |
| 86 | + final ChannelN ch = new ChannelN((AMQConnection)conn, n + 1, |
| 87 | + new ConsumerWorkService(Executors.newSingleThreadExecutor())); |
| 88 | + conn.addShutdownListener(new ShutdownListener() { |
| 89 | + public void shutdownCompleted(ShutdownSignalException cause) { |
| 90 | + // make sure channel.open continuation is released |
| 91 | + ch.processShutdownSignal(cause, true, true); |
| 92 | + } |
| 93 | + }); |
| 94 | + ch.open(); |
| 95 | + fail("expected channel.open to cause a connection exception"); |
| 96 | + } catch (IOException e) { |
| 97 | + } finally { |
| 98 | + Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'"); |
81 | 99 | } |
82 | | - // ChannelManager guards against channel.open being sent |
83 | | - assertNull(conn.createChannel(n + 1)); |
84 | 100 | } |
85 | 101 | } |
0 commit comments