Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DFF0C200C60 for ; Mon, 24 Apr 2017 12:04:31 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id DE902160BA5; Mon, 24 Apr 2017 10:04:31 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 3186C160B99 for ; Mon, 24 Apr 2017 12:04:31 +0200 (CEST) Received: (qmail 14933 invoked by uid 500); 24 Apr 2017 10:04:30 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 14917 invoked by uid 99); 24 Apr 2017 10:04:29 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Apr 2017 10:04:29 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id E3BF63A0119 for ; Mon, 24 Apr 2017 10:04:28 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1792447 - in /httpcomponents/httpcore/branches/4.4.x: httpcore-nio/src/test/java/org/apache/http/nio/pool/ httpcore/src/main/java/org/apache/http/concurrent/ httpcore/src/test/java/org/apache/http/concurrent/ Date: Mon, 24 Apr 2017 10:04:28 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170424100428.E3BF63A0119@svn01-us-west.apache.org> archived-at: Mon, 24 Apr 2017 10:04:32 -0000 Author: olegk Date: Mon Apr 24 10:04:28 2017 New Revision: 1792447 URL: http://svn.apache.org/viewvc?rev=1792447&view=rev Log: HTTPCORE-456: BasicFuture fails to honor Future interface contract by not throwing CancellationException when cancelled Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java Modified: httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java?rev=1792447&r1=1792446&r2=1792447&view=diff ============================================================================== --- httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java (original) +++ httpcomponents/httpcore/branches/4.4.x/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java Mon Apr 24 10:04:28 2017 @@ -32,6 +32,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.UnknownHostException; import java.util.Collections; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -259,8 +260,11 @@ public class TestNIOConnPool { Assert.assertTrue(future.isDone()); Assert.assertTrue(future.isCancelled()); - final LocalPoolEntry entry = future.get(); - Assert.assertNull(entry); + try { + future.get(); + Assert.fail("CancellationException expected"); + } catch (CancellationException ignore) { + } totals = pool.getTotalStats(); Assert.assertEquals(0, totals.getAvailable()); @@ -1046,8 +1050,11 @@ public class TestNIOConnPool { pool.requestCompleted(sessionRequest1); Assert.assertTrue(future1.isDone()); - final LocalPoolEntry entry1 = future1.get(); - Assert.assertNull(entry1); + try { + future1.get(); + Assert.fail("CancellationException expected"); + } catch (CancellationException ignore) { + } final PoolStats totals = pool.getTotalStats(); Assert.assertEquals(1, totals.getAvailable()); Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java?rev=1792447&r1=1792446&r2=1792447&view=diff ============================================================================== --- httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java (original) +++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java Mon Apr 24 10:04:28 2017 @@ -28,6 +28,7 @@ package org.apache.http.concurrent; import org.apache.http.util.Args; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; @@ -69,6 +70,9 @@ public class BasicFuture implements F if (this.ex != null) { throw new ExecutionException(this.ex); } + if (cancelled) { + throw new CancellationException(); + } return this.result; } Modified: httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java?rev=1792447&r1=1792446&r2=1792447&view=diff ============================================================================== --- httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java (original) +++ httpcomponents/httpcore/branches/4.4.x/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java Mon Apr 24 10:04:28 2017 @@ -26,6 +26,7 @@ */ package org.apache.http.concurrent; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -118,7 +119,11 @@ public class TestBasicFuture { Assert.assertNull(callback.getException()); Assert.assertTrue(callback.isCancelled()); - Assert.assertNull(future.get()); + try { + future.get(); + Assert.fail("CancellationException expected"); + } catch (final CancellationException ex) { + } Assert.assertTrue(future.isDone()); Assert.assertTrue(future.isCancelled()); } @@ -175,7 +180,7 @@ public class TestBasicFuture { Assert.assertFalse(future.isCancelled()); } - @Test + @Test(expected = CancellationException.class) public void testAsyncCancelled() throws Exception { final BasicFuture future = new BasicFuture(null); @@ -193,9 +198,7 @@ public class TestBasicFuture { }; t.setDaemon(true); t.start(); - Assert.assertNull(future.get(60, TimeUnit.SECONDS)); - Assert.assertTrue(future.isDone()); - Assert.assertTrue(future.isCancelled()); + future.get(60, TimeUnit.SECONDS); } @Test(expected=TimeoutException.class)