Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop the http client instances after firing CompleteEvent #261

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!groovy

def oss = ["linux"]
def jdks = ["jdk11", "jdk17"]
def jdks = ["jdk11", "jdk17", "jdk21"]

def builds = [:]
for (def os in oss) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.time.Duration;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.EventListener;
Expand Down Expand Up @@ -207,6 +206,14 @@ public CompletableFuture<Void> begin() {
.thenCompose(v -> CompletableFuture.allOf(responses));
})
.thenRun(this::fireCompleteEvent)
// HttpClient cannot be stopped from one of its own threads.
.whenCompleteAsync((r, x) -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("stopping http clients");
}
Collection<HttpClient> clients = getBeans(HttpClient.class);
clients.forEach(this::stopHttpClient);
}, executorService)
// Call halt() even if previous stages failed.
.whenCompleteAsync((r, x) -> halt(), executorService);
}
Expand Down Expand Up @@ -235,8 +242,6 @@ private CompletableFuture<Void> process() {
// The method returns a CompletableFuture, but the implementation
// uses Callbacks that need to reference the innermost CompletableFuture.

HttpClient[] clients = new HttpClient[config.getUsersPerThread()];

Callback.Completable anyFailure = new Callback.Completable();

// This is the callback to use for warmup iterations.
Expand Down Expand Up @@ -267,6 +272,7 @@ private CompletableFuture<Void> process() {
}

Collection<Connection.Listener> connectionListeners = getBeans(Connection.Listener.class);
HttpClient[] clients = new HttpClient[config.getUsersPerThread()];
for (int i = 0; i < clients.length; ++i) {
HttpClient client = clients[i] = newHttpClient(getConfig());
connectionListeners.forEach(client::addBean);
Expand Down Expand Up @@ -386,14 +392,7 @@ private CompletableFuture<Void> process() {
LOGGER.debug("sender thread failed: {}", threadName, x);
}
}
})
// HttpClient cannot be stopped from one of its own threads.
.whenCompleteAsync((r, x) -> {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("stopping http clients");
}
Arrays.stream(clients).forEach(this::stopHttpClient);
}, executorService);
});
}

protected HttpClient newHttpClient(Config config) {
Expand Down