Skip to content

Commit be4b274

Browse files
Test bogus channel.open
This required making ConsumerWorkService public in order to be able to instantiate ChannelN directly. Per discussion with Simon.
1 parent fdd9579 commit be4b274

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

src/com/rabbitmq/client/impl/ConsumerWorkService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
import com.rabbitmq.client.Channel;
2424

25-
final class ConsumerWorkService {
25+
final public class ConsumerWorkService {
2626
private static final int MAX_RUNNABLE_BLOCK_SIZE = 16;
2727
private static final int DEFAULT_NUM_THREADS = 5;
2828
private final ExecutorService executor;

test/src/com/rabbitmq/client/test/server/ChannelLimitNegotiation.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.rabbitmq.client.test.server;
22

3-
import com.rabbitmq.client.AMQP;
4-
import com.rabbitmq.client.Connection;
5-
import com.rabbitmq.client.ConnectionFactory;
3+
import com.rabbitmq.client.*;
64
import com.rabbitmq.client.impl.*;
75
import com.rabbitmq.client.test.BrokerTestCase;
86
import com.rabbitmq.tools.Host;
@@ -72,14 +70,32 @@ public void testChannelMaxGreaterThanServerValue() throws Exception {
7270
public void testOpeningChannelWithIdGreaterThanChannelMaxFails() throws Exception {
7371
int n = 48;
7472

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());
7878

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).'");
8199
}
82-
// ChannelManager guards against channel.open being sent
83-
assertNull(conn.createChannel(n + 1));
84100
}
85101
}

0 commit comments

Comments
 (0)