From 893f1439df3b512458d6fa6a4a83526f43f72780 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Thu, 10 May 2012 08:57:35 -0400 Subject: [PATCH] AMQP-208 Polishing Remove continue statements; fix whitespace issues. --- .../amqp/rabbit/core/RabbitAdmin.java | 42 +++++++------- .../core/RabbitAdminIntegrationTests.java | 56 +++++++++---------- 2 files changed, 47 insertions(+), 51 deletions(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java index f7bd3f87..e436dda6 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java @@ -98,7 +98,7 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Initiali if (isDeletingDefaultExchange(exchangeName)) { return true; } - + try { channel.exchangeDelete(exchangeName); } catch (IOException e) { @@ -188,7 +188,7 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Initiali if (isRemovingImplicitQueueBinding(binding)) { return null; } - + channel.queueUnbind(binding.getDestination(), binding.getExchange(), binding.getRoutingKey(), binding.getArguments()); } else { @@ -325,13 +325,11 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Initiali if (logger.isDebugEnabled()) { logger.debug("declaring Exchange '" + exchange.getName() + "'"); } - - if (isDeclaringDefaultExchange(exchange)) { - continue; + + if (!isDeclaringDefaultExchange(exchange)) { + channel.exchangeDeclare(exchange.getName(), exchange.getType(), exchange.isDurable(), + exchange.isAutoDelete(), exchange.getArguments()); } - - channel.exchangeDeclare(exchange.getName(), exchange.getType(), exchange.isDurable(), - exchange.isAutoDelete(), exchange.getArguments()); } } @@ -356,14 +354,12 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Initiali + ")] to exchange [" + binding.getExchange() + "] with routing key [" + binding.getRoutingKey() + "]"); } - - if (binding.isDestinationQueue()) { - if (isDeclaringImplicitQueueBinding(binding)) { - continue; - } - channel.queueBind(binding.getDestination(), binding.getExchange(), binding.getRoutingKey(), - binding.getArguments()); + if (binding.isDestinationQueue()) { + if (!isDeclaringImplicitQueueBinding(binding)) { + channel.queueBind(binding.getDestination(), binding.getExchange(), binding.getRoutingKey(), + binding.getArguments()); + } } else { channel.exchangeBind(binding.getDestination(), binding.getExchange(), binding.getRoutingKey(), binding.getArguments()); @@ -380,7 +376,7 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Initiali } return false; } - + private boolean isDeletingDefaultExchange(String exchangeName) { if (isDefaultExchange(exchangeName)) { if (logger.isDebugEnabled()) { @@ -390,30 +386,30 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Initiali } return false; } - + private boolean isDefaultExchange(String exchangeName) { return DEFAULT_EXCHANGE_NAME.equals(exchangeName); } - + private boolean isDeclaringImplicitQueueBinding(Binding binding) { if (isImplicitQueueBinding(binding)) { if (logger.isDebugEnabled()) { logger.debug("The default exchange is implicitly bound to every queue, with a routing key equal to the queue name."); - } + } return true; } return false; } - + private boolean isRemovingImplicitQueueBinding(Binding binding) { if (isImplicitQueueBinding(binding)) { if (logger.isDebugEnabled()) { - logger.debug("Cannot remove implicit default exchange binding to queue."); - } + logger.debug("Cannot remove implicit default exchange binding to queue."); + } return true; } return false; - } + } private boolean isImplicitQueueBinding(Binding binding) { return isDefaultExchange(binding.getExchange()) && binding.getDestination().equals(binding.getRoutingKey()); diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminIntegrationTests.java index d271d8c6..be158653 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/core/RabbitAdminIntegrationTests.java @@ -151,13 +151,13 @@ public class RabbitAdminIntegrationTests { assertTrue(rabbitAdmin.deleteQueue(queue.getName())); assertFalse(queueExists(queue)); } - + @Test public void testDeclareExchangeWithDefaultExchange() throws Exception { Exchange exchange = new DirectExchange(RabbitAdmin.DEFAULT_EXCHANGE_NAME); - + rabbitAdmin.declareExchange(exchange); - + // Pass by virtue of RabbitMQ not firing a 403 reply code } @@ -165,20 +165,20 @@ public class RabbitAdminIntegrationTests { public void testSpringWithDefaultExchange() throws Exception { Exchange exchange = new DirectExchange(RabbitAdmin.DEFAULT_EXCHANGE_NAME); context.getBeanFactory().registerSingleton("foo", exchange); - rabbitAdmin.afterPropertiesSet(); - + rabbitAdmin.afterPropertiesSet(); + rabbitAdmin.initialize(); - + // Pass by virtue of RabbitMQ not firing a 403 reply code } - + @Test public void testDeleteExchangeWithDefaultExchange() throws Exception { boolean result = rabbitAdmin.deleteExchange(RabbitAdmin.DEFAULT_EXCHANGE_NAME); - - assertTrue(result); - } - + + assertTrue(result); + } + @Test public void testDeclareBindingWithDefaultExchangeImplicitBinding() throws Exception { Exchange exchange = new DirectExchange(RabbitAdmin.DEFAULT_EXCHANGE_NAME); @@ -186,13 +186,13 @@ public class RabbitAdminIntegrationTests { final Queue queue = new Queue(queueName, false, false, false); rabbitAdmin.declareQueue(queue); Binding binding = new Binding(queueName, DestinationType.QUEUE, exchange.getName(), queueName, null); - + rabbitAdmin.declareBinding(binding); - + // Pass by virtue of RabbitMQ not firing a 403 reply code for both exchange and binding declaration assertTrue(queueExists(queue)); } - + @Test public void testSpringWithDefaultExchangeImplicitBinding() throws Exception { Exchange exchange = new DirectExchange(RabbitAdmin.DEFAULT_EXCHANGE_NAME); @@ -203,25 +203,25 @@ public class RabbitAdminIntegrationTests { Binding binding = new Binding(queueName, DestinationType.QUEUE, exchange.getName(), queueName, null); context.getBeanFactory().registerSingleton("baz", binding); rabbitAdmin.afterPropertiesSet(); - + rabbitAdmin.initialize(); - + // Pass by virtue of RabbitMQ not firing a 403 reply code for both exchange and binding declaration assertTrue(queueExists(queue)); - } - + } + @Test public void testRemoveBindingWithDefaultExchangeImplicitBinding() throws Exception { String queueName = "test.queue"; final Queue queue = new Queue(queueName, false, false, false); rabbitAdmin.declareQueue(queue); Binding binding = new Binding(queueName, DestinationType.QUEUE, RabbitAdmin.DEFAULT_EXCHANGE_NAME, queueName, null); - + rabbitAdmin.removeBinding(binding); - + // Pass by virtue of RabbitMQ not firing a 403 reply code } - + @Test public void testDeclareBindingWithDefaultExchangeNonImplicitBinding() throws Exception { Exchange exchange = new DirectExchange(RabbitAdmin.DEFAULT_EXCHANGE_NAME); @@ -229,7 +229,7 @@ public class RabbitAdminIntegrationTests { final Queue queue = new Queue(queueName, false, false, false); rabbitAdmin.declareQueue(queue); Binding binding = new Binding(queueName, DestinationType.QUEUE, exchange.getName(), "test.routingKey", null); - + try { rabbitAdmin.declareBinding(binding); } catch (AmqpIOException ex) { @@ -243,7 +243,7 @@ public class RabbitAdminIntegrationTests { assertTrue(rootCause.getMessage().contains("operation not permitted on the default exchange")); } } - + @Test public void testSpringWithDefaultExchangeNonImplicitBinding() throws Exception { Exchange exchange = new DirectExchange(RabbitAdmin.DEFAULT_EXCHANGE_NAME); @@ -254,7 +254,7 @@ public class RabbitAdminIntegrationTests { Binding binding = new Binding(queueName, DestinationType.QUEUE, exchange.getName(), "test.routingKey", null); context.getBeanFactory().registerSingleton("baz", binding); rabbitAdmin.afterPropertiesSet(); - + try { rabbitAdmin.declareBinding(binding); } catch (AmqpIOException ex) { @@ -267,10 +267,10 @@ public class RabbitAdminIntegrationTests { assertTrue(rootCause.getMessage().contains("reply-code=403")); assertTrue(rootCause.getMessage().contains("operation not permitted on the default exchange")); } - } - + } + /** - * Verify that a queue exists using the native Rabbit API to bypass all the connection and + * Verify that a queue exists using the native Rabbit API to bypass all the connection and * channel caching and callbacks in Spring AMQP. * * @param Queue The queue to verify @@ -292,5 +292,5 @@ public class RabbitAdminIntegrationTests { } finally { connection.close(); } - } + } }