|
| 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 at |
| 4 | +// 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 the |
| 8 | +// License for the specific language governing rights and limitations |
| 9 | +// under the License. |
| 10 | +// |
| 11 | +// The Original Code is RabbitMQ. |
| 12 | +// |
| 13 | +// The Initial Developers of the Original Code are LShift Ltd, |
| 14 | +// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd. |
| 15 | +// |
| 16 | +// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd, |
| 17 | +// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd |
| 18 | +// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial |
| 19 | +// Technologies LLC, and Rabbit Technologies Ltd. |
| 20 | +// |
| 21 | +// Portions created by LShift Ltd are Copyright (C) 2007-2010 LShift |
| 22 | +// Ltd. Portions created by Cohesive Financial Technologies LLC are |
| 23 | +// Copyright (C) 2007-2010 Cohesive Financial Technologies |
| 24 | +// LLC. Portions created by Rabbit Technologies Ltd are Copyright |
| 25 | +// (C) 2007-2010 Rabbit Technologies Ltd. |
| 26 | +// |
| 27 | +// All Rights Reserved. |
| 28 | +// |
| 29 | +// Contributor(s): ______________________________________. |
| 30 | +// |
| 31 | + |
| 32 | +package com.rabbitmq.client.test.functional; |
| 33 | + |
| 34 | +import com.rabbitmq.client.test.BrokerTestCase; |
| 35 | + |
| 36 | +import java.io.IOException; |
| 37 | + |
| 38 | +import com.rabbitmq.client.MessageProperties; |
| 39 | +import com.rabbitmq.client.QueueingConsumer; |
| 40 | +import com.rabbitmq.client.QueueingConsumer.Delivery; |
| 41 | + |
| 42 | +/* Publish a message of size FRAME_MAX. The broker should split this |
| 43 | + * into two frames before sending back. */ |
| 44 | +public class FrameMax extends BrokerTestCase { |
| 45 | + /* This value for FrameMax is larger than the minimum and less |
| 46 | + * than what Rabbit suggests. */ |
| 47 | + final static int FRAME_MAX = 131008; |
| 48 | + final static int TIMEOUT = 3000; /* Time to wait for messages. */ |
| 49 | + final static String EXCHANGE_NAME = "xchg1"; |
| 50 | + final static String ROUTING_KEY = "something"; |
| 51 | + |
| 52 | + QueueingConsumer consumer; |
| 53 | + |
| 54 | + @Override |
| 55 | + protected void setUp() |
| 56 | + throws IOException |
| 57 | + { |
| 58 | + super.setUp(); |
| 59 | + connectionFactory.setRequestedFrameMax(FRAME_MAX); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + protected void createResources() |
| 64 | + throws IOException |
| 65 | + { |
| 66 | + channel.exchangeDeclare(EXCHANGE_NAME, "direct"); |
| 67 | + consumer = new QueueingConsumer(channel); |
| 68 | + String queueName = channel.queueDeclare().getQueue(); |
| 69 | + channel.basicConsume(queueName, consumer); |
| 70 | + channel.queueBind(queueName, EXCHANGE_NAME, ROUTING_KEY); |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + protected void releaseResources() |
| 75 | + throws IOException |
| 76 | + { |
| 77 | + consumer = null; |
| 78 | + channel.exchangeDelete(EXCHANGE_NAME); |
| 79 | + } |
| 80 | + |
| 81 | + /* Frame content should be less or equal to frame-max - 8. */ |
| 82 | + public void testFrameSizes() |
| 83 | + throws IOException, InterruptedException |
| 84 | + { |
| 85 | + int howMuch = FRAME_MAX; |
| 86 | + produce(howMuch); |
| 87 | + /* Receive everything that was sent out. */ |
| 88 | + while (howMuch > 0) { |
| 89 | + Delivery delivery = consumer.nextDelivery(TIMEOUT); |
| 90 | + int received = delivery.getBody().length; |
| 91 | + assertTrue(received <= FRAME_MAX - 8); |
| 92 | + howMuch -= received; |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + /* Send out howMuch worth of gibberish */ |
| 97 | + protected void produce(int howMuch) |
| 98 | + throws IOException |
| 99 | + { |
| 100 | + while (howMuch > 0) { |
| 101 | + int size = (howMuch <= (FRAME_MAX-8)) ? howMuch : (FRAME_MAX-8); |
| 102 | + publish(new byte[size]); |
| 103 | + howMuch -= (FRAME_MAX-8); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + /* Publish a non-persistant, non-immediate message. */ |
| 108 | + private void publish(byte[] msg) |
| 109 | + throws IOException |
| 110 | + { |
| 111 | + channel.basicPublish(EXCHANGE_NAME, ROUTING_KEY, |
| 112 | + false, false, |
| 113 | + MessageProperties.MINIMAL_BASIC, |
| 114 | + msg); |
| 115 | + } |
| 116 | +} |
0 commit comments