camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: Fixed test
Date Tue, 08 Oct 2013 08:06:57 GMT
Updated Branches:
  refs/heads/camel-2.12.x b5a166f9e -> 04dfcd29a
  refs/heads/master 4e9f47649 -> b62e88ff6


Fixed test


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

Branch: refs/heads/master
Commit: b62e88ff618d9803d06847ba8f88afbbd8d94aac
Parents: 4e9f476
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Oct 8 10:05:57 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Oct 8 10:06:26 2013 +0200

----------------------------------------------------------------------
 .../camel/processor/ShutdownDeferTest.java      | 39 ++++++++++++++---
 .../camel/processor/ShutdownNotDeferTest.java   | 41 +++++++++++++++---
 .../processor/SpringShutdownDeferTest.java      | 32 --------------
 .../processor/SpringShutdownNotDeferTest.java   | 32 --------------
 .../spring/processor/ShutdownDeferTest.xml      | 45 --------------------
 .../spring/processor/ShutdownNotDeferTest.xml   | 43 -------------------
 6 files changed, 67 insertions(+), 165 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b62e88ff/camel-core/src/test/java/org/apache/camel/processor/ShutdownDeferTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ShutdownDeferTest.java b/camel-core/src/test/java/org/apache/camel/processor/ShutdownDeferTest.java
index c4aed11..5220ed4 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ShutdownDeferTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ShutdownDeferTest.java
@@ -16,8 +16,16 @@
  */
 package org.apache.camel.processor;
 
+import java.io.File;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.camel.Component;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.FileConsumer;
+import org.apache.camel.component.file.FileEndpoint;
+import org.apache.camel.component.file.GenericFileOperations;
 import org.apache.camel.component.mock.MockEndpoint;
 
 import static org.apache.camel.ShutdownRoute.Defer;
