From f14c2ff890c451f324d2c3ed1310d7b2a600190b Mon Sep 17 00:00:00 2001
From: Kevin Walter <kevin.walter.private@gmail.com>
Date: Mon, 14 Sep 2020 14:12:22 +0200
Subject: [PATCH] cleanup http client after each test

---
 .../netapi/calls/CallAsyncEventsTest.java     | 20 +++++++++++++++++--
 .../suse/salt/netapi/calls/LocalCallTest.java | 15 ++++++++++++--
 .../salt/netapi/calls/modules/CmdTest.java    | 15 ++++++++++++--
 .../salt/netapi/calls/modules/FileTest.java   | 15 ++++++++++++--
 .../salt/netapi/calls/modules/GitTest.java    | 15 ++++++++++++--
 .../salt/netapi/calls/modules/GrainsTest.java | 15 ++++++++++++--
 .../salt/netapi/calls/modules/LocateTest.java | 15 ++++++++++++--
 .../salt/netapi/calls/modules/MatchTest.java  | 15 ++++++++++++--
 .../salt/netapi/calls/modules/MinionTest.java | 15 ++++++++++++--
 .../netapi/calls/modules/SaltUtilTest.java    | 15 ++++++++++++--
 .../netapi/calls/modules/ScheduleTest.java    | 15 ++++++++++++--
 .../salt/netapi/calls/modules/SmbiosTest.java | 15 ++++++++++++--
 .../salt/netapi/calls/modules/StatusTest.java | 15 ++++++++++++--
 .../netapi/calls/modules/TimezoneTest.java    | 15 ++++++++++++--
 .../salt/netapi/calls/runner/EventTest.java   | 15 ++++++++++++--
 .../salt/netapi/calls/runner/JobsTest.java    | 15 ++++++++++++--
 .../suse/salt/netapi/calls/wheel/KeyTest.java | 15 ++++++++++++--
 .../netapi/client/SaltClientDockerTest.java   | 13 +++++++++++-
 .../salt/netapi/client/SaltClientTest.java    | 14 +++++++++++--
 19 files changed, 250 insertions(+), 37 deletions(-)

diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/CallAsyncEventsTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/CallAsyncEventsTest.java
index fbbffcbf8..dcabacec1 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/CallAsyncEventsTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/CallAsyncEventsTest.java
@@ -25,10 +25,13 @@ import com.suse.salt.netapi.exception.SaltException;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.time.Duration;
@@ -58,12 +61,25 @@ public class CallAsyncEventsTest extends AbstractEventsTest {
 
     private SaltClient client;
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Override
     @Before
     public void init() throws URISyntaxException, DeploymentException {
         super.init();
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() {
+        super.cleanup();
+        try {
+            closeableHttpAsyncClient.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
     }
 
     @Override
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/LocalCallTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/LocalCallTest.java
index 6e0d7575f..3b8cf481c 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/LocalCallTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/LocalCallTest.java
@@ -29,10 +29,13 @@ import com.suse.salt.netapi.datatypes.target.SSHTarget;
 import com.suse.salt.netapi.datatypes.target.Target;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Optional;
@@ -66,10 +69,18 @@ public class LocalCallTest {
 
     private SaltClient client;
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/CmdTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/CmdTest.java
index b75493ad2..6f8b5a595 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/CmdTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/CmdTest.java
@@ -18,10 +18,13 @@ import com.suse.salt.netapi.results.CmdResult;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Map;
@@ -69,10 +72,18 @@ public class CmdTest {
     @Rule
     public WireMockRule wireMockRule = new WireMockRule(MOCK_HTTP_PORT);
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/FileTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/FileTest.java
index 1dff247bb..74b16e8d5 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/FileTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/FileTest.java
@@ -23,10 +23,13 @@ import com.suse.salt.netapi.errors.JsonParsingError;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.List;
@@ -114,10 +117,18 @@ public class FileTest {
     @Rule
     public WireMockRule wireMockRule = new WireMockRule(MOCK_HTTP_PORT);
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/GitTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/GitTest.java
index 8b219df45..b08425892 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/GitTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/GitTest.java
@@ -19,10 +19,13 @@ import com.suse.salt.netapi.results.GitResult;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Map;
@@ -58,10 +61,18 @@ public class GitTest {
     @Rule
     public WireMockRule wireMockRule = new WireMockRule(MOCK_HTTP_PORT);
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/GrainsTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/GrainsTest.java
index 8ad9ffce0..c4776ec57 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/GrainsTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/GrainsTest.java
@@ -19,10 +19,13 @@ import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
 
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.HashMap;
@@ -70,10 +73,18 @@ public class GrainsTest {
 
     static final AuthMethod AUTH = new AuthMethod(new Token());
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     private static void mockOkResponseWith(String json) {
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/LocateTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/LocateTest.java
index db5360977..53c64f743 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/LocateTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/LocateTest.java
@@ -20,10 +20,13 @@ import com.suse.salt.netapi.errors.JsonParsingError;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.List;
@@ -72,10 +75,18 @@ public class LocateTest {
 
     static final AuthMethod AUTH = new AuthMethod(new Token());
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/MatchTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/MatchTest.java
index 4c4fcd4dd..669607fa7 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/MatchTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/MatchTest.java
@@ -8,11 +8,14 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Map;
 import java.util.Optional;
 
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -45,10 +48,18 @@ public class MatchTest {
 
     private static final AuthMethod AUTH = new AuthMethod(new Token());
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     private static void mockOkResponseWith(String json) {
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/MinionTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/MinionTest.java
index 875e89735..cf3c237fc 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/MinionTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/MinionTest.java
@@ -18,10 +18,13 @@ import com.suse.salt.netapi.datatypes.target.MinionList;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Map;
@@ -50,10 +53,18 @@ public class MinionTest {
 
     static final AuthMethod AUTH = new AuthMethod(new Token());
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/SaltUtilTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/SaltUtilTest.java
index 2581d25a3..64aeaa783 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/SaltUtilTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/SaltUtilTest.java
@@ -16,10 +16,13 @@ import com.suse.salt.netapi.datatypes.target.MinionList;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.List;
@@ -55,10 +58,18 @@ public class SaltUtilTest {
 
     private SaltClient client;
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/ScheduleTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/ScheduleTest.java
index ac3eedf91..c15ae9b00 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/ScheduleTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/ScheduleTest.java
@@ -19,10 +19,13 @@ import com.suse.salt.netapi.datatypes.target.MinionList;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.time.LocalDateTime;
@@ -48,10 +51,18 @@ public class ScheduleTest {
     static final AuthMethod TOKEN_AUTH = new AuthMethod(new Token());
     static final AuthMethod AUTH = new AuthMethod(new PasswordAuth("", "", AuthModule.AUTO));
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/SmbiosTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/SmbiosTest.java
index 5f5d4a29c..29c3e1040 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/SmbiosTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/SmbiosTest.java
@@ -17,10 +17,13 @@ import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
 import com.suse.salt.netapi.utils.Xor;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.List;
@@ -52,10 +55,18 @@ public class SmbiosTest {
 
     private SaltClient client;
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/StatusTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/StatusTest.java
index eb68b9b9a..a72689012 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/StatusTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/StatusTest.java
@@ -17,10 +17,13 @@ import com.suse.salt.netapi.datatypes.target.MinionList;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Map;
@@ -54,10 +57,18 @@ public class StatusTest {
 
     static final AuthMethod AUTH = new AuthMethod(new Token());
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/TimezoneTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/TimezoneTest.java
index ca89f627a..b3431f75e 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/TimezoneTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/modules/TimezoneTest.java
@@ -12,10 +12,13 @@ import com.suse.salt.netapi.errors.JsonParsingError;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Map;
@@ -48,10 +51,18 @@ public class TimezoneTest {
 
     static final AuthMethod AUTH = new AuthMethod(new Token());
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/runner/EventTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/runner/EventTest.java
index 220a07140..9478b7d01 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/runner/EventTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/runner/EventTest.java
@@ -19,10 +19,13 @@ import com.suse.salt.netapi.datatypes.AuthMethod;
 import com.suse.salt.netapi.datatypes.Token;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.HashMap;
@@ -48,10 +51,18 @@ public class EventTest {
 
     private SaltClient client;
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/runner/JobsTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/runner/JobsTest.java
index 9a93d7c28..38bfcbfc5 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/runner/JobsTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/runner/JobsTest.java
@@ -17,11 +17,14 @@ import com.suse.salt.netapi.datatypes.Token;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
 import org.hamcrest.CoreMatchers;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Optional;
@@ -48,10 +51,18 @@ public class JobsTest {
 
     private SaltClient client;
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/wheel/KeyTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/wheel/KeyTest.java
index 30e168ad0..9c827dffe 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/wheel/KeyTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/calls/wheel/KeyTest.java
@@ -21,10 +21,13 @@ import com.suse.salt.netapi.datatypes.Token;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.ClientUtils;
 import com.suse.salt.netapi.utils.TestUtils;
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.util.Optional;
@@ -49,10 +52,18 @@ public class KeyTest {
 
     private SaltClient client;
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/client/SaltClientDockerTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/client/SaltClientDockerTest.java
index 1fb64c340..471c8fb97 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/client/SaltClientDockerTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/client/SaltClientDockerTest.java
@@ -18,11 +18,14 @@ import com.suse.salt.netapi.exception.SaltUserUnauthorizedException;
 import com.suse.salt.netapi.results.Result;
 import com.suse.salt.netapi.utils.TestUtils;
 
+import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
+import java.io.IOException;
 import java.net.URI;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
@@ -53,10 +56,18 @@ public class SaltClientDockerTest {
     @Rule
     public ExpectedException exception = ExpectedException.none();
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
         URI uri = URI.create(SALT_NETAPI_SERVER + ":" + SALT_NETAPI_PORT);
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
diff --git a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/client/SaltClientTest.java b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/client/SaltClientTest.java
index 4ab3f007e..c3f3b889d 100644
--- a/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/client/SaltClientTest.java
+++ b/src/salt-netapi-client-0.17.0/src/test/java/com/suse/salt/netapi/client/SaltClientTest.java
@@ -33,11 +33,13 @@ import org.apache.http.client.config.RequestConfig;
 import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
 import org.apache.http.impl.nio.client.HttpAsyncClientBuilder;
 import org.apache.http.impl.nio.client.HttpAsyncClients;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
+import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.SocketTimeoutException;
 import java.net.URI;
@@ -80,10 +82,18 @@ public class SaltClientTest {
     @Rule
     public ExpectedException exception = ExpectedException.none();
 
+    private CloseableHttpAsyncClient closeableHttpAsyncClient;
+
     @Before
     public void init() {
-        URI uri = URI.create("http://localhost:" + Integer.toString(MOCK_HTTP_PORT));
-        client = new SaltClient(uri, new HttpAsyncClientImpl(TestUtils.defaultClient()));
+        URI uri = URI.create("http://localhost:" + MOCK_HTTP_PORT);
+        closeableHttpAsyncClient = TestUtils.defaultClient();
+        client = new SaltClient(uri, new HttpAsyncClientImpl(closeableHttpAsyncClient));
+    }
+
+    @After
+    public void cleanup() throws IOException {
+        closeableHttpAsyncClient.close();
     }
 
     @Test
-- 
2.28.0

