You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/04/20 08:09:26 UTC
svn commit: r766584 - in /camel/trunk/components:
camel-http/src/test/java/org/apache/camel/component/http/
camel-jetty/src/test/java/org/apache/camel/component/jetty/
Author: davsclaus
Date: Mon Apr 20 06:09:25 2009
New Revision: 766584
URL: http://svn.apache.org/viewvc?rev=766584&view=rev
Log:
Moved some of the http tests to jetty to avoid online lookup as it failis sporatic on some of the TC servers.
Added:
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java (with props)
camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java (with props)
Removed:
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpPollingGetTest.java
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/MultiThreadedHttpGetTest.java
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java?rev=766584&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java Mon Apr 20 06:09:25 2009
@@ -0,0 +1,75 @@
+/**
+ * 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.jetty;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class HttpPollingGetTest extends ContextTestSupport {
+
+ protected String expectedText = "<html";
+
+ public void testHttpPollingGet() throws Exception {
+ MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
+ mockEndpoint.expectedMinimumMessageCount(1);
+
+ mockEndpoint.assertIsSatisfied();
+ List<Exchange> list = mockEndpoint.getReceivedExchanges();
+ Exchange exchange = list.get(0);
+ assertNotNull("exchange", exchange);
+
+ Message in = exchange.getIn();
+ assertNotNull("in", in);
+
+ Map<String, Object> headers = in.getHeaders();
+
+ log.debug("Headers: " + headers);
+ assertTrue("Should be more than one header but was: " + headers, headers.size() > 0);
+
+ String body = in.getBody(String.class);
+
+ log.debug("Body: " + body);
+ assertNotNull("Should have a body!", body);
+ assertTrue("body should contain: " + expectedText, body.contains(expectedText));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("http://localhost:5431/myservice?delay=5000").to("mock:results");
+
+ from("jetty:http://localhost:5431/myservice").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getOut().setBody("<html>Bye World</html>");
+ }
+ });
+ }
+ };
+ }
+
+}
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java?rev=766584&view=auto
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java (added)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java Mon Apr 20 06:09:25 2009
@@ -0,0 +1,113 @@
+/**
+ * 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.jetty;
+
+import java.io.InputStream;
+import java.util.List;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpComponent;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class MultiThreadedHttpGetTest extends ContextTestSupport {
+
+ public void testHttpGetWithConversion() throws Exception {
+
+ // In this scenario response stream is converted to String
+ // so the stream has to be read to the end. When this happens
+ // the associated connection is released automatically.
+
+ String endpointName = "seda:withConversion";
+ sendMessagesTo(endpointName, 5);
+ }
+
+ public void testHttpGetWithoutConversion() throws Exception {
+
+ // This is needed as by default there are 2 parallel
+ // connections to some host and there is nothing that
+ // closes the http connection here.
+
+ context.getComponent("http", HttpComponent.class).getHttpConnectionManager().getParams()
+ .setDefaultMaxConnectionsPerHost(5);
+
+ String endpointName = "seda:withoutConversion";
+ sendMessagesTo(endpointName, 5);
+ }
+
+ public void testHttpGetWithExplicitStreamClose() throws Exception {
+
+ // We close connections explicitely at the very end of the flow
+ // (camel doesn't know when the stream is not needed any more)
+
+ MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
+
+ for (int i = 0; i < 5; i++) {
+ mockEndpoint.expectedMessageCount(1);
+ template.sendBody("seda:withoutConversion", null);
+ mockEndpoint.assertIsSatisfied();
+ Object response = mockEndpoint.getReceivedExchanges().get(0).getIn().getBody();
+ InputStream responseStream = assertIsInstanceOf(InputStream.class, response);
+ responseStream.close();
+ mockEndpoint.reset();
+ }
+ }
+
+ protected void sendMessagesTo(String endpointName, int count) throws InterruptedException {
+ MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
+ mockEndpoint.expectedMessageCount(count);
+
+ for (int i = 0; i < count; i++) {
+ template.sendBody(endpointName, null);
+ }
+
+ mockEndpoint.assertIsSatisfied();
+ List<Exchange> list = mockEndpoint.getReceivedExchanges();
+ for (Exchange exchange : list) {
+ String body = exchange.getIn().getBody(String.class);
+
+ log.debug("Body: " + body);
+ assertNotNull("Should have a body!", body);
+ assertTrue("body should contain: <html", body.contains("<html"));
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("seda:withConversion").thread(5).to("http://localhost:5430/search")
+ .convertBodyTo(String.class).to("mock:results");
+
+ from("seda:withoutConversion").thread(5).to("http://localhost:5430/search")
+ .to("mock:results");
+
+ from("jetty:http://localhost:5430/search").process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getOut().setBody("<html>Bye World</html>");
+ }
+ });
+ }
+ };
+ }
+
+}
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiThreadedHttpGetTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date