svn commit: r661222 - in /activemq/camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/builder/ main/scala/org/apache/camel/scala/dsl/ test/scala/org/apache/camel/scala/ test/scala/org/apache/camel/scala/dsl/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r661222 - in /activemq/camel/trunk/components/camel-scala/src: main/scala/org/apache/camel/scala/builder/ main/scala/org/apache/camel/scala/dsl/ test/scala/org/apache/camel/scala/ test/scala/org/apache/camel/scala/dsl/

gertv-2
Author: gertv
Date: Wed May 28 23:37:40 2008
New Revision: 661222

URL: http://svn.apache.org/viewvc?rev=661222&view=rev
Log:
CAMEL-463: Adding resequencer support

Added:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SResequencerType.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ResequencerTest.scala
Modified:
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala
    activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTestSupport.scala
    activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala?rev=661222&r1=661221&r2=661222&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/builder/RouteBuilder.scala Wed May 28 23:37:40 2008
@@ -63,5 +63,6 @@
   def throttle(frequency: Frequency) = stack.top.throttle(frequency)
   def loadbalance = stack.top.loadbalance
   def delay(delay: Period) = stack.top.delay(delay)
+  def resequence(expression: Exchange => Any) = stack.top.resequence(expression)
 
 }

Added: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SResequencerType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SResequencerType.scala?rev=661222&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SResequencerType.scala (added)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SResequencerType.scala Wed May 28 23:37:40 2008
@@ -0,0 +1,28 @@
+/**
+ * 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.scala.dsl;
+
+import org.apache.camel.model.ResequencerType
+import org.apache.camel.scala.builder.RouteBuilder
+
+class SResequencerType(val target: ResequencerType)(implicit val builder: RouteBuilder) extends ScalaDsl with Wrapper[ResequencerType] {
+  
+  val unwrap = target
+  
+  def batch = this
+
+}

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala?rev=661222&r1=661221&r2=661222&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/SThrottlerType.scala Wed May 28 23:37:40 2008
@@ -22,7 +22,7 @@
 /**
  * Scala enrichment for Camel's ThrottlerType
  */
-class STrottlerType(val target: ThrottlerType)(implicit val builder: RouteBuilder) extends ScalaDsl with Wrapper[ThrottlerType] {
+class SThrottlerType(val target: ThrottlerType)(implicit val builder: RouteBuilder) extends ScalaDsl with Wrapper[ThrottlerType] {
 
   val unwrap = target
   

Modified: activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala?rev=661222&r1=661221&r2=661222&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/main/scala/org/apache/camel/scala/dsl/ScalaDsl.scala Wed May 28 23:37:40 2008
@@ -26,6 +26,7 @@
   
   val target : ProcessorType[T] forSome {type T}
   implicit val builder: RouteBuilder
+  implicit def expressionBuilder(expression: Exchange => Any) = new ScalaExpression(expression)
   
   def -->(uris: String*) = to(uris:_*)
   def to(uris: String*) = {
@@ -48,10 +49,10 @@
   }
   
   def splitter(expression: Exchange => Any) =
-    new SSplitterType(target.splitter(new ScalaExpression(expression)))
+    new SSplitterType(target.splitter(expression))
     
   def recipients(expression: Exchange => Any) =
-    target.recipientList(new ScalaExpression(expression))
+    target.recipientList(expression)
 
   def apply(block: => Unit) = {
     builder.build(this, block)
@@ -70,10 +71,12 @@
     this
   }
   
-  def throttle(frequency: Frequency) = new STrottlerType(target.throttler(frequency.count).timePeriodMillis(frequency.period.milliseconds))
+  def throttle(frequency: Frequency) = new SThrottlerType(target.throttler(frequency.count).timePeriodMillis(frequency.period.milliseconds))
   
   def loadbalance = new SLoadBalanceType(target.loadBalance)
   
   def delay(period: Period) = new SDelayerType(target.delayer(period.milliseconds))
+  
+  def resequence(expression: Exchange => Any) = new SResequencerType(target.resequencer(expression))
 
 }

Modified: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTestSupport.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTestSupport.scala?rev=661222&r1=661221&r2=661222&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTestSupport.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/ScalaTestSupport.scala Wed May 28 23:37:40 2008
@@ -20,18 +20,23 @@
 import org.apache.camel.component.mock.MockEndpoint
 import builder.{RouteBuilder,RouteBuilderSupport}
 import org.apache.camel.scala.dsl._
-import _root_.scala.List
+import _root_.scala.collection.mutable.ArrayBuffer
 
 abstract class ScalaTestSupport extends ContextTestSupport with RouteBuilderSupport with Preamble {
   
   implicit def stringToUri(uri:String) = new RichTestUri(uri, this)
   implicit def mockWrapper(endpoint: MockEndpoint) = new RichMockEndpoint(endpoint)
+  val endpoints = new ArrayBuffer[MockEndpoint]()
 
   def assert(uri: String) = getMockEndpoint(uri).assertIsSatisfied
 
   protected[scala] def getTemplate() = template
 
-  protected[scala] def mock(uri: String) = getMockEndpoint(uri)
+  protected[scala] def mock(uri: String) = {
+    val mock = getMockEndpoint(uri)
+    endpoints += mock
+    mock
+  }
 
   def in(message: Any) : Exchange = {
     val exchange = createExchangeWithBody(message)
@@ -42,5 +47,14 @@
   val builder : RouteBuilder
   
   override protected def createRouteBuilder = builder.print
-
+  
+  override def setUp = {
+    super.setUp
+    endpoints.foreach(_.reset())
+  }
+  
+  def test(block : => Unit) = {
+    block
+    endpoints.foreach(_.assertIsSatisfied)
+  }
 }

Modified: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala?rev=661222&r1=661221&r2=661222&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala (original)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ContentBasedRouterTest.scala Wed May 28 23:37:40 2008
@@ -43,7 +43,7 @@
         when (_.in == "<hallo/>") {
           to ("mock:dutch")
           to ("mock:german")
-        }
+        }
         otherwise to ("mock:french")
       }
     }

