You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2011/12/26 13:16:32 UTC
svn commit: r1224725 - in /camel/trunk/examples: camel-example-osgi-rmi/
camel-example-osgi-rmi/src/main/resources/
camel-example-osgi-rmi/src/main/resources/META-INF/spring/
camel-example-osgi-rmi/src/test/java/org/apache/camel/example/osgi/
camel-exa...
Author: davsclaus
Date: Mon Dec 26 12:16:31 2011
New Revision: 1224725
URL: http://svn.apache.org/viewvc?rev=1224725&view=rev
Log:
CAMEL-4814: Use dynamic port numbers for testing examples.
Added:
camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/log4j.properties
camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/myapp.properties
camel/trunk/examples/camel-example-osgi-rmi/src/test/resources/
Removed:
camel/trunk/examples/camel-example-route-throttling/src/test/
Modified:
camel/trunk/examples/camel-example-osgi-rmi/pom.xml
camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/META-INF/spring/camelContext.xml
camel/trunk/examples/camel-example-osgi-rmi/src/test/java/org/apache/camel/example/osgi/RmiTest.java
camel/trunk/examples/camel-example-pojo-messaging/src/test/java/org/apache/camel/example/pojo_messaging/CamelContextTest.java
camel/trunk/examples/camel-example-spring/src/main/resources/META-INF/spring/camel-context.xml
Modified: camel/trunk/examples/camel-example-osgi-rmi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-osgi-rmi/pom.xml?rev=1224725&r1=1224724&r2=1224725&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-osgi-rmi/pom.xml (original)
+++ camel/trunk/examples/camel-example-osgi-rmi/pom.xml Mon Dec 26 12:16:31 2011
@@ -60,9 +60,13 @@
<!-- used for mvn camel:run -->
<dependency>
<groupId>org.slf4j</groupId>
- <artifactId>slf4j-simple</artifactId>
+ <artifactId>slf4j-log4j12</artifactId>
<version>${slf4j-version}</version>
</dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
</dependencies>
Modified: camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/META-INF/spring/camelContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/META-INF/spring/camelContext.xml?rev=1224725&r1=1224724&r2=1224725&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/META-INF/spring/camelContext.xml (original)
+++ camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/META-INF/spring/camelContext.xml Mon Dec 26 12:16:31 2011
@@ -19,23 +19,31 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
+ xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+ <!-- spring property placeholder, ignore resource not found as the file resource is for unit testing -->
+ <context:property-placeholder location="classpath:myapp.properties,file:target/custom.properties"
+ ignore-resource-not-found="true"/>
+
<!-- bean implementing logic -->
<bean id="helloServiceBean" class="org.apache.camel.example.osgi.HelloServiceImpl"/>
- <!-- setup RMI server on port 37541 -->
+ <!-- setup RMI server -->
<bean id="rmiServer" class="java.rmi.registry.LocateRegistry" factory-method="createRegistry">
- <constructor-arg index="0" value="37541"/>
+ <constructor-arg index="0" value="${port}"/>
</bean>
<camelContext xmlns="http://camel.apache.org/schema/spring" depends-on="rmiServer">
+ <endpoint id="rmiService" uri="rmi://localhost:${port}/helloServiceBean?remoteInterfaces=org.apache.camel.example.osgi.HelloService"/>
+
<!-- expose a RMI service as a Camel route -->
<camel:route>
- <from uri="rmi://localhost:37541/helloServiceBean?remoteInterfaces=org.apache.camel.example.osgi.HelloService"/>
+ <from ref="rmiService"/>
<to uri="log:Incoming request on RMI"/>
<to uri="bean:helloServiceBean"/>
</camel:route>
Added: camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/log4j.properties
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/log4j.properties?rev=1224725&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/log4j.properties (added)
+++ camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/log4j.properties Mon Dec 26 12:16:31 2011
@@ -0,0 +1,29 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+# default properties to initialise log4j
+log4j.rootLogger=INFO, console
+
+# Camel logging
+#log4j.logger.org.apache.camel=DEBUG
+
+# Console appender
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.throwableRenderer=org.apache.log4j.EnhancedThrowableRenderer
+
Added: camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/myapp.properties
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/myapp.properties?rev=1224725&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/myapp.properties (added)
+++ camel/trunk/examples/camel-example-osgi-rmi/src/main/resources/myapp.properties Mon Dec 26 12:16:31 2011
@@ -0,0 +1,19 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+# properties for the application
+port=37541
\ No newline at end of file
Modified: camel/trunk/examples/camel-example-osgi-rmi/src/test/java/org/apache/camel/example/osgi/RmiTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-osgi-rmi/src/test/java/org/apache/camel/example/osgi/RmiTest.java?rev=1224725&r1=1224724&r2=1224725&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-osgi-rmi/src/test/java/org/apache/camel/example/osgi/RmiTest.java (original)
+++ camel/trunk/examples/camel-example-osgi-rmi/src/test/java/org/apache/camel/example/osgi/RmiTest.java Mon Dec 26 12:16:31 2011
@@ -16,10 +16,15 @@
*/
package org.apache.camel.example.osgi;
+import java.io.File;
+import java.io.FileOutputStream;
+
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.AvailablePortFinder;
import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -30,6 +35,21 @@ import org.springframework.context.suppo
* @version
*/
public class RmiTest extends CamelSpringTestSupport {
+
+ private static int PORT;
+
+ @BeforeClass
+ public static void setupFreePort() throws Exception {
+ // find a free port number from 9100 onwards, and write that in the custom.properties file
+ // which we will use for the unit tests, to avoid port number in use problems
+ PORT = AvailablePortFinder.getNextAvailable(9100);
+ String s = "port=" + PORT;
+
+ File custom = new File("target/custom.properties");
+ FileOutputStream fos = new FileOutputStream(custom);
+ fos.write(s.getBytes());
+ fos.close();
+ }
@Override
protected AbstractApplicationContext createApplicationContext() {
@@ -39,19 +59,17 @@ public class RmiTest extends CamelSpring
@Test
public void testRmi() throws Exception {
// Create a new camel context to send the request so we can test the service which is deployed into a container
- CamelContext camelContext = new DefaultCamelContext();
- ProducerTemplate myTemplate = camelContext.createProducerTemplate();
+ CamelContext myContext = new DefaultCamelContext();
+ ProducerTemplate myTemplate = myContext.createProducerTemplate();
myTemplate.start();
try {
- String out = myTemplate.requestBody("rmi://localhost:37541/helloServiceBean", "Camel", String.class);
+ System.out.println("Calling on port " + PORT);
+ String out = myTemplate.requestBody("rmi://localhost:" + PORT + "/helloServiceBean", "Camel", String.class);
assertEquals("Hello Camel", out);
} finally {
- if (myTemplate != null) {
- template.stop();
- }
- camelContext.stop();
+ myTemplate.stop();
+ myContext.stop();
}
-
}
}
Modified: camel/trunk/examples/camel-example-pojo-messaging/src/test/java/org/apache/camel/example/pojo_messaging/CamelContextTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-pojo-messaging/src/test/java/org/apache/camel/example/pojo_messaging/CamelContextTest.java?rev=1224725&r1=1224724&r2=1224725&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-pojo-messaging/src/test/java/org/apache/camel/example/pojo_messaging/CamelContextTest.java (original)
+++ camel/trunk/examples/camel-example-pojo-messaging/src/test/java/org/apache/camel/example/pojo_messaging/CamelContextTest.java Mon Dec 26 12:16:31 2011
@@ -16,11 +16,9 @@
*/
package org.apache.camel.example.pojo_messaging;
-
import java.io.File;
import org.apache.camel.test.junit4.CamelSpringTestSupport;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
@@ -31,34 +29,18 @@ public class CamelContextTest extends Ca
protected int getExpectedRouteCount() {
return 0;
}
-
- protected void deleteLockFile() {
- File file = new File("src/data/message1.xml.camelLock");
- file.delete();
- file = new File("src/data/message2.xml.camelLock");
- file.delete();
- file = new File("src/data/message3.xml.camelLock");
- file.delete();
- }
-
+
@Before
public void setUp() throws Exception {
deleteDirectory("target/messages");
- // delete the lock file
- deleteLockFile();
super.setUp();
}
-
- @After
- public void tearDown() throws Exception {
- super.tearDown();
- deleteLockFile();
- }
-
+
@Test
public void testCheckFiles() throws Exception {
- Thread.sleep(5000);
-
+ // wait a little for the files to be picked up and processed
+ Thread.sleep(3000);
+
File file = new File("target/messages/emea/hr_pickup");
file = file.getAbsoluteFile();
assertTrue("The pickup folder should exists", file.exists());
@@ -66,13 +48,11 @@ public class CamelContextTest extends Ca
file = new File("target/messages/amer/hr_pickup");
file = file.getAbsoluteFile();
assertTrue("The pickup folder should exists", file.exists());
- assertEquals("There should be 2 dumped files", 2, file.list().length);
-
+ assertEquals("There should be 2 dumped files", 2, file.list().length);
}
@Override
- protected AbstractXmlApplicationContext createApplicationContext() {
-
+ protected AbstractXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext(new String[] {"/META-INF/spring/camel-context.xml"});
}
Modified: camel/trunk/examples/camel-example-spring/src/main/resources/META-INF/spring/camel-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-spring/src/main/resources/META-INF/spring/camel-context.xml?rev=1224725&r1=1224724&r2=1224725&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-spring/src/main/resources/META-INF/spring/camel-context.xml (original)
+++ camel/trunk/examples/camel-example-spring/src/main/resources/META-INF/spring/camel-context.xml Mon Dec 26 12:16:31 2011
@@ -24,9 +24,6 @@
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<package>org.apache.camel.example.spring</package>
-
- <!-- Default JMX connector url: "service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi/camel" -->
- <jmxAgent id="agent" createConnector="true"/>
</camelContext>
<!-- lets configure the default ActiveMQ broker URL -->