forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerHttpClientLeakDetector.java
More file actions
31 lines (25 loc) · 972 Bytes
/
Copy pathDockerHttpClientLeakDetector.java
File metadata and controls
31 lines (25 loc) · 972 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.github.dockerjava.cmd;
import org.junit.rules.ExternalResource;
public class DockerHttpClientLeakDetector extends ExternalResource {
@Override
protected void before() {
synchronized (TrackingDockerHttpClient.ACTIVE_RESPONSES) {
TrackingDockerHttpClient.ACTIVE_RESPONSES.clear();
}
}
@Override
protected void after() {
synchronized (TrackingDockerHttpClient.ACTIVE_RESPONSES) {
if (TrackingDockerHttpClient.ACTIVE_RESPONSES.isEmpty()) {
return;
}
System.out.println("Leaked responses:");
IllegalStateException exception = new IllegalStateException("Leaked responses!");
exception.setStackTrace(new StackTraceElement[0]);
TrackingDockerHttpClient.ACTIVE_RESPONSES.forEach(response -> {
exception.addSuppressed(response.allocatedAt);
});
throw exception;
}
}
}