Repository: asterixdb
Updated Branches:
  refs/heads/master 5630d8a15 -> 70daead8b


[NO ISSUE][TEST] Close HTTP requests upon thread interruption

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Ensure Http client in tests closes on interrupt.

Change-Id: I39e43b8136df6b6a7965d033ca8892feda7394d4
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2458
Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mb...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/70daead8
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/70daead8
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/70daead8

Branch: refs/heads/master
Commit: 70daead8b5614e6a6f6822944c3f9f695b245cf5
Parents: 5630d8a
Author: Abdullah Alamoudi <bamou...@gmail.com>
Authored: Tue Mar 6 16:15:51 2018 -0800
Committer: abdullah alamoudi <bamou...@gmail.com>
Committed: Tue Mar 6 20:06:11 2018 -0800

----------------------------------------------------------------------
 .../asterix/test/common/TestExecutor.java       | 21 ++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/70daead8/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
 
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
index 48603a5..8c0a3d4 100644
--- 
a/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
+++ 
b/asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
@@ -85,6 +85,7 @@ import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.client.methods.RequestBuilder;
 import org.apache.http.entity.ContentType;
 import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
 import org.apache.http.protocol.HttpContext;
@@ -477,13 +478,25 @@ public class TestExecutor {
     }
 
     protected HttpResponse executeHttpRequest(HttpUriRequest method) throws 
Exception {
-        HttpClient client = 
HttpClients.custom().setRetryHandler(StandardHttpRequestRetryHandler.INSTANCE).build();
+        // https://issues.apache.org/jira/browse/ASTERIXDB-2315
+        ExecutorService executor = Executors.newSingleThreadExecutor();
+        CloseableHttpClient client =
+                
HttpClients.custom().setRetryHandler(StandardHttpRequestRetryHandler.INSTANCE).build();
+        Future<HttpResponse> future = executor.submit(() -> {
+            try {
+                return client.execute(method, getHttpContext());
+            } catch (Exception e) {
+                GlobalConfig.ASTERIX_LOGGER.log(Level.ERROR, "Failure 
executing {}", method, e);
+                throw e;
+            }
+        });
         try {
-            return client.execute(method, getHttpContext());
+            return future.get();
         } catch (Exception e) {
-            GlobalConfig.ASTERIX_LOGGER.log(Level.ERROR, e.getMessage(), e);
-            e.printStackTrace();
+            client.close();
             throw e;
+        } finally {
+            executor.shutdownNow();
         }
     }
 

Reply via email to