You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2008/02/03 19:14:49 UTC
svn commit: r618048 - in /httpcomponents/httpclient/trunk: ./
module-client/src/test/java/org/apache/http/impl/conn/
module-client/src/test/java/org/apache/http/mockup/
Author: rolandw
Date: Sun Feb 3 10:14:48 2008
New Revision: 618048
URL: http://svn.apache.org/viewvc?rev=618048&view=rev
Log:
HTTPCLIENT-723: basic test coverage for ProxySelectorRoutePlanner
Added:
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java (with props)
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/ProxySelectorMockup.java (with props)
Modified:
httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestAllConnImpl.java
Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=618048&r1=618047&r2=618048&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Sun Feb 3 10:14:48 2008
@@ -1,6 +1,9 @@
Changes since 4.0 Alpha 2
-------------------
+* [HTTPCLIENT-723] route planner based on java.net.ProxySelector
+ Contributed by Roland Weber <rolandw at apache.org>
+
* [HTTPCLIENT-740] don't start connection GC thread in pool constructor
Contributed by Roland Weber <rolandw at apache.org>
Modified: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestAllConnImpl.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestAllConnImpl.java?rev=618048&r1=618047&r2=618048&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestAllConnImpl.java (original)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestAllConnImpl.java Sun Feb 3 10:14:48 2008
@@ -44,6 +44,7 @@
TestSuite suite = new TestSuite();
suite.addTest(TestLocalServer.suite()); // doesn't really belong here
+ suite.addTest(TestProxySelRoutePlanner.suite());
suite.addTest(TestTSCCMNoServer.suite());
suite.addTest(TestTSCCMWithServer.suite());
Added: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java?rev=618048&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java (added)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java Sun Feb 3 10:14:48 2008
@@ -0,0 +1,141 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.impl.conn;
+
+
+import java.net.Proxy;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.util.List;
+import java.util.ArrayList;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpVersion;
+import org.apache.http.message.BasicHttpRequest;
+
+import org.apache.http.conn.PlainSocketFactory;
+import org.apache.http.conn.Scheme;
+import org.apache.http.conn.SchemeRegistry;
+import org.apache.http.conn.SocketFactory;
+import org.apache.http.conn.routing.HttpRoute;
+import org.apache.http.conn.routing.HttpRoutePlanner;
+
+import org.apache.http.mockup.ProxySelectorMockup;
+
+
+
+/**
+ * Tests for <code>ProxySelectorRoutePlanner</code>.
+ */
+public class TestProxySelRoutePlanner extends TestCase {
+
+ public TestProxySelRoutePlanner(String testName) {
+ super(testName);
+ }
+
+ public static void main(String args[]) {
+ String[] testCaseName = { TestProxySelRoutePlanner.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ public static Test suite() {
+ return new TestSuite(TestProxySelRoutePlanner.class);
+ }
+
+
+ /**
+ * Instantiates a default scheme registry.
+ *
+ * @return the default scheme registry
+ */
+ public SchemeRegistry createSchemeRegistry() {
+
+ SchemeRegistry schreg = new SchemeRegistry();
+ SocketFactory sf = PlainSocketFactory.getSocketFactory();
+ schreg.register(new Scheme("http", sf, 80));
+
+ return schreg;
+ }
+
+
+ public void testDirect() throws Exception {
+
+ HttpRoutePlanner hrp =
+ new ProxySelectorRoutePlanner(createSchemeRegistry(),
+ new ProxySelectorMockup(null));
+
+ HttpHost target =
+ new HttpHost("www.test.invalid", 80, "http");
+ HttpRequest request =
+ new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+
+ HttpRoute route = hrp.determineRoute(target, request, null);
+
+ assertEquals("wrong target", target, route.getTargetHost());
+ assertEquals("not direct", 1, route.getHopCount());
+ }
+
+
+ public void testProxy() throws Exception {
+
+ InetAddress ia = InetAddress.getByAddress(new byte[] {
+ (byte)127, (byte)0, (byte)0, (byte)1
+ });
+ InetSocketAddress isa1 = new InetSocketAddress(ia, 11111);
+ InetSocketAddress isa2 = new InetSocketAddress(ia, 22222);
+
+ List<Proxy> proxies = new ArrayList<Proxy>(2);
+ proxies.add(new Proxy(Proxy.Type.HTTP, isa1));
+ proxies.add(new Proxy(Proxy.Type.HTTP, isa2));
+
+ HttpRoutePlanner hrp =
+ new ProxySelectorRoutePlanner(createSchemeRegistry(),
+ new ProxySelectorMockup(proxies));
+
+ HttpHost target =
+ new HttpHost("www.test.invalid", 80, "http");
+ HttpRequest request =
+ new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
+
+ HttpRoute route = hrp.determineRoute(target, request, null);
+
+ assertEquals("wrong target", target, route.getTargetHost());
+ assertEquals("not via proxy", 2, route.getHopCount());
+ assertEquals("wrong proxy", isa1.getPort(),
+ route.getProxyHost().getPort());
+ }
+
+} // class TestProxySelRoutePlanner
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/impl/conn/TestProxySelRoutePlanner.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/ProxySelectorMockup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/ProxySelectorMockup.java?rev=618048&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/ProxySelectorMockup.java (added)
+++ httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/ProxySelectorMockup.java Sun Feb 3 10:14:48 2008
@@ -0,0 +1,94 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ * ====================================================================
+ * 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.mockup;
+
+
+import java.net.URI;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.SocketAddress;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.io.IOException;
+
+
+
+/**
+ * Mockup of a {@link ProxySelector}.
+ * Always returns a fixed list.
+ */
+public class ProxySelectorMockup extends ProxySelector {
+
+ protected List<Proxy> proxyList;
+
+
+ /**
+ * Creates a mock proxy selector.
+ *
+ * @param proxies the list of proxies, or
+ * <code>null</code> for direct connections
+ */
+ public ProxySelectorMockup(List<Proxy> proxies) {
+
+ if (proxies == null) {
+ proxies = new ArrayList<Proxy>(1);
+ proxies.add(Proxy.NO_PROXY);
+ } else if (proxies.isEmpty()) {
+ throw new IllegalArgumentException
+ ("Proxy list must not be empty.");
+ }
+
+ proxyList = proxies;
+ }
+
+
+ /**
+ * Obtains the constructor argument.
+ *
+ * @param ignored not used by this mockup
+ *
+ * @return the list passed to the constructor,
+ * or a default list with "DIRECT" as the only element
+ */
+ public List<Proxy> select(URI ignored) {
+ return proxyList;
+ }
+
+
+ /**
+ * Does nothing.
+ */
+ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
+ // no body
+ }
+}
+
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/ProxySelectorMockup.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/ProxySelectorMockup.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpclient/trunk/module-client/src/test/java/org/apache/http/mockup/ProxySelectorMockup.java
------------------------------------------------------------------------------
svn:mime-type = text/plain