camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1324999 - in /camel/branches/camel-2.8.x/components/camel-jaxb/src: main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java test/java/org/apache/camel/example/DataFormatConcurrentTest.java
Date Wed, 11 Apr 2012 20:55:59 GMT
Author: cmueller
Date: Wed Apr 11 20:55:58 2012
New Revision: 1324999

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

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

Modified: camel/branches/camel-2.8.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java?rev=1324999&r1=1324998&r2=1324999&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
Wed Apr 11 20:55:58 2012
@@ -177,7 +177,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/branches/camel-2.8.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java?rev=1324999&r1=1324998&r2=1324999&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java
Wed Apr 11 20:55:58 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");
             }
         };
     }



Mime
View raw message