|
10 | 10 | import java.util.concurrent.Executors; |
11 | 11 |
|
12 | 12 | public class ChannelLimitNegotiation extends BrokerTestCase { |
13 | | - class SpecialConnection extends AMQConnection { |
14 | | - private final int channelMax; |
| 13 | + class SpecialConnection extends AMQConnection { |
| 14 | + private final int channelMax; |
15 | 15 |
|
16 | | - public SpecialConnection(int channelMax) throws Exception { |
17 | | - this(new ConnectionFactory(), channelMax); |
18 | | - } |
| 16 | + public SpecialConnection(int channelMax) throws Exception { |
| 17 | + this(new ConnectionFactory(), channelMax); |
| 18 | + } |
19 | 19 |
|
20 | | - private SpecialConnection(ConnectionFactory factory, int channelMax) throws Exception { |
21 | | - super(factory.getUsername(), |
22 | | - factory.getPassword(), |
23 | | - new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", AMQP.PROTOCOL.PORT)), |
24 | | - Executors.newFixedThreadPool(1), |
25 | | - factory.getVirtualHost(), |
26 | | - factory.getClientProperties(), |
27 | | - factory.getRequestedFrameMax(), |
28 | | - channelMax, |
29 | | - factory.getRequestedHeartbeat(), |
30 | | - factory.getSaslConfig(), |
31 | | - new DefaultExceptionHandler()); |
| 20 | + private SpecialConnection(ConnectionFactory factory, int channelMax) throws Exception { |
| 21 | + super(factory.getUsername(), |
| 22 | + factory.getPassword(), |
| 23 | + new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", AMQP.PROTOCOL.PORT)), |
| 24 | + Executors.newFixedThreadPool(1), |
| 25 | + factory.getVirtualHost(), |
| 26 | + factory.getClientProperties(), |
| 27 | + factory.getRequestedFrameMax(), |
| 28 | + channelMax, |
| 29 | + factory.getRequestedHeartbeat(), |
| 30 | + factory.getSaslConfig(), |
| 31 | + new DefaultExceptionHandler()); |
32 | 32 |
|
33 | | - this.channelMax = channelMax; |
34 | | - } |
| 33 | + this.channelMax = channelMax; |
| 34 | + } |
35 | 35 |
|
36 | | - /** |
37 | | - * Private API, allows for easier simulation of bogus clients. |
38 | | - */ |
39 | | - @Override |
40 | | - protected int negotiateChannelMax(int requestedChannelMax, int serverMax) { |
41 | | - return this.channelMax; |
| 36 | + /** |
| 37 | + * Private API, allows for easier simulation of bogus clients. |
| 38 | + */ |
| 39 | + @Override |
| 40 | + protected int negotiateChannelMax(int requestedChannelMax, int serverMax) { |
| 41 | + return this.channelMax; |
| 42 | + } |
42 | 43 | } |
43 | | - } |
44 | | - |
45 | | - public void testChannelMaxLowerThanServerMinimum() throws Exception { |
46 | | - int n = 64; |
47 | | - ConnectionFactory cf = new ConnectionFactory(); |
48 | | - cf.setRequestedChannelMax(n); |
49 | 44 |
|
50 | | - Connection conn = cf.newConnection(); |
51 | | - assertEquals(n, conn.getChannelMax()); |
52 | | - } |
| 45 | + public void testChannelMaxLowerThanServerMinimum() throws Exception { |
| 46 | + int n = 64; |
| 47 | + ConnectionFactory cf = new ConnectionFactory(); |
| 48 | + cf.setRequestedChannelMax(n); |
53 | 49 |
|
54 | | - public void testChannelMaxGreaterThanServerValue() throws Exception { |
55 | | - try { |
56 | | - Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 2048).'"); |
| 50 | + Connection conn = cf.newConnection(); |
| 51 | + assertEquals(n, conn.getChannelMax()); |
| 52 | + } |
57 | 53 |
|
58 | | - SpecialConnection connection = new SpecialConnection(4096); |
| 54 | + public void testChannelMaxGreaterThanServerValue() throws Exception { |
59 | 55 | try { |
60 | | - connection.start(); |
61 | | - fail("expected failure during connection negotiation"); |
62 | | - } catch (IOException e) { |
63 | | - // expected |
| 56 | + Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 2048).'"); |
| 57 | + |
| 58 | + SpecialConnection connection = new SpecialConnection(4096); |
| 59 | + try { |
| 60 | + connection.start(); |
| 61 | + fail("expected failure during connection negotiation"); |
| 62 | + } catch (IOException e) { |
| 63 | + // expected |
| 64 | + } |
| 65 | + } finally { |
| 66 | + Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'"); |
64 | 67 | } |
65 | | - } finally { |
66 | | - Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'"); |
67 | | - } |
68 | | - } |
| 68 | + } |
69 | 69 |
|
70 | | - public void testOpeningTooManyChannels() throws Exception { |
71 | | - int n = 48; |
| 70 | + public void testOpeningTooManyChannels() throws Exception { |
| 71 | + int n = 48; |
72 | 72 |
|
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()); |
| 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)); |
81 | | - } |
82 | | - // ChannelManager guards against channel.open being sent |
83 | | - assertNull(conn.createChannel(n + 1)); |
| 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 | 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); |
| 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 | + checkShutdownSignal(530, e); |
| 98 | + } finally { |
| 99 | + Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'"); |
92 | 100 | } |
93 | | - }); |
94 | | - ch.open(); |
95 | | - fail("expected channel.open to cause a connection exception"); |
96 | | - } catch (IOException e) { |
97 | | - checkShutdownSignal(530, e); |
98 | | - } finally { |
99 | | - Host.rabbitmqctl("eval 'application:set_env(rabbit, channel_max, 0).'"); |
100 | 101 | } |
101 | | - } |
102 | 102 | } |
0 commit comments