hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [26/50] httpcomponents-core git commit: HTTPCORE-456: BasicFuture fails to honor Future interface contract by not throwing CancellationException when cancelled
Date Tue, 09 May 2017 20:01:52 GMT
HTTPCORE-456: BasicFuture fails to honor Future interface contract by not throwing CancellationException
when cancelled

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/branches/4.4.x@1792447
13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/bde8ec2e
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/bde8ec2e
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/bde8ec2e

Branch: refs/heads/4.4.x
Commit: bde8ec2e7b040193cfdea7434a16f23a9930b504
Parents: b9e3688
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Mon Apr 24 10:04:28 2017 +0000
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Mon Apr 24 10:04:28 2017 +0000

----------------------------------------------------------------------
 .../org/apache/http/nio/pool/TestNIOConnPool.java    | 15 +++++++++++----
 .../java/org/apache/http/concurrent/BasicFuture.java |  4 ++++
 .../org/apache/http/concurrent/TestBasicFuture.java  | 13 ++++++++-----
 3 files changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bde8ec2e/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java b/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
index 859d547..82abb22 100644
--- a/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
+++ b/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
@@ -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());

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bde8ec2e/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java
----------------------------------------------------------------------
diff --git a/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java b/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java
index 4e03cc4..b8b2ca1 100644
--- a/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java
+++ b/httpcore/src/main/java/org/apache/http/concurrent/BasicFuture.java
@@ -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<T> implements Future<T>, Cancellable
{
         if (this.ex != null) {
             throw new ExecutionException(this.ex);
         }
+        if (cancelled) {
+            throw new CancellationException();
+        }
         return this.result;
     }
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/bde8ec2e/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java
----------------------------------------------------------------------
diff --git a/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java b/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java
index 65dfd23..33fc46d 100644
--- a/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java
+++ b/httpcore/src/test/java/org/apache/http/concurrent/TestBasicFuture.java
@@ -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<Object> future = new BasicFuture<Object>(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)


Mime
View raw message