Author: cmueller Date: Sat Mar 23 18:43:16 2013 New Revision: 1460204 URL: http://svn.apache.org/r1460204 Log: simplyfied the Avro tests
Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroConsumerTestSupport.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpConsumerTest.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpProducerTest.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpSpringProducerTest.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyConsumerTest.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyProducerTest.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringConsumerTest.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringProducerTest.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroProducerTestSupport.java camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroTestSupport.java camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-consumer.xml camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-producer.xml camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-consumer.xml camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-producer.xml Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroConsumerTestSupport.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroConsumerTestSupport.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroConsumerTestSupport.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroConsumerTestSupport.java Sat Mar 23 18:43:16 2013 @@ -28,6 +28,7 @@ import org.apache.camel.avro.generated.K import org.apache.camel.avro.generated.Value; import org.apache.camel.avro.impl.KeyValueProtocolImpl; +import org.junit.After; import org.junit.Assert; import org.junit.Test; @@ -40,14 +41,15 @@ public abstract class AvroConsumerTestSu protected abstract void initializeTranceiver() throws IOException; @Override + @After public void tearDown() throws Exception { super.tearDown(); + if (transceiver != null) { transceiver.close(); } } - @Test public void testInOnly() throws Exception { initializeTranceiver(); @@ -57,7 +59,6 @@ public abstract class AvroConsumerTestSu requestor.request("put", request); } - @Test public void testInOut() throws Exception { initializeTranceiver(); Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpConsumerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpConsumerTest.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpConsumerTest.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpConsumerTest.java Sat Mar 23 18:43:16 2013 @@ -22,7 +22,6 @@ import java.net.URL; import org.apache.avro.ipc.HttpTransceiver; import org.apache.avro.ipc.specific.SpecificRequestor; - import org.apache.camel.avro.generated.KeyValueProtocol; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.avro.processors.GetProcessor; @@ -30,8 +29,6 @@ import org.apache.camel.component.avro.p public class AvroHttpConsumerTest extends AvroConsumerTestSupport { - static int avroPort = setupFreePort("avroport"); - @Override protected void initializeTranceiver() throws IOException { transceiver = new HttpTransceiver(new URL("http://localhost:" + avroPort)); @@ -44,8 +41,8 @@ public class AvroHttpConsumerTest extend public void configure() throws Exception { //In Only from("avro:http:localhost:" + avroPort).choice() - .when().el("${in.headers." + AvroConstants.AVRO_MESSAGE_NAME + " == 'put'}").process(new PutProcessor(keyValue)) - .when().el("${in.headers." + AvroConstants.AVRO_MESSAGE_NAME + " == 'get'}").process(new GetProcessor(keyValue)); + .when().el("${in.headers." + AvroConstants.AVRO_MESSAGE_NAME + " == 'put'}").process(new PutProcessor(keyValue)) + .when().el("${in.headers." + AvroConstants.AVRO_MESSAGE_NAME + " == 'get'}").process(new GetProcessor(keyValue)); } }; } Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpProducerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpProducerTest.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpProducerTest.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpProducerTest.java Sat Mar 23 18:43:16 2013 @@ -21,14 +21,11 @@ import java.io.IOException; import org.apache.avro.ipc.HttpServer; import org.apache.avro.ipc.specific.SpecificResponder; - import org.apache.camel.avro.generated.KeyValueProtocol; import org.apache.camel.builder.RouteBuilder; public class AvroHttpProducerTest extends AvroProducerTestSupport { - static int avroPort = setupFreePort("avroport"); - @Override protected void initializeServer() throws IOException { if (server == null) { @@ -49,5 +46,4 @@ public class AvroHttpProducerTest extend } }; } - } Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpSpringProducerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpSpringProducerTest.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpSpringProducerTest.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroHttpSpringProducerTest.java Sat Mar 23 18:43:16 2013 @@ -19,10 +19,7 @@ package org.apache.camel.component.avro; import org.apache.camel.CamelContext; import org.apache.camel.spring.SpringCamelContext; - import org.junit.After; -import org.junit.Before; - import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -31,28 +28,18 @@ public class AvroHttpSpringProducerTest private AbstractApplicationContext applicationContext; @Override - @Before - public void setUp() throws Exception { - initializeServer(); - applicationContext = createApplicationContext(); - super.setUp(); - } - - @Override @After public void tearDown() throws Exception { super.tearDown(); + if (applicationContext != null) { applicationContext.destroy(); } } - public AbstractApplicationContext createApplicationContext() throws Exception { - return new ClassPathXmlApplicationContext("org/apache/camel/component/avro/avro-http-producer.xml"); - } - @Override protected CamelContext createCamelContext() throws Exception { + applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/avro/avro-http-producer.xml"); return SpringCamelContext.springCamelContext(applicationContext); } Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyConsumerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyConsumerTest.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyConsumerTest.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyConsumerTest.java Sat Mar 23 18:43:16 2013 @@ -22,7 +22,6 @@ import java.net.InetSocketAddress; import org.apache.avro.ipc.NettyTransceiver; import org.apache.avro.ipc.specific.SpecificRequestor; - import org.apache.camel.avro.generated.KeyValueProtocol; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.avro.processors.GetProcessor; @@ -30,8 +29,6 @@ import org.apache.camel.component.avro.p public class AvroNettyConsumerTest extends AvroConsumerTestSupport { - static int avroPort = setupFreePort("avroport"); - @Override protected void initializeTranceiver() throws IOException { transceiver = new NettyTransceiver(new InetSocketAddress("localhost", avroPort)); @@ -44,8 +41,8 @@ public class AvroNettyConsumerTest exten public void configure() throws Exception { //In Only from("avro:netty:localhost:" + avroPort).choice() - .when().el("${in.headers." + AvroConstants.AVRO_MESSAGE_NAME + " == 'put'}").process(new PutProcessor(keyValue)) - .when().el("${in.headers." + AvroConstants.AVRO_MESSAGE_NAME + " == 'get'}").process(new GetProcessor(keyValue)); + .when().el("${in.headers." + AvroConstants.AVRO_MESSAGE_NAME + " == 'put'}").process(new PutProcessor(keyValue)) + .when().el("${in.headers." + AvroConstants.AVRO_MESSAGE_NAME + " == 'get'}").process(new GetProcessor(keyValue)); } }; } Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyProducerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyProducerTest.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyProducerTest.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettyProducerTest.java Sat Mar 23 18:43:16 2013 @@ -26,8 +26,6 @@ import org.apache.camel.builder.RouteBui public class AvroNettyProducerTest extends AvroProducerTestSupport { - static int avroPort = setupFreePort("avroport"); - public RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringConsumerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringConsumerTest.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringConsumerTest.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringConsumerTest.java Sat Mar 23 18:43:16 2013 @@ -17,6 +17,7 @@ package org.apache.camel.component.avro; +import org.apache.camel.CamelContext; import org.apache.camel.avro.impl.KeyValueProtocolImpl; import org.apache.camel.spring.SpringCamelContext; @@ -33,23 +34,25 @@ public class AvroNettySpringConsumerTest @Override @Before public void setUp() throws Exception { - applicationContext = createApplicationContext(); - context = SpringCamelContext.springCamelContext(applicationContext); - keyValue = (KeyValueProtocolImpl) applicationContext.getBean("keyValue"); super.setUp(); + + keyValue = (KeyValueProtocolImpl) applicationContext.getBean("keyValue"); } @Override @After public void tearDown() throws Exception { super.tearDown(); + if (applicationContext != null) { applicationContext.destroy(); } } - public AbstractApplicationContext createApplicationContext() throws Exception { - return new ClassPathXmlApplicationContext("org/apache/camel/component/avro/avro-netty-consumer.xml"); + @Override + protected CamelContext createCamelContext() throws Exception { + applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/avro/avro-netty-consumer.xml"); + return SpringCamelContext.springCamelContext(applicationContext); } @Override Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringProducerTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringProducerTest.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringProducerTest.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroNettySpringProducerTest.java Sat Mar 23 18:43:16 2013 @@ -27,13 +27,6 @@ public class AvroNettySpringProducerTest private AbstractApplicationContext applicationContext; @Override - public void setUp() throws Exception { - initializeServer(); - applicationContext = createApplicationContext(); - super.setUp(); - } - - @Override public void tearDown() throws Exception { super.tearDown(); if (applicationContext != null) { @@ -41,12 +34,9 @@ public class AvroNettySpringProducerTest } } - public AbstractApplicationContext createApplicationContext() throws Exception { - return new ClassPathXmlApplicationContext("org/apache/camel/component/avro/avro-netty-producer.xml"); - } - @Override protected CamelContext createCamelContext() throws Exception { + applicationContext = new ClassPathXmlApplicationContext("org/apache/camel/component/avro/avro-netty-producer.xml"); return SpringCamelContext.springCamelContext(applicationContext); } Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroProducerTestSupport.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroProducerTestSupport.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroProducerTestSupport.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroProducerTestSupport.java Sat Mar 23 18:43:16 2013 @@ -21,14 +21,13 @@ import java.io.IOException; import org.apache.avro.Protocol; import org.apache.avro.ipc.Server; - import org.apache.camel.CamelContext; import org.apache.camel.avro.generated.Key; import org.apache.camel.avro.generated.KeyValueProtocol; import org.apache.camel.avro.generated.Value; import org.apache.camel.avro.impl.KeyValueProtocolImpl; import org.apache.camel.component.mock.MockEndpoint; - +import org.junit.After; import org.junit.Assert; import org.junit.Test; @@ -40,14 +39,17 @@ public abstract class AvroProducerTestSu protected abstract void initializeServer() throws IOException; @Override - public void setUp() throws Exception { + protected void doPreSetup() throws Exception { + super.doPreSetup(); + initializeServer(); - super.setUp(); } @Override + @After public void tearDown() throws Exception { super.tearDown(); + if (server != null) { server.close(); } @@ -62,7 +64,6 @@ public abstract class AvroProducerTestSu Assert.assertEquals(value, keyValue.getStore().get(key)); } - @Test public void testInOut() throws InterruptedException { keyValue.getStore().clear(); Modified: camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroTestSupport.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroTestSupport.java?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroTestSupport.java (original) +++ camel/trunk/components/camel-avro/src/test/java/org/apache/camel/component/avro/AvroTestSupport.java Sat Mar 23 18:43:16 2013 @@ -16,58 +16,18 @@ */ package org.apache.camel.component.avro; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; - -import java.util.Properties; - import org.apache.camel.test.AvailablePortFinder; import org.apache.camel.test.junit4.CamelTestSupport; public class AvroTestSupport extends CamelTestSupport { + int avroPort; - public static int setupFreePort(String name) { - int port = -1; - FileInputStream fis = null; - FileOutputStream fos = null; - try { - Properties properties = new Properties(); - File propertiesFile = new File("target/custom.properties"); - if (!propertiesFile.exists()) { - propertiesFile.createNewFile(); - } - fis = new FileInputStream(propertiesFile); - fos = new FileOutputStream(propertiesFile); - properties.load(fis); - if (properties.contains(name)) { - return Integer.parseInt((String) properties.get(name)); - } else { - // 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); - properties.put(name, String.valueOf(port)); - properties.store(fos, "avro"); - } - } catch (IOException e) { - //Ignore - } finally { - if (fis != null) { - try { - fis.close(); - } catch (Exception ex) { - } - } - if (fos != null) { - try { - fos.close(); - } catch (Exception ex) { - } - } - } - return port; - } + @Override + protected void doPreSetup() throws Exception { + avroPort = AvailablePortFinder.getNextAvailable(9100); + System.setProperty("avroport", String.valueOf(avroPort)); -} + super.doPreSetup(); + } +} \ No newline at end of file Modified: camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-consumer.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-consumer.xml?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-consumer.xml (original) +++ camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-consumer.xml Sat Mar 23 18:43:16 2013 @@ -23,7 +23,7 @@ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> - <propertyPlaceholder id="properties" location="file:target/custom.properties"/> + <propertyPlaceholder id="properties" ignoreMissingLocation="true" location="classpath:custom.properties"/> <route> <from uri="avro:http:localhost:{{avroport}}?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/> <choice> @@ -37,7 +37,6 @@ </when> </choice> </route> - </camelContext> <bean id="keyValue" class="org.apache.camel.avro.impl.KeyValueProtocolImpl"/> Modified: camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-producer.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-producer.xml?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-producer.xml (original) +++ camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-http-producer.xml Sat Mar 23 18:43:16 2013 @@ -23,7 +23,7 @@ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> - <propertyPlaceholder id="properties" location="file:target/custom.properties"/> + <propertyPlaceholder id="properties" ignoreMissingLocation="true" location="classpath:custom.properties"/> <route> <from uri="direct:in"/> <to uri="avro:http:localhost:{{avroport}}?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/> Modified: camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-consumer.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-consumer.xml?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-consumer.xml (original) +++ camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-consumer.xml Sat Mar 23 18:43:16 2013 @@ -23,7 +23,7 @@ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> - <propertyPlaceholder id="properties" location="file:target/custom.properties"/> + <propertyPlaceholder id="properties" ignoreMissingLocation="true" location="classpath:custom.properties"/> <route> <from uri="avro:netty:localhost:{{avroport}}?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/> <choice> Modified: camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-producer.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-producer.xml?rev=1460204&r1=1460203&r2=1460204&view=diff ============================================================================== --- camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-producer.xml (original) +++ camel/trunk/components/camel-avro/src/test/resources/org/apache/camel/component/avro/avro-netty-producer.xml Sat Mar 23 18:43:16 2013 @@ -23,7 +23,7 @@ <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring"> - <propertyPlaceholder id="properties" location="file:target/custom.properties"/> + <propertyPlaceholder id="properties" ignoreMissingLocation="true" location="classpath:custom.properties"/> <route> <from uri="direct:in"/> <to uri="avro:netty:localhost:{{avroport}}?protocolClassName=org.apache.camel.avro.generated.KeyValueProtocol"/>