camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject svn commit: r1425103 - in /camel/branches/camel-2.10.x: ./ camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringStreamResequencerTest.java
Date Fri, 21 Dec 2012 19:29:28 GMT
Author: bvahdat
Date: Fri Dec 21 19:29:28 2012
New Revision: 1425103

URL: http://svn.apache.org/viewvc?rev=1425103&view=rev
Log:
Merged revisions 1425102 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1425102 | bvahdat | 2012-12-21 20:26:13 +0100 (Fr, 21 Dez 2012) | 1 line
  
  CAMEL-5900: Clean-up the test being mentioned by the user.
........

Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java
    camel/branches/camel-2.10.x/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringStreamResequencerTest.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1425102

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java?rev=1425103&r1=1425102&r2=1425103&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/processor/StreamResequencerTest.java
Fri Dec 21 19:29:28 2012
@@ -17,8 +17,8 @@
 package org.apache.camel.processor;
 
 import java.util.List;
+import java.util.Random;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 import org.apache.camel.Channel;
 import org.apache.camel.ContextTestSupport;
@@ -28,15 +28,12 @@ import org.apache.camel.Processor;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.Route;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.impl.EventDrivenConsumerRoute;
+import org.apache.camel.util.ServiceHelper;
 
 public class StreamResequencerTest extends ContextTestSupport {
 
-    protected MockEndpoint resultEndpoint;
-
-    protected void sendBodyAndHeader(String endpointUri, final Object body,
-                                     final String headerName, final Object headerValue) {
+    protected void sendBodyAndHeader(String endpointUri, final Object body, final String
headerName, final Object headerValue) {
         template.send(endpointUri, new Processor() {
             public void process(Exchange exchange) {
                 Message in = exchange.getIn();
@@ -48,44 +45,46 @@ public class StreamResequencerTest exten
     }
 
     public void testSendMessagesInWrongOrderButReceiveThemInCorrectOrder() throws Exception
{
-        resultEndpoint.expectedBodiesReceived("msg1", "msg2", "msg3", "msg4");
+        getMockEndpoint("mock:result").expectedBodiesReceived("msg1", "msg2", "msg3", "msg4");
+
         sendBodyAndHeader("direct:start", "msg4", "seqnum", 4L);
         sendBodyAndHeader("direct:start", "msg1", "seqnum", 1L);
         sendBodyAndHeader("direct:start", "msg3", "seqnum", 3L);
         sendBodyAndHeader("direct:start", "msg2", "seqnum", 2L);
-        resultEndpoint.assertIsSatisfied();
+
+        assertMockEndpointsSatisfied();
     }
 
     public void testMultithreaded() throws Exception {
         int numMessages = 100;
 
-        ExecutorService service = Executors.newFixedThreadPool(2);
-        service.execute(new Sender(context.createProducerTemplate(), 0, numMessages, 2));
-        service.execute(new Sender(context.createProducerTemplate(), 1, numMessages + 1,
2));
+        ProducerTemplate producerTemplate = context.createProducerTemplate();
+        ProducerTemplate producerTemplate2 = context.createProducerTemplate();
+
+        ExecutorService service = context.getExecutorServiceManager().newFixedThreadPool(this,
getName(), 2);
+
+        service.execute(new Sender(producerTemplate, 0, numMessages, 2));
+        service.execute(new Sender(producerTemplate2, 1, numMessages, 2));
 
         Object[] bodies = new Object[numMessages];
         for (int i = 0; i < numMessages; i++) {
             bodies[i] = "msg" + i;
         }
 
-        resultEndpoint.expectedBodiesReceived(bodies);
-        resultEndpoint.setResultWaitTime(20000);
-        resultEndpoint.assertIsSatisfied();
+        getMockEndpoint("mock:result").expectedBodiesReceivedInAnyOrder(bodies);
+        getMockEndpoint("mock:result").setResultWaitTime(20000);
 
-        service.shutdownNow();
-    }
-    
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        disableJMX();
-        resultEndpoint = getMockEndpoint("mock:result");
+        assertMockEndpointsSatisfied();
+
+        ServiceHelper.stopServices(producerTemplate, producerTemplate2);
     }
 
     @Override
-    protected void tearDown() throws Exception {
-        super.tearDown();
-        enableJMX();
+    protected boolean useJmx() {
+        boolean enable = "testStreamResequencerTypeWithJmx".equals(getName());
+        log.info("Going to {} JMX for the test {}", (enable ? "enable" : "disable"), getName());
+
+        return enable;
     }
 
     protected RouteBuilder createRouteBuilder() {
@@ -103,8 +102,6 @@ public class StreamResequencerTest exten
     }
 
     public void testStreamResequencerTypeWithoutJmx() throws Exception {
-        log.debug("This will now fail");
-        disableJMX();
         doTestStreamResequencerType();
     }
 
@@ -120,34 +117,36 @@ public class StreamResequencerTest exten
         assertIsInstanceOf(DefaultErrorHandler.class, channel.getErrorHandler());
         assertIsInstanceOf(StreamResequencer.class, channel.getNextProcessor());
     }
-    
-    private static class Sender extends Thread {
-        
-        ProducerTemplate template;
-
-        int start;
-        int end;
-        int increment;
-        
+
+    private static class Sender implements Runnable {
+
+        private final ProducerTemplate template;
+        private final int start;
+        private final int end;
+        private final int increment;
+        private final Random random;
+
         public Sender(ProducerTemplate template, int start, int end, int increment) {
             this.template = template;
             this.start = start;
             this.end = end;
             this.increment = increment;
+            random = new Random();
         }
 
         @Override
         public void run() {
             for (long i = start; i < end; i += increment) {
                 try {
-                    Thread.sleep(4);
+                    // let's sleep randomly
+                    Thread.sleep(random.nextInt(20));
                 } catch (InterruptedException e) {
-                    // ignore
+                    Thread.currentThread().interrupt();
                 }
+
                 template.sendBodyAndHeader("direct:start", "msg" + i, "seqnum", i);
             }
         }
-        
+
     }
 }
-

Modified: camel/branches/camel-2.10.x/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringStreamResequencerTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringStreamResequencerTest.java?rev=1425103&r1=1425102&r2=1425103&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringStreamResequencerTest.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringStreamResequencerTest.java
Fri Dec 21 19:29:28 2012
@@ -16,13 +16,14 @@
  */
 package org.apache.camel.spring.processor;
 
-
 import org.apache.camel.CamelContext;
 import org.apache.camel.processor.StreamResequencerTest;
-import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
 public class SpringStreamResequencerTest extends StreamResequencerTest {
+
+    @Override
     protected CamelContext createCamelContext() throws Exception {
         return createSpringCamelContext(this, "org/apache/camel/spring/processor/streamResequencer.xml");
     }



Mime
View raw message