|
| 1 | +// The contents of this file are subject to the Mozilla Public License |
| 2 | +// Version 1.1 (the "License"); you may not use this file except in |
| 3 | +// compliance with the License. You may obtain a copy of the License |
| 4 | +// at http://www.mozilla.org/MPL/ |
| 5 | +// |
| 6 | +// Software distributed under the License is distributed on an "AS IS" |
| 7 | +// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See |
| 8 | +// the License for the specific language governing rights and |
| 9 | +// limitations under the License. |
| 10 | +// |
| 11 | +// The Original Code is RabbitMQ. |
| 12 | +// |
| 13 | +// The Initial Developer of the Original Code is VMware, Inc. |
| 14 | +// Copyright (c) 2007-2012 VMware, Inc. All rights reserved. |
| 15 | +// |
| 16 | + |
| 17 | + |
| 18 | +package com.rabbitmq.client.test.functional; |
| 19 | + |
| 20 | +import com.rabbitmq.client.AMQP; |
| 21 | +import com.rabbitmq.client.test.BrokerTestCase; |
| 22 | +import java.io.IOException; |
| 23 | +import java.util.HashMap; |
| 24 | +import java.util.Map; |
| 25 | + |
| 26 | +/** |
| 27 | + * Test queue maxdepth limit. |
| 28 | + */ |
| 29 | +public class QueueSizeLimit extends BrokerTestCase { |
| 30 | + |
| 31 | + private final int MAXDEPTH=5; |
| 32 | + private final String q = "queue"; |
| 33 | + |
| 34 | + @Override |
| 35 | + protected void setUp() throws IOException { |
| 36 | + super.setUp(); |
| 37 | + channel.confirmSelect(); |
| 38 | + } |
| 39 | + |
| 40 | + public void testQueueSize() throws IOException, InterruptedException { |
| 41 | + declareQueue(); |
| 42 | + for (int i=1; i <= MAXDEPTH; i++){ |
| 43 | + channel.basicPublish("", q, null, ("msg" + i).getBytes()); |
| 44 | + channel.waitForConfirmsOrDie(); |
| 45 | + assertEquals(i, declareQueue()); |
| 46 | + } |
| 47 | + for (int i=1; i <= MAXDEPTH; i++){ |
| 48 | + channel.basicPublish("", q, null, ("msg overflow").getBytes()); |
| 49 | + channel.waitForConfirmsOrDie(); |
| 50 | + assertEquals(MAXDEPTH, declareQueue()); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public void testQueueUnacked() throws IOException, InterruptedException { |
| 55 | + declareQueue(); |
| 56 | + for (int i=1; i <= MAXDEPTH; i++){ |
| 57 | + channel.basicPublish ("", q, null, ("msg" + i).getBytes()); |
| 58 | + channel.waitForConfirmsOrDie(); |
| 59 | + channel.basicGet(q, false); |
| 60 | + assertEquals(0, declareQueue()); |
| 61 | + } |
| 62 | + channel.basicPublish("", q, null, ("msg overflow").getBytes()); |
| 63 | + channel.waitForConfirmsOrDie(); |
| 64 | + assertEquals(null, channel.basicGet(q, false)); |
| 65 | + } |
| 66 | + |
| 67 | + private int declareQueue() throws IOException { |
| 68 | + Map<String, Object> args = new HashMap<String, Object>(); |
| 69 | + args.put("x-maxdepth", MAXDEPTH); |
| 70 | + AMQP.Queue.DeclareOk ok = channel.queueDeclare(q, false, true, true, args); |
| 71 | + return ok.getMessageCount(); |
| 72 | + } |
| 73 | +} |
0 commit comments