Author: davsclaus Date: Sat Jan 26 16:47:36 2013 New Revision: 1438914 URL: http://svn.apache.org/viewvc?rev=1438914&view=rev Log: Added load balancing tests to urlrewrite.
Added: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceFailoverTest.java (with props) camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceRoundRobinTest.java (with props) camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceFailoverTest.java (with props) camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceRoundRobinTest.java - copied, changed from r1438865, camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteTest.java camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceFailoverTest.java (with props) camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceRoundRobinTest.java - copied, changed from r1438865, camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteTest.java Added: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceFailoverTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceFailoverTest.java?rev=1438914&view=auto ============================================================================== --- camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceFailoverTest.java (added) +++ camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceFailoverTest.java Sat Jan 26 16:47:36 2013 @@ -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.component.urlrewrite.http; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.urlrewrite.BaseUrlRewriteTest; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Test; + +/** + * + */ +public class HttpUrlRewriteLoadBalanceFailoverTest extends BaseUrlRewriteTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + + HttpUrlRewrite myRewrite = new HttpUrlRewrite(); + myRewrite.setConfigFile("example/urlrewrite2.xml"); + + jndi.bind("myRewrite", myRewrite); + + return jndi; + } + + @Test + public void testHttpUriRewrite() throws Exception { + // we should failover from app2 to app3 all the time + String out = template.requestBody("http://localhost:{{port}}/myapp/products/1234", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=1234", out); + + out = template.requestBody("http://localhost:{{port}}/myapp/products/5678", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=5678", out); + + out = template.requestBody("http://localhost:{{port}}/myapp/products/3333", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=3333", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // just disable error handler as we use failover load balancer + errorHandler(noErrorHandler()); + + // START SNIPPET: e1 + // we want to use the failover loadbalancer + // to have it to react we must set throwExceptionOnFailure=true, which is also the default value + // so we can omit configuring this option + from("jetty:http://localhost:{{port}}/myapp?matchOnUriPrefix=true") + .loadBalance().failover(Exception.class) + .to("http://localhost:{{port2}}/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=true&urlRewrite=#myRewrite") + .to("http://localhost:{{port2}}/myapp3?bridgeEndpoint=true&throwExceptionOnFailure=true&urlRewrite=#myRewrite"); + // END SNIPPET: e1 + + from("jetty:http://localhost:{{port2}}/myapp2?matchOnUriPrefix=true") + .log("I am going to fail") + .throwException(new IllegalArgumentException("Failed")); + + from("jetty:http://localhost:{{port2}}/myapp3?matchOnUriPrefix=true") + .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); + } + }; + } +} Propchange: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceFailoverTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceFailoverTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceRoundRobinTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceRoundRobinTest.java?rev=1438914&view=auto ============================================================================== --- camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceRoundRobinTest.java (added) +++ camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceRoundRobinTest.java Sat Jan 26 16:47:36 2013 @@ -0,0 +1,72 @@ +/** + * 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.component.urlrewrite.http; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.urlrewrite.BaseUrlRewriteTest; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Test; + +/** + * + */ +public class HttpUrlRewriteLoadBalanceRoundRobinTest extends BaseUrlRewriteTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + + HttpUrlRewrite myRewrite = new HttpUrlRewrite(); + myRewrite.setConfigFile("example/urlrewrite2.xml"); + + jndi.bind("myRewrite", myRewrite); + + return jndi; + } + + @Test + public void testHttpUriRewrite() throws Exception { + // we should round robin between app2 and app3 + String out = template.requestBody("http://localhost:{{port}}/myapp/products/1234", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp2/products/index.jsp?product_id=1234", out); + + out = template.requestBody("http://localhost:{{port}}/myapp/products/5678", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=5678", out); + + out = template.requestBody("http://localhost:{{port}}/myapp/products/3333", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp2/products/index.jsp?product_id=3333", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://localhost:{{port}}/myapp?matchOnUriPrefix=true") + .loadBalance().roundRobin() + .to("http://localhost:{{port2}}/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite") + .to("http://localhost:{{port2}}/myapp3?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite"); + + from("jetty:http://localhost:{{port2}}/myapp2?matchOnUriPrefix=true") + .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); + + from("jetty:http://localhost:{{port2}}/myapp3?matchOnUriPrefix=true") + .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); + } + }; + } +} Propchange: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceRoundRobinTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteLoadBalanceRoundRobinTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceFailoverTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceFailoverTest.java?rev=1438914&view=auto ============================================================================== --- camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceFailoverTest.java (added) +++ camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceFailoverTest.java Sat Jan 26 16:47:36 2013 @@ -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.component.urlrewrite.http4; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.urlrewrite.BaseUrlRewriteTest; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Test; + +/** + * + */ +public class Http4UrlRewriteLoadBalanceFailoverTest extends BaseUrlRewriteTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + + Http4UrlRewrite myRewrite = new Http4UrlRewrite(); + myRewrite.setConfigFile("example/urlrewrite2.xml"); + + jndi.bind("myRewrite", myRewrite); + + return jndi; + } + + @Test + public void testHttpUriRewrite() throws Exception { + // we should failover from app2 to app3 all the time + String out = template.requestBody("http4://localhost:{{port}}/myapp/products/1234", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=1234", out); + + out = template.requestBody("http4://localhost:{{port}}/myapp/products/5678", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=5678", out); + + out = template.requestBody("http4://localhost:{{port}}/myapp/products/3333", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=3333", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // just disable error handler as we use failover load balancer + errorHandler(noErrorHandler()); + + // START SNIPPET: e1 + // we want to use the failover loadbalancer + // to have it to react we must set throwExceptionOnFailure=true, which is also the default value + // so we can omit configuring this option + from("jetty:http://localhost:{{port}}/myapp?matchOnUriPrefix=true") + .loadBalance().failover(Exception.class) + .to("http4://localhost:{{port2}}/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=true&urlRewrite=#myRewrite") + .to("http4://localhost:{{port2}}/myapp3?bridgeEndpoint=true&throwExceptionOnFailure=true&urlRewrite=#myRewrite"); + // END SNIPPET: e1 + + from("jetty:http://localhost:{{port2}}/myapp2?matchOnUriPrefix=true") + .log("I am going to fail") + .throwException(new IllegalArgumentException("Failed")); + + from("jetty:http://localhost:{{port2}}/myapp3?matchOnUriPrefix=true") + .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); + } + }; + } +} Propchange: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceFailoverTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceFailoverTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceRoundRobinTest.java (from r1438865, camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceRoundRobinTest.java?p2=camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceRoundRobinTest.java&p1=camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteTest.java&r1=1438865&r2=1438914&rev=1438914&view=diff ============================================================================== --- camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteTest.java (original) +++ camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http4/Http4UrlRewriteLoadBalanceRoundRobinTest.java Sat Jan 26 16:47:36 2013 @@ -24,7 +24,7 @@ import org.junit.Test; /** * */ -public class Http4UrlRewriteTest extends BaseUrlRewriteTest { +public class Http4UrlRewriteLoadBalanceRoundRobinTest extends BaseUrlRewriteTest { @Override protected JndiRegistry createRegistry() throws Exception { @@ -40,8 +40,15 @@ public class Http4UrlRewriteTest extends @Test public void testHttpUriRewrite() throws Exception { + // we should round robin between app2 and app3 String out = template.requestBody("http4://localhost:{{port}}/myapp/products/1234", null, String.class); assertEquals("http://localhost:" + getPort2() + "/myapp2/products/index.jsp?product_id=1234", out); + + out = template.requestBody("http4://localhost:{{port}}/myapp/products/5678", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=5678", out); + + out = template.requestBody("http4://localhost:{{port}}/myapp/products/3333", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp2/products/index.jsp?product_id=3333", out); } @Override @@ -50,10 +57,15 @@ public class Http4UrlRewriteTest extends @Override public void configure() throws Exception { from("jetty:http://localhost:{{port}}/myapp?matchOnUriPrefix=true") - .to("http4://localhost:{{port2}}/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite"); + .loadBalance().roundRobin() + .to("http4://localhost:{{port2}}/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite") + .to("http4://localhost:{{port2}}/myapp3?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite"); from("jetty:http://localhost:{{port2}}/myapp2?matchOnUriPrefix=true") .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); + + from("jetty:http://localhost:{{port2}}/myapp3?matchOnUriPrefix=true") + .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); } }; } Added: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceFailoverTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceFailoverTest.java?rev=1438914&view=auto ============================================================================== --- camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceFailoverTest.java (added) +++ camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceFailoverTest.java Sat Jan 26 16:47:36 2013 @@ -0,0 +1,82 @@ +/** + * 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.component.urlrewrite.jetty; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.urlrewrite.BaseUrlRewriteTest; +import org.apache.camel.component.urlrewrite.http.HttpUrlRewrite; +import org.apache.camel.impl.JndiRegistry; +import org.junit.Test; + +/** + * + */ +public class JettyUrlRewriteLoadBalanceFailoverTest extends BaseUrlRewriteTest { + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + + HttpUrlRewrite myRewrite = new HttpUrlRewrite(); + myRewrite.setConfigFile("example/urlrewrite2.xml"); + + jndi.bind("myRewrite", myRewrite); + + return jndi; + } + + @Test + public void testHttpUriRewrite() throws Exception { + // we should failover from app2 to app3 all the time + String out = template.requestBody("http4://localhost:{{port}}/myapp/products/1234", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=1234", out); + + out = template.requestBody("http4://localhost:{{port}}/myapp/products/5678", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=5678", out); + + out = template.requestBody("http4://localhost:{{port}}/myapp/products/3333", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=3333", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // just disable error handler as we use failover load balancer + errorHandler(noErrorHandler()); + + // START SNIPPET: e1 + // we want to use the failover loadbalancer + // to have it to react we must set throwExceptionOnFailure=true, which is also the default value + // so we can omit configuring this option + from("jetty:http://localhost:{{port}}/myapp?matchOnUriPrefix=true") + .loadBalance().failover(Exception.class) + .to("jetty:http://localhost:{{port2}}/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=true&urlRewrite=#myRewrite") + .to("jetty:http://localhost:{{port2}}/myapp3?bridgeEndpoint=true&throwExceptionOnFailure=true&urlRewrite=#myRewrite"); + // END SNIPPET: e1 + + from("jetty:http://localhost:{{port2}}/myapp2?matchOnUriPrefix=true") + .log("I am going to fail") + .throwException(new IllegalArgumentException("Failed")); + + from("jetty:http://localhost:{{port2}}/myapp3?matchOnUriPrefix=true") + .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); + } + }; + } +} Propchange: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceFailoverTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceFailoverTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceRoundRobinTest.java (from r1438865, camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteTest.java) URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceRoundRobinTest.java?p2=camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceRoundRobinTest.java&p1=camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteTest.java&r1=1438865&r2=1438914&rev=1438914&view=diff ============================================================================== --- camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteTest.java (original) +++ camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/jetty/JettyUrlRewriteLoadBalanceRoundRobinTest.java Sat Jan 26 16:47:36 2013 @@ -25,16 +25,14 @@ import org.junit.Test; /** * */ -public class JettyUrlRewriteTest extends BaseUrlRewriteTest { +public class JettyUrlRewriteLoadBalanceRoundRobinTest extends BaseUrlRewriteTest { @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry jndi = super.createRegistry(); - // START SNIPPET: e1 HttpUrlRewrite myRewrite = new HttpUrlRewrite(); myRewrite.setConfigFile("example/urlrewrite2.xml"); - // END SNIPPET: e1 jndi.bind("myRewrite", myRewrite); @@ -43,8 +41,15 @@ public class JettyUrlRewriteTest extends @Test public void testJettyUriRewrite() throws Exception { + // we should round robin between app2 and app3 String out = template.requestBody("jetty:http://localhost:{{port}}/myapp/products/1234", null, String.class); assertEquals("http://localhost:" + getPort2() + "/myapp2/products/index.jsp?product_id=1234", out); + + out = template.requestBody("jetty:http://localhost:{{port}}/myapp/products/5678", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp3/products/index.jsp?product_id=5678", out); + + out = template.requestBody("jetty:http://localhost:{{port}}/myapp/products/3333", null, String.class); + assertEquals("http://localhost:" + getPort2() + "/myapp2/products/index.jsp?product_id=3333", out); } @Override @@ -52,13 +57,16 @@ public class JettyUrlRewriteTest extends return new RouteBuilder() { @Override public void configure() throws Exception { - // START SNIPPET: e2 from("jetty:http://localhost:{{port}}/myapp?matchOnUriPrefix=true") - .to("jetty:http://localhost:{{port2}}/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite"); - // END SNIPPET: e2 + .loadBalance().roundRobin() + .to("jetty:http://localhost:{{port2}}/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite") + .to("jetty:http://localhost:{{port2}}/myapp3?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite"); from("jetty:http://localhost:{{port2}}/myapp2?matchOnUriPrefix=true") .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); + + from("jetty:http://localhost:{{port2}}/myapp3?matchOnUriPrefix=true") + .transform().simple("${header.CamelHttpUrl}?${header.CamelHttpQuery}"); } }; }