camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r712486 - in /activemq/camel/trunk/camel-core/src: main/java/org/apache/camel/component/list/ main/java/org/apache/camel/component/timer/ test/java/org/apache/camel/component/file/ test/java/org/apache/camel/component/list/
Date Sun, 09 Nov 2008 12:02:27 GMT
Author: davsclaus
Date: Sun Nov  9 04:02:27 2008
New Revision: 712486

URL: http://svn.apache.org/viewvc?rev=712486&view=rev
Log:
CAMEL-656: Polished list and timer component. And tried to fix a failing unit test on the
Bamboo, that happens rarely

Added:
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListRouteTest.java
  (contents, props changed)
      - copied, changed from r712398, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java?rev=712486&r1=712485&r2=712486&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/list/ListEndpoint.java
Sun Nov  9 04:02:27 2008
@@ -27,6 +27,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.Service;
 import org.apache.camel.impl.DefaultEndpoint;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.processor.loadbalancer.LoadBalancerConsumer;
@@ -39,24 +40,22 @@
  *
  * @version $Revision$
  */
-public class ListEndpoint extends DefaultEndpoint<Exchange> implements BrowsableEndpoint<Exchange>
{
+public class ListEndpoint extends DefaultEndpoint<Exchange> implements BrowsableEndpoint<Exchange>,
Service {
     private List<Exchange> exchanges;
     private TopicLoadBalancer loadBalancer = new TopicLoadBalancer();
+    // TODO: firing of property changes not implemented
     private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
 
     public ListEndpoint(String uri, CamelContext camelContext) {
         super(uri, camelContext);
-        reset();
     }
 
     public ListEndpoint(String uri, Component component) {
         super(uri, component);
-        reset();
     }
 
     public ListEndpoint(String endpointUri) {
         super(endpointUri);
-        reset();
     }
 
     public boolean isSingleton() {
@@ -91,16 +90,15 @@
         return new LoadBalancerConsumer(this, processor, loadBalancer);
     }
 
-    public void reset() {
-        exchanges = createExchangeList();
-    }
-
     protected List<Exchange> createExchangeList() {
         return new CopyOnWriteArrayList<Exchange>();
     }
 
     /**
      * Invoked on a message exchange being sent by a producer
+     *
+     * @param exchange the exchange
+     * @throws Exception is thrown if failed to process the exchange
      */
     protected void onExchange(Exchange exchange) throws Exception {
         exchanges.add(exchange);
@@ -108,4 +106,15 @@
         // lets fire any consumers
         loadBalancer.process(exchange);
     }
+
+    public void start() throws Exception {
+        exchanges = createExchangeList();
+    }
+
+    public void stop() throws Exception {
+        if (exchanges != null) {
+            exchanges.clear();
+            exchanges = null;
+        }
+    }
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java?rev=712486&r1=712485&r2=712486&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/timer/TimerConsumer.java
Sun Nov  9 04:02:27 2008
@@ -57,6 +57,7 @@
     @Override
     protected void doStop() throws Exception {
         task.cancel();
+        task = null;
     }
 
     protected void configureTask(TimerTask task, Timer timer) {
@@ -94,10 +95,13 @@
         // also set now on in header with same key as quaartz to be consistent
         exchange.getIn().setHeader("firedTime", now);
 
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Timer " + endpoint.getTimerName() + " is firing");
+        }
         try {
             getProcessor().process(exchange);
         } catch (Exception e) {
-            LOG.error("Caught: " + e, e);
+            getExceptionHandler().handleException(e);
         }
     }
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java?rev=712486&r1=712485&r2=712486&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/file/FileAsyncRouteTest.java
Sun Nov  9 04:02:27 2008
@@ -34,9 +34,9 @@
     protected Object expectedBody = "Hello there!";
     protected String uri = "file:target/test-async-inbox?delete=true&consumer.delay=10000&consumer.recursive=true";
 
-    CountDownLatch receivedLatch = new CountDownLatch(1);
-    CountDownLatch processingLatch = new CountDownLatch(1);
-    AtomicReference<File> file = new AtomicReference<File>();
+    private CountDownLatch receivedLatch = new CountDownLatch(1);
+    private CountDownLatch processingLatch = new CountDownLatch(1);
+    private AtomicReference<File> file = new AtomicReference<File>();
 
     @Override
     protected void setUp() throws Exception {
@@ -65,15 +65,13 @@
         // The file consumer support async processing of the exchange,
         // so the file should not get deleted until the exchange
         // finishes being asynchronously processed.
-        Thread.sleep(1000);
-        assertTrue("File should exist", file.exists());
+        assertTrue("File should exist", file.getAbsoluteFile().exists());
 
         // Release the async processing thread so that the exchange completes
-        // and the file
-        // gets deleted.
+        // and the file gets deleted.
         processingLatch.countDown();
-        Thread.sleep(1000);
-        assertFalse("File should not exist", file.exists());
+        Thread.sleep(500);
+        assertFalse("File should not exist", file.getAbsoluteFile().exists());
 
         result.assertIsSatisfied();
     }

Copied: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListRouteTest.java
(from r712398, activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListRouteTest.java?p2=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListRouteTest.java&p1=activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java&r1=712398&r2=712486&rev=712486&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListRouteTest.java
Sun Nov  9 04:02:27 2008
@@ -16,52 +16,37 @@
  */
 package org.apache.camel.component.list;
 
-import java.util.List;
-
 import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spi.BrowsableEndpoint;
-import org.apache.camel.util.CamelContextHelper;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 /**
  * @version $Revision$
  */
-public class ListTest extends ContextTestSupport {
-    private static final transient Log LOG = LogFactory.getLog(ListTest.class);
-
-    protected Object body1 = "one";
-    protected Object body2 = "two";
-
-    public void testListEndpoints() throws Exception {
-        template.sendBody("list:foo", body1);
-        template.sendBody("list:foo", body2);
-
-        List<BrowsableEndpoint> list = CamelContextHelper.getSingletonEndpoints(context,
BrowsableEndpoint.class);
-        assertEquals("number of endpoints", 2, list.size());
+public class ListRouteTest extends ContextTestSupport {
 
-        Thread.sleep(2000);
+    public void testListRoute() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World", "Bye World");
 
-        for (BrowsableEndpoint endpoint : list) {
-            List<Exchange> exchanges = endpoint.getExchanges();
+        template.sendBody("direct:start", "Hello World");
+        template.sendBody("direct:start", "Bye World");
 
-            LOG.debug(">>>> " + endpoint + " has: " + exchanges);
+        assertMockEndpointsSatisfied();
 
-            assertEquals("Exchanges received on " + endpoint, 2, exchanges.size());
+        BrowsableEndpoint list = context.getEndpoint("list:foo", BrowsableEndpoint.class);
 
-            assertInMessageBodyEquals(exchanges.get(0), body1);
-            assertInMessageBodyEquals(exchanges.get(1), body2);
-        }
+        mock.getExchanges().get(0).equals(list.getExchanges().get(0));
+        mock.getExchanges().get(1).equals(list.getExchanges().get(1));
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("list:foo").to("list:bar");
+                from("direct:start").to("list:foo").to("mock:result");
             }
         };
     }
-}
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListRouteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListRouteTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/component/list/ListRouteTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 



Mime
View raw message