@@ -27,6 +35,8 @@ import static org.apache.camel.ShutdownRoute.Defer;
  */
 public class ShutdownDeferTest extends ContextTestSupport {
 
+    private static final AtomicBoolean consumerSuspended = new AtomicBoolean();
+
     @Override
     protected void setUp() throws Exception {
         deleteDirectory("target/deferred");
@@ -34,9 +44,6 @@ public class ShutdownDeferTest extends ContextTestSupport {
     }
 
     public void testShutdownDeferred() throws Exception {
-        // give it 20 seconds to shutdown
-        context.getShutdownStrategy().setTimeout(20);
-        
         MockEndpoint bar = getMockEndpoint("mock:bar");
         bar.expectedMinimumMessageCount(1);
 
@@ -52,8 +59,7 @@ public class ShutdownDeferTest extends ContextTestSupport {
 
         context.stop();
 
-        // should route all 5
-        assertEquals(5, bar.getReceivedCounter());
+        assertFalse("Should not have been suspended", consumerSuspended.get());
     }
 
     @Override
@@ -69,7 +75,10 @@ public class ShutdownDeferTest extends ContextTestSupport {
                 // use file component to transfer files from route 1 -> route 2 as it
                 // will normally suspend, but by deferring this we can let route 1
                 // complete while shutting down
-                from("file://target/deferred")
+                MyDeferFileEndpoint defer = new MyDeferFileEndpoint("file://target/deferred",
getContext().getComponent("file"));
+                defer.setFile(new File("target/deferred"));
+
+                from(defer)
                     // defer shutting down this route as the 1st route depends upon it
                     .startupOrder(2).shutdownRoute(Defer)
                     .to("mock:bar");
@@ -77,4 +86,22 @@ public class ShutdownDeferTest extends ContextTestSupport {
             // END SNIPPET: e1
         };
     }
+
+    private static final class MyDeferFileEndpoint extends FileEndpoint {
+
+        private MyDeferFileEndpoint(String endpointUri, Component component) {
+            super(endpointUri, component);
+        }
+
+        @Override
+        protected FileConsumer newFileConsumer(Processor processor, GenericFileOperations<File>
operations) {
+            return new FileConsumer(this, processor, operations) {
+                @Override
+                protected void doSuspend() throws Exception {
+                    consumerSuspended.set(true);
+                    super.doSuspend();
+                }
+            };
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b62e88ff/camel-core/src/test/java/org/apache/camel/processor/ShutdownNotDeferTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/ShutdownNotDeferTest.java
b/camel-core/src/test/java/org/apache/camel/processor/ShutdownNotDeferTest.java
index d72ae61..5a8156d 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/ShutdownNotDeferTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/ShutdownNotDeferTest.java
@@ -16,8 +16,16 @@
  */
 package org.apache.camel.processor;
 
+import java.io.File;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.camel.Component;
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.file.FileConsumer;
+import org.apache.camel.component.file.FileEndpoint;
+import org.apache.camel.component.file.GenericFileOperations;
 import org.apache.camel.component.mock.MockEndpoint;
 
 import static org.apache.camel.ShutdownRoute.Default;
@@ -27,6 +35,8 @@ import static org.apache.camel.ShutdownRoute.Default;
  */
 public class ShutdownNotDeferTest extends ContextTestSupport {
 
+    private static final AtomicBoolean consumerSuspended = new AtomicBoolean();
+
     @Override
     protected void setUp() throws Exception {
         deleteDirectory("target/deferred");
@@ -34,9 +44,6 @@ public class ShutdownNotDeferTest extends ContextTestSupport {
     }
 
     public void testShutdownNotDeferred() throws Exception {
-        // give it 20 seconds to shutdown
-        context.getShutdownStrategy().setTimeout(20);
-
         MockEndpoint bar = getMockEndpoint("mock:bar");
         bar.expectedMinimumMessageCount(1);
 
@@ -50,8 +57,7 @@ public class ShutdownNotDeferTest extends ContextTestSupport {
 
         context.stop();
 
-        // should not route all 5
-        assertTrue("Should NOT complete all messages, was " + bar.getReceivedCounter(), bar.getReceivedCounter()
< 5);
+        assertTrue("Should have been suspended", consumerSuspended.get());
     }
 
     @Override
@@ -61,14 +67,35 @@ public class ShutdownNotDeferTest extends ContextTestSupport {
             public void configure() throws Exception {
                 from("seda:foo")
                     .startupOrder(1)
-                    .delay(1000).to("file://target/deferred");
+                    .to("file://target/deferred");
 
                 // use file component to transfer files from route 1 -> route 2
-                from("file://target/deferred")
+                MyDeferFileEndpoint defer = new MyDeferFileEndpoint("file://target/deferred",
getContext().getComponent("file"));
+                defer.setFile(new File("target/deferred"));
+
+                from(defer)
                     // do NOT defer it but use default for testing this
                     .startupOrder(2).shutdownRoute(Default)
                     .to("mock:bar");
             }
         };
     }
+
+    private static final class MyDeferFileEndpoint extends FileEndpoint {
+
+        private MyDeferFileEndpoint(String endpointUri, Component component) {
+            super(endpointUri, component);
+        }
+
+        @Override
+        protected FileConsumer newFileConsumer(Processor processor, GenericFileOperations<File>
operations) {
+            return new FileConsumer(this, processor, operations) {
+                @Override
+                protected void doSuspend() throws Exception {
+                    consumerSuspended.set(true);
+                    super.doSuspend();
+                }
+            };
+        }
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/b62e88ff/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringShutdownDeferTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringShutdownDeferTest.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringShutdownDeferTest.java
deleted file mode 100644
index 5742ee4..0000000
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringShutdownDeferTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.spring.processor;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.processor.ShutdownDeferTest;
-
-import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
-
-/**
- * @version 
- */
-public class SpringShutdownDeferTest extends ShutdownDeferTest {
-
-    protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/ShutdownDeferTest.xml");
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/b62e88ff/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringShutdownNotDeferTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringShutdownNotDeferTest.java
b/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringShutdownNotDeferTest.java
deleted file mode 100644
index 8f3f027..0000000
--- a/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringShutdownNotDeferTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.spring.processor;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.processor.ShutdownNotDeferTest;
-
-import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
-
-/**
- * @version 
- */
-public class SpringShutdownNotDeferTest extends ShutdownNotDeferTest {
-
-    protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/ShutdownNotDeferTest.xml");
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/b62e88ff/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ShutdownDeferTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ShutdownDeferTest.xml
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ShutdownDeferTest.xml
deleted file mode 100644
index 6a91f6f..0000000
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ShutdownDeferTest.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
-    ">
-
-    <bean id="shutdownStrategy" class="org.apache.camel.impl.DefaultShutdownStrategy">
-        <!-- use 20 sec to give this unit test some time -->
-        <property name="timeout" value="20"/>
-    </bean>
-
-    <!-- START SNIPPET: e1 -->
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
-        <route startupOrder="1">
-            <from uri="seda:foo"/>
-            <to uri="file://target/deferred"/>
-        </route>
-
-        <!-- defer shutting down this route as the first route is depend upon it -->
-        <route startupOrder="2" shutdownRoute="Defer">
-            <from uri="file://target/deferred"/>
-            <to uri="mock:bar"/>
-        </route>
-    </camelContext>
-    <!-- END SNIPPET: e1 -->
-
-</beans>

http://git-wip-us.apache.org/repos/asf/camel/blob/b62e88ff/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ShutdownNotDeferTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ShutdownNotDeferTest.xml
b/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ShutdownNotDeferTest.xml
deleted file mode 100644
index 611ef90..0000000
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/ShutdownNotDeferTest.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xsi:schemaLocation="
-       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
-    ">
-
-    <bean id="shutdownStrategy" class="org.apache.camel.impl.DefaultShutdownStrategy">
-        <!-- use 20 sec to give this unit test some time -->
-        <property name="timeout" value="20"/>
-    </bean>
-
-    <camelContext xmlns="http://camel.apache.org/schema/spring">
-        <route startupOrder="1">
-            <from uri="seda:foo"/>
-            <delay><constant>1000</constant></delay>
-            <to uri="file://target/deferred"/>
-        </route>
-
-        <route startupOrder="2" shutdownRoute="Default">
-            <from uri="file://target/deferred"/>
-            <to uri="mock:bar"/>
-        </route>
-    </camelContext>
-
-</beans>


Mime
View raw message