abdullah alamoudi has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/2458

Change subject: [NO ISSUE][TEST] Close HTTP requests upon thread interruption
......................................................................

[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
---
M 
asterixdb/asterix-app/src/test/java/org/apache/asterix/test/common/TestExecutor.java
1 file changed, 20 insertions(+), 7 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/58/2458/1

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..d7a902a 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.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 @@
     }
 
     protected HttpResponse executeHttpRequest(HttpUriRequest method) throws 
Exception {
-        HttpClient client = 
HttpClients.custom().setRetryHandler(StandardHttpRequestRetryHandler.INSTANCE).build();
+        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, e.getMessage(), 
e);
+                e.printStackTrace();
+                throw e;
+            }
+        });
         try {
-            return client.execute(method, getHttpContext());
-        } catch (Exception e) {
-            GlobalConfig.ASTERIX_LOGGER.log(Level.ERROR, e.getMessage(), e);
-            e.printStackTrace();
+            return future.get();
+        } catch (InterruptedException e) {
+            client.close();
             throw e;
+        } finally {
+            executor.shutdownNow();
         }
     }
 
@@ -1007,7 +1020,7 @@
                         ctx.extension(), cUnit.getOutputDir().getCompare());
                 break;
             case "server": // (start <test server name> <port>
-                               // [<arg1>][<arg2>][<arg3>]...|stop 
(<port>|all))
+                           // [<arg1>][<arg2>][<arg3>]...|stop (<port>|all))
                 try {
                     lines = statement.trim().split("\n");
                     String[] command = lines[lines.length - 1].trim().split(" 
");
@@ -1055,7 +1068,7 @@
                 }
                 break;
             case "lib": // expected format <dataverse-name> <library-name>
-                            // <library-directory>
+                        // <library-directory>
                         // TODO: make this case work well with entity names 
containing spaces by
                         // looking for \"
                 lines = statement.split("\n");

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2458
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I39e43b8136df6b6a7965d033ca8892feda7394d4
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: abdullah alamoudi <bamou...@gmail.com>

Reply via email to