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 GoPivotal, Inc.
14+ // Copyright (c) 2007-2013 GoPivotal, Inc. All rights reserved.
15+ //
16+
117package com .rabbitmq .client .test .functional ;
218
3- import com .rabbitmq .client .AMQP ;
419import com .rabbitmq .client .Channel ;
520import com .rabbitmq .client .GetResponse ;
621import com .rabbitmq .client .test .BrokerTestCase ;
1227import java .util .Map ;
1328import java .util .Set ;
1429
15- /**
16- *
17- */
1830public class Policies extends BrokerTestCase {
31+ private static final int DELAY = 10 ; // MILLIS
32+
1933 @ Override protected void createResources () throws IOException {
2034 setPolicy ("AE" , "^has-ae" , "{\\ \" alternate-exchange\\ \" :\\ \" ae\\ \" }" );
2135 setPolicy ("DLX" , "^has-dlx" , "{\\ \" dead-letter-exchange\\ \" :\\ \" dlx\\ \" \\ ,\\ \" dead-letter-routing-key\\ \" :\\ \" rk\\ \" }" );
22- setPolicy ("TTL" , "^has-ttl" , "{\\ \" message-ttl\\ \" :10 }" );
23- setPolicy ("Expires" , "^has-expires" , "{\\ \" expires\\ \" :10 }" );
36+ setPolicy ("TTL" , "^has-ttl" , "{\\ \" message-ttl\\ \" :" + DELAY + " }" );
37+ setPolicy ("Expires" , "^has-expires" , "{\\ \" expires\\ \" :" + DELAY + " }" );
2438 setPolicy ("MaxLength" , "^has-max-length" , "{\\ \" max-length\\ \" :1}" );
2539 channel .exchangeDeclare ("has-ae" , "fanout" );
2640 Map <String , Object > args = new HashMap <String , Object >();
@@ -56,13 +70,13 @@ public void testDeadLetterExchange() throws IOException, InterruptedException {
5670 channel .exchangeDeclare ("dlx" , "fanout" , false , true , null );
5771 channel .queueBind (dest , "dlx" , "" );
5872 basicPublishVolatile (src );
59- Thread .sleep (10 );
73+ Thread .sleep (DELAY );
6074 GetResponse resp = channel .basicGet (dest , true );
6175 assertEquals ("rk" , resp .getEnvelope ().getRoutingKey ());
6276 clearPolicies ();
6377
6478 basicPublishVolatile (src );
65- Thread .sleep (10 );
79+ Thread .sleep (DELAY );
6680 assertDelivered (dest , 0 );
6781 }
6882
@@ -76,59 +90,59 @@ public void testDeadLetterExchangeArgs() throws IOException, InterruptedExceptio
7690 channel .exchangeDeclare ("dlx2" , "fanout" , false , true , null );
7791 channel .queueBind (dest , "dlx2" , "" );
7892 basicPublishVolatile (src );
79- Thread .sleep (10 );
93+ Thread .sleep (DELAY );
8094 GetResponse resp = channel .basicGet (dest , true );
8195 assertEquals ("rk2" , resp .getEnvelope ().getRoutingKey ());
8296 }
8397
8498 public void testTTL () throws IOException , InterruptedException {
8599 String q = declareQueue ("has-ttl" , null );
86100 basicPublishVolatile (q );
87- Thread .sleep (20 );
101+ Thread .sleep (2 * DELAY );
88102 assertDelivered (q , 0 );
89103 clearPolicies ();
90104
91105 basicPublishVolatile (q );
92- Thread .sleep (20 );
106+ Thread .sleep (2 * DELAY );
93107 assertDelivered (q , 1 );
94108 }
95109
96110 // Test that we get lower of args and policy
97111 public void testTTLArgs () throws IOException , InterruptedException {
98- String q = declareQueue ("has-ttl" , ttlArgs (30 ));
112+ String q = declareQueue ("has-ttl" , ttlArgs (3 * DELAY ));
99113 basicPublishVolatile (q );
100- Thread .sleep (20 );
114+ Thread .sleep (2 * DELAY );
101115 assertDelivered (q , 0 );
102116 clearPolicies ();
103117
104118 basicPublishVolatile (q );
105- Thread .sleep (20 );
119+ Thread .sleep (2 * DELAY );
106120 assertDelivered (q , 1 );
107121 basicPublishVolatile (q );
108- Thread .sleep (40 );
122+ Thread .sleep (4 * DELAY );
109123 assertDelivered (q , 0 );
110124 }
111125
112126 public void testExpires () throws IOException , InterruptedException {
113127 String q = declareQueue ("has-expires" , null );
114- Thread .sleep (20 );
128+ Thread .sleep (2 * DELAY );
115129 assertFalse (queueExists (q ));
116130 clearPolicies ();
117131
118132 q = declareQueue ("has-expires" , null );
119- Thread .sleep (20 );
133+ Thread .sleep (2 * DELAY );
120134 assertTrue (queueExists (q ));
121135 }
122136
123137 // Test that we get lower of args and policy
124138 public void testExpiresArgs () throws IOException , InterruptedException {
125- String q = declareQueue ("has-expires" , args ("x-expires" , 30 ));
126- Thread .sleep (20 );
139+ String q = declareQueue ("has-expires" , args ("x-expires" , 3 * DELAY ));
140+ Thread .sleep (2 * DELAY );
127141 assertFalse (queueExists (q ));
128142 clearPolicies ();
129143
130- q = declareQueue ("has-expires" , args ("x-expires" , 30 ));
131- Thread .sleep (20 );
144+ q = declareQueue ("has-expires" , args ("x-expires" , 3 * DELAY ));
145+ Thread .sleep (2 * DELAY );
132146 assertTrue (queueExists (q ));
133147 }
134148
0 commit comments