11package com .rabbitmq .client .test .functional ;
22
33import com .rabbitmq .client .AMQP ;
4+ import com .rabbitmq .client .Channel ;
45import com .rabbitmq .client .GetResponse ;
56import com .rabbitmq .client .QueueingConsumer ;
67import com .rabbitmq .client .QueueingConsumer .Delivery ;
1617import java .util .concurrent .Callable ;
1718
1819public class DeadLetterExchange extends BrokerTestCase {
19- private static final String DLX = "dead.letter.exchange" ;
20- private static final String DLX_ARG = "x-dead-letter-exchange" ;
21- private static final String DLX_RK_ARG = "x-dead-letter-routing-key" ;
22- private static final String TEST_QUEUE_NAME = "test.queue.dead.letter" ;
23- private static final String DLQ = "queue.dlq" ;
24- private static final String DLQ2 = "queue.dlq2" ;
25- private static final int MSG_COUNT = 10 ;
26- private static final int MSG_COUNT_MANY = 1000 ;
27- private static final int TTL = 1000 ;
20+ public static final String DLX = "dead.letter.exchange" ;
21+ public static final String DLX_ARG = "x-dead-letter-exchange" ;
22+ public static final String DLX_RK_ARG = "x-dead-letter-routing-key" ;
23+ public static final String TEST_QUEUE_NAME = "test.queue.dead.letter" ;
24+ public static final String DLQ = "queue.dlq" ;
25+ public static final String DLQ2 = "queue.dlq2" ;
26+ public static final int MSG_COUNT = 10 ;
27+ public static final int MSG_COUNT_MANY = 1000 ;
28+ public static final int TTL = 1000 ;
2829
2930 @ Override
3031 protected void createResources () throws IOException {
@@ -348,19 +349,23 @@ private void deadLetterTest(Callable<?> deathTrigger,
348349
349350 deathTrigger .call ();
350351
351- consumeN (DLQ , MSG_COUNT , new WithResponse () {
352- @ SuppressWarnings ("unchecked" )
353- public void process (GetResponse getResponse ) {
354- Map <String , Object > headers = getResponse .getProps ().getHeaders ();
355- assertNotNull (headers );
356- ArrayList <Object > death = (ArrayList <Object >)headers .get ("x-death" );
357- assertNotNull (death );
358- assertEquals (1 , death .size ());
359- assertDeathReason (death , 0 , TEST_QUEUE_NAME , reason ,
360- "amq.direct" ,
361- Arrays .asList (new String []{"test" }));
362- }
363- });
352+ consume (channel , reason );
353+ }
354+
355+ public static void consume (final Channel channel , final String reason ) throws IOException {
356+ consumeN (channel , DLQ , MSG_COUNT , new WithResponse () {
357+ @ SuppressWarnings ("unchecked" )
358+ public void process (GetResponse getResponse ) {
359+ Map <String , Object > headers = getResponse .getProps ().getHeaders ();
360+ assertNotNull (headers );
361+ ArrayList <Object > death = (ArrayList <Object >) headers .get ("x-death" );
362+ assertNotNull (death );
363+ assertEquals (1 , death .size ());
364+ assertDeathReason (death , 0 , TEST_QUEUE_NAME , reason ,
365+ "amq.direct" ,
366+ Arrays .asList (new String []{"test" }));
367+ }
368+ });
364369 }
365370
366371 private void ttlTest (final long ttl ) throws Exception {
@@ -455,6 +460,12 @@ private void waitUntil(long when) throws Exception {
455460
456461 private void consumeN (String queue , int n , WithResponse withResponse )
457462 throws IOException
463+ {
464+ consumeN (channel , queue , n , withResponse );
465+ }
466+
467+ private static void consumeN (Channel channel , String queue , int n , WithResponse withResponse )
468+ throws IOException
458469 {
459470 for (int x = 0 ; x < n ; x ++) {
460471 GetResponse getResponse =
@@ -469,7 +480,7 @@ private void consumeN(String queue, int n, WithResponse withResponse)
469480 }
470481
471482 @ SuppressWarnings ("unchecked" )
472- private void assertDeathReason (List <Object > death , int num ,
483+ private static void assertDeathReason (List <Object > death , int num ,
473484 String queue , String reason ,
474485 String exchange , List <String > routingKeys )
475486 {
@@ -489,7 +500,7 @@ private void assertDeathReason(List<Object> death, int num,
489500 }
490501
491502 @ SuppressWarnings ("unchecked" )
492- private void assertDeathReason (List <Object > death , int num ,
503+ private static void assertDeathReason (List <Object > death , int num ,
493504 String queue , String reason ) {
494505 Map <String , Object > deathHeader =
495506 (Map <String , Object >)death .get (num );
0 commit comments