summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteffen Pingel2013-05-06 18:20:19 (EDT)
committer Gerrit Code Review @ Eclipse.org2013-05-08 03:27:31 (EDT)
commit72f83ab66f447100770672a3556e1efdd88a798e (patch)
tree906a4dd7ac850a7dbb890514fdd21b3bb4550c8d
parentf1bd276eef5cba42c3d2ec0037dde32096a0581d (diff)
downloadorg.eclipse.mylyn.commons-72f83ab66f447100770672a3556e1efdd88a798e.zip
org.eclipse.mylyn.commons-72f83ab66f447100770672a3556e1efdd88a798e.tar.gz
org.eclipse.mylyn.commons-72f83ab66f447100770672a3556e1efdd88a798e.tar.bz2
404761: CommonGetMethod3.releaseConnection(IProgressMonitor) does notrefs/changes/57/12557/5
close stream when progress monitor cancelled * test against mylyn.org instead of eclipse.org which is more reliable Change-Id: I2c7dff23a7dde3d2a3867732b2f370309d686134 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=404761
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java11
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java11
-rw-r--r--org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java24
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java2
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/CommonHttpMethod3Test.java70
-rw-r--r--org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java19
6 files changed, 102 insertions, 35 deletions
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java
index 091ea36..cd70602 100644
--- a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonGetMethod3.java
@@ -107,12 +107,11 @@ public class CommonGetMethod3 extends GetMethod implements CommonHttpMethod3 {
if (monitor != null && monitor.isCanceled()) {
// force a connection close on cancel to avoid blocking to do reading the remainder of the response
abort();
- } else {
- try {
- releaseConnection();
- } catch (NullPointerException e) {
- // ignore, see bug 255417
- }
+ }
+ try {
+ releaseConnection();
+ } catch (NullPointerException e) {
+ // ignore, see bug 255417
}
}
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java
index 385d6ab..e063df9 100644
--- a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonHeadMethod3.java
@@ -80,12 +80,11 @@ public class CommonHeadMethod3 extends HeadMethod implements CommonHttpMethod3 {
if (monitor != null && monitor.isCanceled()) {
// force a connection close on cancel to avoid blocking to do reading the remainder of the response
abort();
- } else {
- try {
- releaseConnection();
- } catch (NullPointerException e) {
- // ignore, see bug 255417
- }
+ }
+ try {
+ releaseConnection();
+ } catch (NullPointerException e) {
+ // ignore, see bug 255417
}
}
diff --git a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java
index 5add126..4b3257f 100644
--- a/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java
+++ b/org.eclipse.mylyn.commons.net/src/org/eclipse/mylyn/internal/commons/net/http/CommonPostMethod3.java
@@ -14,18 +14,17 @@
package org.eclipse.mylyn.internal.commons.net.http;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.mylyn.commons.net.WebUtil;
-import org.eclipse.mylyn.commons.net.http.CommonHttpMethod3;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.GZIPInputStream;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.methods.PostMethod;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.GZIPInputStream;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.commons.net.WebUtil;
+import org.eclipse.mylyn.commons.net.http.CommonHttpMethod3;
/**
* Based on {@code org.eclipse.ecf.provider.filetransfer.httpclient.HttpClientRetrieveFileTransfer}.
@@ -108,12 +107,11 @@ public class CommonPostMethod3 extends PostMethod implements CommonHttpMethod3 {
if (monitor != null && monitor.isCanceled()) {
// force a connection close on cancel to avoid blocking to do reading the remainder of the response
abort();
- } else {
- try {
- releaseConnection();
- } catch (NullPointerException e) {
- // ignore, see bug 255417
- }
+ }
+ try {
+ releaseConnection();
+ } catch (NullPointerException e) {
+ // ignore, see bug 255417
}
}
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java
index 353b7ac..7654ea9 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java
@@ -20,6 +20,7 @@ import org.eclipse.mylyn.commons.tests.core.CoreUtilTest;
import org.eclipse.mylyn.commons.tests.core.ExtensionPointReaderTest;
import org.eclipse.mylyn.commons.tests.core.Html2TextReaderTest;
import org.eclipse.mylyn.commons.tests.core.storage.CommonStoreTest;
+import org.eclipse.mylyn.commons.tests.net.CommonHttpMethod3Test;
import org.eclipse.mylyn.commons.tests.net.NetUtilTest;
import org.eclipse.mylyn.commons.tests.net.SslProtocolSocketFactoryTest;
import org.eclipse.mylyn.commons.tests.net.TimeoutInputStreamTest;
@@ -46,6 +47,7 @@ public class AllCommonsTests {
suite.addTestSuite(CommonListenerListTest.class);
suite.addTestSuite(CommonStoreTest.class);
suite.addTestSuite(Html2TextReaderTest.class);
+ suite.addTestSuite(CommonHttpMethod3Test.class);
return suite;
}
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/CommonHttpMethod3Test.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/CommonHttpMethod3Test.java
new file mode 100644
index 0000000..cbc93f6
--- /dev/null
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/CommonHttpMethod3Test.java
@@ -0,0 +1,70 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.commons.tests.net;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.eclipse.mylyn.commons.net.WebLocation;
+import org.eclipse.mylyn.commons.net.WebUtil;
+import org.eclipse.mylyn.commons.net.http.CommonHttpMethod3;
+import org.eclipse.mylyn.commons.tests.net.WebUtilTest.StubProgressMonitor;
+import org.eclipse.mylyn.internal.commons.net.CommonsNetPlugin;
+import org.eclipse.mylyn.internal.commons.net.http.CommonGetMethod3;
+import org.eclipse.mylyn.internal.commons.net.http.CommonPostMethod3;
+
+/**
+ * @author Steffen Pingel
+ */
+public class CommonHttpMethod3Test extends TestCase {
+
+ public void testGetOpenStreamAndCancel() throws Exception {
+ CommonGetMethod3 method = new CommonGetMethod3("/");
+ openStreamAndCancel(method);
+ }
+
+ public void testPostOpenStreamAndCancel() throws Exception {
+ CommonPostMethod3 method = new CommonPostMethod3("/");
+ openStreamAndCancel(method);
+ }
+
+ void openStreamAndCancel(CommonHttpMethod3 method) throws Exception {
+ StubProgressMonitor monitor = new StubProgressMonitor();
+ HttpClient client = new HttpClient();
+ String url = "http://mylyn.org/";
+ WebLocation location = new WebLocation(url);
+ HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(client, location, monitor);
+
+ InputStream in;
+ try {
+ WebUtil.execute(client, hostConfiguration, method, monitor);
+ in = method.getResponseBodyAsStream(monitor);
+ } finally {
+ monitor.setCanceled(true);
+ method.releaseConnection(monitor);
+ }
+ assertNotNull(in);
+ Thread.sleep(500); // wait for executor to release
+ assertEquals(0, ((ThreadPoolExecutor) CommonsNetPlugin.getExecutorService()).getActiveCount());
+ try {
+ in.read();
+ fail("Expected channel to be closed");
+ } catch (IOException e) {
+ // expected
+ }
+ }
+}
diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
index 063ae16..f539986 100644
--- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
+++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/net/WebUtilTest.java
@@ -54,7 +54,7 @@ import org.eclipse.mylyn.internal.commons.net.TimeoutInputStream;
*/
public class WebUtilTest extends TestCase {
- private class StubProgressMonitor implements IProgressMonitor {
+ static class StubProgressMonitor implements IProgressMonitor {
private volatile boolean canceled;
@@ -139,7 +139,7 @@ public class WebUtilTest extends TestCase {
public void testExecute() throws Exception {
StubProgressMonitor monitor = new StubProgressMonitor();
HttpClient client = new HttpClient();
- String url = "http://eclipse.org/";
+ String url = "http://mylyn.org/";
WebLocation location = new WebLocation(url);
HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(client, location, monitor);
@@ -184,7 +184,7 @@ public class WebUtilTest extends TestCase {
public void testExecuteAlreadyCancelled() throws Exception {
StubProgressMonitor monitor = new StubProgressMonitor();
HttpClient client = new HttpClient();
- String url = "http://eclipse.org/";
+ String url = "http://mylyn.org/";
WebLocation location = new WebLocation(url);
HostConfiguration hostConfiguration = WebUtil.createHostConfiguration(client, location, monitor);
@@ -217,13 +217,12 @@ public class WebUtilTest extends TestCase {
public void testCreateHostConfigurationProxy() throws Exception {
StubProgressMonitor monitor = new StubProgressMonitor();
HttpClient client = new HttpClient();
- WebUtil.createHostConfiguration(client, new WebLocation("http://eclipse.org/", null, null,
- new IProxyProvider() {
- public Proxy getProxyForHost(String host, String proxyType) {
- assertEquals(IProxyData.HTTP_PROXY_TYPE, proxyType);
- return null;
- }
- }), monitor);
+ WebUtil.createHostConfiguration(client, new WebLocation("http://mylyn.org/", null, null, new IProxyProvider() {
+ public Proxy getProxyForHost(String host, String proxyType) {
+ assertEquals(IProxyData.HTTP_PROXY_TYPE, proxyType);
+ return null;
+ }
+ }), monitor);
WebUtil.createHostConfiguration(client, new WebLocation("https://eclipse.org/", null, null,
new IProxyProvider() {
public Proxy getProxyForHost(String host, String proxyType) {