|
| 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.AMQP; |
| 35 | +import com.rabbitmq.client.test.BrokerTestCase; |
| 36 | + |
| 37 | +import java.io.IOException; |
| 38 | +import java.util.Collections; |
| 39 | +import java.util.Map; |
| 40 | + |
| 41 | +/** |
| 42 | + * |
| 43 | + */ |
| 44 | +public class PerQueueTTL extends BrokerTestCase { |
| 45 | + |
| 46 | + private static final String TTL_ARG = "x-message-ttl"; |
| 47 | + |
| 48 | + private static final String TTL_QUEUE_NAME = "queue.ttl"; |
| 49 | + |
| 50 | + private static final String TTL_INVALID_QUEUE_NAME = "invalid.queue.ttl"; |
| 51 | + |
| 52 | + public void testCreateQueueWithTTL() throws IOException { |
| 53 | + AMQP.Queue.DeclareOk declareOk = declareQueue(TTL_QUEUE_NAME, 2000); |
| 54 | + assertNotNull(declareOk); |
| 55 | + } |
| 56 | + |
| 57 | + public void testCreateQueueWithInvalidTTL() throws Exception { |
| 58 | + try { |
| 59 | + declareQueue(TTL_INVALID_QUEUE_NAME, "foobar"); |
| 60 | + fail("Should not be able to declare a queue with a non-long value for x-message-ttl"); |
| 61 | + } catch (IOException e) { |
| 62 | + assertNotNull(e); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + public void testCreateQueueWithZeroTTL() throws Exception { |
| 67 | + try { |
| 68 | + declareQueue(TTL_INVALID_QUEUE_NAME, 0); |
| 69 | + fail("Should not be able to declare a queue with zero for x-message-ttl"); |
| 70 | + } catch (IOException e) { |
| 71 | + assertNotNull(e); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + private AMQP.Queue.DeclareOk declareQueue(String name, Object ttlValue) throws IOException { |
| 76 | + AMQP.Queue.DeclareOk declareOk = this.channel.queueDeclare(name, false, false, false, |
| 77 | + Collections.<String, Object>singletonMap(TTL_ARG, ttlValue)); |
| 78 | + return declareOk; |
| 79 | + } |
| 80 | +} |
0 commit comments