camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [3/4] git commit: Fix and improve Re-connection integration test
Date Fri, 06 Jun 2014 05:02:56 GMT
Fix and improve Re-connection integration test


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8029d0c7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8029d0c7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8029d0c7

Branch: refs/heads/master
Commit: 8029d0c7663504b248f94f7daf36eda3e0b61060
Parents: 1191e19
Author: Gerald Quintana <gerald.quintana@zenika.com>
Authored: Tue May 6 22:42:11 2014 +0200
Committer: Gerald Quintana <gerald.quintana@zenika.com>
Committed: Wed May 7 09:02:21 2014 +0200

----------------------------------------------------------------------
 .../component/rabbitmq/RabbitMQConsumer.java    |  6 +--
 .../component/rabbitmq/RabbitMQProducer.java    |  2 +
 .../rabbitmq/RabbitMQReConnectionIntTest.java   | 42 +++++++++++---------
 3 files changed, 29 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/8029d0c7/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQConsumer.java
b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQConsumer.java
index 0bdc93b..18ed62f 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQConsumer.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQConsumer.java
@@ -63,14 +63,14 @@ public class RabbitMQConsumer extends DefaultConsumer {
         log.trace("Creating channel...");
         this.channel = conn.createChannel();
         log.debug("Created channel: {}", channel);
-    }
+
+		getEndpoint().declareExchangeAndQueue(channel);
+	}
 
     /**
      * If needed, create Exchange and Queue, then add message listener
      */
     private void addConsumer() throws IOException {
-        getEndpoint().declareExchangeAndQueue(channel);
-
         channel.basicConsume(endpoint.getQueue(), endpoint.isAutoAck(),
                 new RabbitConsumer(this, channel));
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/8029d0c7/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQProducer.java
b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQProducer.java
index 03177e2..f8596c9 100644
--- a/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQProducer.java
+++ b/components/camel-rabbitmq/src/main/java/org/apache/camel/component/rabbitmq/RabbitMQProducer.java
@@ -56,6 +56,8 @@ public class RabbitMQProducer extends DefaultProducer {
         log.trace("Creating channel...");
         this.channel = conn.createChannel();
         log.debug("Created channel: {}", channel);
+
+		getEndpoint().declareExchangeAndQueue(this.channel);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/8029d0c7/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQReConnectionIntTest.java
----------------------------------------------------------------------
diff --git a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQReConnectionIntTest.java
b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQReConnectionIntTest.java
index 6a63948..512aed4 100644
--- a/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQReConnectionIntTest.java
+++ b/components/camel-rabbitmq/src/test/java/org/apache/camel/component/rabbitmq/RabbitMQReConnectionIntTest.java
@@ -14,11 +14,11 @@ import java.util.concurrent.TimeUnit;
  * Integration test to check that RabbitMQ Endpoint is able to reconnect to broker when broker
  * is not avaibable.
  * <ul>
- *     <li>Stop the broker</li>
- *     <li>Run the test: the producer complains it can not send messages, the consumer
is silent</li>
- *     <li>Start the broker: the producer sends messages, and the consumer receives
messages</li>
- *     <li>Stop the broker: the producer complains it can not send messages, the consumer
is silent</li>
- *     <li>Start the broker: the producer sends messages, and the consumer receives
messages</li>
+ * <li>Stop the broker</li>
+ * <li>Run the test: the producer complains it can not send messages, the consumer
is silent</li>
+ * <li>Start the broker: the producer sends messages, and the consumer receives messages</li>
+ * <li>Stop the broker: the producer complains it can not send messages, the consumer
is silent</li>
+ * <li>Start the broker: the producer sends messages, and the consumer receives messages</li>
  * </ul>
  */
 public class RabbitMQReConnectionIntTest extends CamelTestSupport {
@@ -28,14 +28,17 @@ public class RabbitMQReConnectionIntTest extends CamelTestSupport {
     protected ProducerTemplate directProducer;
 
     @EndpointInject(uri = "rabbitmq:localhost:5672/" + EXCHANGE + "?username=cameltest&password=cameltest"
+
-            "&queue=q3&routingKey=rk3"+
+            "&queue=q3&routingKey=rk3" +
             "&automaticRecoveryEnabled=true" +
             "&requestedHeartbeat=1000" +
             "&connectionTimeout=5000")
     private Endpoint rabbitMQEndpoint;
 
-    @EndpointInject(uri = "mock:result")
-    private MockEndpoint mockEndpoint;
+    @EndpointInject(uri = "mock:producing")
+    private MockEndpoint producingMockEndpoint;
+
+    @EndpointInject(uri = "mock:consuming")
+    private MockEndpoint consumingMockEndpoint;
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -46,32 +49,35 @@ public class RabbitMQReConnectionIntTest extends CamelTestSupport {
                 from("direct:rabbitMQ")
                         .id("producingRoute")
                         .onException(AlreadyClosedException.class, ConnectException.class)
-                            .maximumRedeliveries(10)
-                            .redeliveryDelay(500L)
-                            .end()
+                        .maximumRedeliveries(10)
+                        .redeliveryDelay(500L)
+                        .end()
                         .log("Sending message")
-                        .inOnly(rabbitMQEndpoint);
+                        .inOnly(rabbitMQEndpoint)
+                        .to(producingMockEndpoint);
                 from(rabbitMQEndpoint)
                         .id("consumingRoute")
                         .log("Receiving message")
-                        .to(mockEndpoint);
+                        .to(consumingMockEndpoint);
             }
         };
     }
+
     @Test
     public void testSendEndReceive() throws Exception {
-        int nbMessages=100;
-        int failedMessages=0;
-        for(int i=0;i<nbMessages;i++) {
+        int nbMessages = 50;
+        int failedMessages = 0;
+        for (int i = 0; i < nbMessages; i++) {
             try {
-                directProducer.sendBodyAndHeader("Message #"+i, RabbitMQConstants.ROUTING_KEY,
"rk3");
+                directProducer.sendBodyAndHeader("Message #" + i, RabbitMQConstants.ROUTING_KEY,
"rk3");
             } catch (CamelExecutionException e) {
                 log.debug("Can not send message", e);
                 failedMessages++;
             }
             Thread.sleep(500L);
         }
-        mockEndpoint.assertExchangeReceived(nbMessages-failedMessages);
+        producingMockEndpoint.expectedMessageCount(nbMessages - failedMessages);
+        consumingMockEndpoint.expectedMessageCount(nbMessages - failedMessages);
         assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
     }
 }


Mime
View raw message