Added: activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ResequencerTest.scala
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ResequencerTest.scala?rev=661222&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ResequencerTest.scala (added)
+++ activemq/camel/trunk/components/camel-scala/src/test/scala/org/apache/camel/scala/dsl/ResequencerTest.scala Wed May 28 23:37:40 2008
@@ -0,0 +1,81 @@
+/**
+ * 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.scala.dsl;
+
+import org.w3c.dom.Document
+import scala.builder.RouteBuilder
+
+/**
+ * Test case for message resequencer
+ */
+class ResequencerTest extends ScalaTestSupport {
+  
+  def testSimpleResequencer = {
+    "mock:a" expect { _.received("message 1", "message 2", "message 3", "message 4", "message 5") }
+    test {
+      "direct:a" ! ("message 5", "message 1", "message 3", "message 2", "message 4")
+    }
+  }
+  
+  def testBlockResequencer = {
+    "mock:b" expect (_.received("message 5", "message 1", "message 3", "message 2", "message 4"))
+    "mock:c" expect (_.received("message 1", "message 2", "message 3", "message 4", "message 5"))
+    test {
+      "direct:b" ! ("message 5", "message 1", "message 3", "message 2", "message 4")
+    }
+  }
+  
+  def testBatchResequencer = {
+    "mock:d" expect (_.received("message 5", "message 1", "message 3", "message 2"))
+    "mock:e" expect (_.count = 0)
+    test {
+      "direct:d" ! ("message 5", "message 1", "message 3", "message 2")
+    }
+    "mock:d" expect (_.count = 5)
+    "mock:e" expect (_.received("message 1", "message 2", "message 3", "message 4", "message 5"))
+    test {
+      "direct:d" ! "message 4"
+    }
+  }
+    
+  val builder =
+    new RouteBuilder {
+       //START SNIPPET: simple
+       "direct:a" resequence (_.in) to "mock:a"
+       //END SNIPPET: simple
+      
+       //START SNIPPET: block
+       "direct:b" ==> {
+         to ("mock:b")
+         resequence (_.in) {
+           to ("mock:c")
+         }
+       }
+       //END SNIPPET: block
+      
+       //START SNIPPET: batch
+       "direct:d" ==> {
+         to ("mock:d")
+         resequence (_.in) batch {
+           to ("mock:e")
+         }
+       }
+       //END SNIPPET: batch
+    }
+
+  
+}