Skip to content

Commit adbabb6

Browse files
author
Matthias Radestock
committed
test limiting multiple channels
1 parent c9c440f commit adbabb6

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

test/src/com/rabbitmq/client/test/functional/QosTests.java

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.List;
3939
import java.util.Queue;
4040

41+
import com.rabbitmq.client.Channel;
4142
import com.rabbitmq.client.GetResponse;
4243
import com.rabbitmq.client.QueueingConsumer;
4344
import com.rabbitmq.client.QueueingConsumer.Delivery;
@@ -180,7 +181,6 @@ public void testConsumerLifecycle()
180181
channel.queueDelete(queue);
181182
}
182183

183-
184184
public void testSetLimitAfterConsume()
185185
throws IOException
186186
{
@@ -225,6 +225,30 @@ public void testLimitedToUnlimited()
225225
drain(c, 2);
226226
}
227227

228+
public void testLimitingMultipleChannels()
229+
throws IOException
230+
{
231+
Channel ch1 = connection.createChannel();
232+
Channel ch2 = connection.createChannel();
233+
QueueingConsumer c1 = new QueueingConsumer(ch1);
234+
QueueingConsumer c2 = new QueueingConsumer(ch2);
235+
String q1 = declareBindConsume(ch1, c1);
236+
String q2 = declareBindConsume(ch2, c2);
237+
ch1.basicConsume(q2, false, c1);
238+
ch2.basicConsume(q1, false, c2);
239+
ch1.basicQos(1);
240+
ch2.basicQos(1);
241+
fill(5);
242+
Queue<Delivery> d1 = drain(c1, 1);
243+
Queue<Delivery> d2 = drain(c2, 1);
244+
ackDelivery(ch1, d1.remove(), true);
245+
ackDelivery(ch2, d2.remove(), true);
246+
drain(c1, 1);
247+
drain(c2, 1);
248+
ch1.close();
249+
ch2.close();
250+
}
251+
228252
protected void runLimitTests(int limit,
229253
boolean multiAck,
230254
boolean txMode,
@@ -325,17 +349,29 @@ protected Queue<Delivery> configure(QueueingConsumer c,
325349
protected String declareBindConsume(QueueingConsumer c)
326350
throws IOException
327351
{
328-
AMQP.Queue.DeclareOk ok = channel.queueDeclare();
352+
return declareBindConsume(channel, c);
353+
}
354+
355+
protected String declareBindConsume(Channel ch, QueueingConsumer c)
356+
throws IOException
357+
{
358+
AMQP.Queue.DeclareOk ok = ch.queueDeclare();
329359
String queue = ok.getQueue();
330-
channel.queueBind(queue, "amq.fanout", "");
331-
channel.basicConsume(queue, false, c);
360+
ch.queueBind(queue, "amq.fanout", "");
361+
ch.basicConsume(queue, false, c);
332362
return queue;
333363
}
334364

335365
protected void ackDelivery(Delivery d, boolean multiple)
336366
throws IOException
337367
{
338-
channel.basicAck(d.getEnvelope().getDeliveryTag(), multiple);
368+
ackDelivery(channel, d, multiple);
369+
}
370+
371+
protected void ackDelivery(Channel ch, Delivery d, boolean multiple)
372+
throws IOException
373+
{
374+
ch.basicAck(d.getEnvelope().getDeliveryTag(), multiple);
339375
}
340376

341377
}

0 commit comments

Comments
 (0)