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 2010/03/21 13:53:16 UTC

svn commit: r925761 - in /camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http: HttpNoConnectionRedeliveryTest.java HttpNoConnectionTest.java

Author: davsclaus
Date: Sun Mar 21 12:53:16 2010
New Revision: 925761

URL: http://svn.apache.org/viewvc?rev=925761&view=rev
Log:
Added no connection tests based on user forum problem.

Added:
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionRedeliveryTest.java   (with props)
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionTest.java   (with props)

Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionRedeliveryTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionRedeliveryTest.java?rev=925761&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionRedeliveryTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionRedeliveryTest.java Sun Mar 21 12:53:16 2010
@@ -0,0 +1,77 @@
+/**
+ * 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.http;
+
+import java.net.ConnectException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.handler.BasicValidationHandler;
+import org.apache.http.conn.HttpHostConnectException;
+import org.apache.http.localserver.LocalTestServer;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpNoConnectionRedeliveryTest extends BaseHttpTest {
+
+    @Test
+    public void httpConnectionOk() throws Exception {
+        Exchange exchange = template.request("direct:start", null);
+
+        assertExchange(exchange);
+    }
+
+    @Test
+    public void httpConnectionNotOk() throws Exception {
+        // stop server so there are no connection
+        localServer.stop();
+
+        Exchange exchange = template.request("direct:start", null);
+        assertTrue(exchange.isFailed());
+
+        HttpHostConnectException cause = assertIsInstanceOf(HttpHostConnectException.class, exchange.getException());
+        assertIsInstanceOf(ConnectException.class, cause.getCause());
+
+        assertEquals(true, exchange.getIn().getHeader(Exchange.REDELIVERED));
+        assertEquals(4, exchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER));
+    }
+
+    @Override
+    protected void registerHandler(LocalTestServer server) {
+        server.register("/search", new BasicValidationHandler("GET", null, null, getExpectedContent()));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .onException(ConnectException.class)
+                        .maximumRedeliveries(4)
+                        .backOffMultiplier(2)
+                        .redeliverDelay(100)
+                        .maximumRedeliveryDelay(5000)
+                        .useExponentialBackOff()
+                    .end()
+                    .to("http://" + getHostName() + ":" + getPort() + "/search");
+            }
+        };
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionRedeliveryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionRedeliveryTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionTest.java?rev=925761&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionTest.java (added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionTest.java Sun Mar 21 12:53:16 2010
@@ -0,0 +1,64 @@
+/**
+ * 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.http;
+
+import java.net.ConnectException;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.http.handler.BasicValidationHandler;
+import org.apache.http.conn.HttpHostConnectException;
+import org.apache.http.localserver.LocalTestServer;
+import org.junit.Test;
+
+/**
+ * @version $Revision$
+ */
+public class HttpNoConnectionTest extends BaseHttpTest {
+
+    @Test
+    public void httpConnectionOk() throws Exception {
+        Exchange exchange = template.request("http://" + getHostName() + ":" + getPort() + "/search", new Processor() {
+            public void process(Exchange exchange) throws Exception {
+            }
+        });
+
+        assertExchange(exchange);
+    }
+
+    @Test
+    public void httpConnectionNotOk() throws Exception {
+        String url = "http://" + getHostName() + ":" + getPort() + "/search";
+        // stop server so there are no connection
+        localServer.stop();
+
+        try {
+            template.request(url, null);
+            fail("Should have thrown an exception");
+        } catch (RuntimeCamelException e) {
+            HttpHostConnectException cause = assertIsInstanceOf(HttpHostConnectException.class, e.getCause());
+            assertIsInstanceOf(ConnectException.class, cause.getCause());
+        }
+    }
+
+    @Override
+    protected void registerHandler(LocalTestServer server) {
+        server.register("/search", new BasicValidationHandler("GET", null, null, getExpectedContent()));
+    }
+
+}

Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpNoConnectionTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date