You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cm...@apache.org on 2012/04/03 00:01:41 UTC

svn commit: r1308593 - in /camel/trunk/components/camel-jaxb/src: main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java test/java/org/apache/camel/example/DataFormatConcurrentTest.java

Author: cmueller
Date: Mon Apr  2 22:01:41 2012
New Revision: 1308593

URL: http://svn.apache.org/viewvc?rev=1308593&view=rev
Log:
CAMEL-3776: Add pooling support for JAXB data format

Modified:
    camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
    camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java

Modified: camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java?rev=1308593&r1=1308592&r2=1308593&view=diff
==============================================================================
--- camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java (original)
+++ camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java Mon Apr  2 22:01:41 2012
@@ -176,7 +176,9 @@ public class FallbackTypeConverter imple
             // must create a new instance of marshaller as its not thread safe
             Marshaller marshaller = context.createMarshaller();
             Writer buffer = new StringWriter();
-            marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, isPrettyPrint() ? Boolean.TRUE : Boolean.FALSE);
+            if (isPrettyPrint()) {
+                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+            }
             if (exchange != null && exchange.getProperty(Exchange.CHARSET_NAME, String.class) != null) {
                 marshaller.setProperty(Marshaller.JAXB_ENCODING, exchange.getProperty(Exchange.CHARSET_NAME, String.class));
             }

Modified: camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java?rev=1308593&r1=1308592&r2=1308593&view=diff
==============================================================================
--- camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java (original)
+++ camel/trunk/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java Mon Apr  2 22:01:41 2012
@@ -84,6 +84,60 @@ public class DataFormatConcurrentTest ex
     }
 
     @Test
+    public void testMarshallFallbackConcurrent() throws Exception {
+        int counter = 10000;
+        final PurchaseOrder order = new PurchaseOrder();
+        order.setName("Wine");
+        order.setAmount(123.45);
+        order.setPrice(2.22);
+        final CountDownLatch latch = new CountDownLatch(counter);
+        template.setDefaultEndpointUri("direct:marshalFallback");
+
+        ExecutorService pool = Executors.newFixedThreadPool(20);
+        //long start = System.currentTimeMillis();
+        for (int i = 0; i < counter; i++) {
+            pool.execute(new Runnable() {
+                public void run() {
+                    template.sendBody(order);
+                    latch.countDown();
+                }
+            });
+        }
+
+        // should finish on fast machines in less than 3 seconds
+        assertTrue(latch.await(10, TimeUnit.SECONDS));
+        //long end = System.currentTimeMillis();
+        //System.out.println("took " + (end - start) + "ms");
+    }
+
+    @Test
+    public void testMarshallConcurrent() throws Exception {
+        int counter = 10000;
+        final PurchaseOrder order = new PurchaseOrder();
+        order.setName("Wine");
+        order.setAmount(123.45);
+        order.setPrice(2.22);
+        final CountDownLatch latch = new CountDownLatch(counter);
+        template.setDefaultEndpointUri("direct:marshal");
+
+        ExecutorService pool = Executors.newFixedThreadPool(20);
+        //long start = System.currentTimeMillis();
+        for (int i = 0; i < counter; i++) {
+            pool.execute(new Runnable() {
+                public void run() {
+                    template.sendBody(order);
+                    latch.countDown();
+                }
+            });
+        }
+
+        // should finish on fast machines in less than 3 seconds
+        assertTrue(latch.await(10, TimeUnit.SECONDS));
+        //long end = System.currentTimeMillis();
+        //System.out.println("took " + (end - start) + "ms");
+    }
+
+    @Test
     public void testSendConcurrent() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(size);
@@ -128,9 +182,17 @@ public class DataFormatConcurrentTest ex
                         .unmarshal(jaxb)
                         .to("mock:result");
 
+                from("direct:marshal")
+                        .marshal(jaxb)
+                        .to("mock:result");
+
                 from("direct:unmarshalFallback")
                         .convertBodyTo(PurchaseOrder.class)
                         .to("mock:result");
+
+                from("direct:marshalFallback")
+                        .convertBodyTo(String.class)
+                        .to("mock:result");
             }
         };
     }