Skip to content

Commit c277cfd

Browse files
committed
Change wiremock to use dynamic ports.
1 parent b64ce91 commit c277cfd

File tree

1 file changed

+8
-23
lines changed

1 file changed

+8
-23
lines changed

util/src/test/java/io/kubernetes/client/CopyTest.java

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
1919
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
2020
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
21+
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
2122

2223
import com.github.tomakehurst.wiremock.junit.WireMockRule;
2324
import com.github.tomakehurst.wiremock.matching.AnythingPattern;
@@ -29,9 +30,7 @@
2930
import io.kubernetes.client.util.exception.CopyNotSupportedException;
3031
import java.io.File;
3132
import java.io.IOException;
32-
import java.io.InputStream;
3333
import java.nio.file.Paths;
34-
import java.util.concurrent.Semaphore;
3534
import org.junit.Before;
3635
import org.junit.Rule;
3736
import org.junit.Test;
@@ -45,13 +44,12 @@ public class CopyTest {
4544

4645
private ApiClient client;
4746

48-
private static final int PORT = 8089;
49-
@Rule public WireMockRule wireMockRule = new WireMockRule(PORT);
47+
@Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
5048
@Rule public TemporaryFolder folder = new TemporaryFolder();
5149

5250
@Before
5351
public void setup() throws IOException {
54-
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build();
52+
client = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
5553

5654
namespace = "default";
5755
podName = "apod";
@@ -71,24 +69,11 @@ public void testUrl() throws IOException, ApiException, InterruptedException {
7169
.withHeader("Content-Type", "application/json")
7270
.withBody("{}")));
7371

74-
final Semaphore s = new Semaphore(1);
75-
s.acquire();
76-
Thread t =
77-
new Thread(
78-
new Runnable() {
79-
@Override
80-
public void run() {
81-
try {
82-
InputStream is = copy.copyFileFromPod(pod, "container", "/some/path/to/file");
83-
} catch (IOException | ApiException e) {
84-
e.printStackTrace();
85-
} finally {
86-
s.release();
87-
}
88-
}
89-
});
90-
t.start();
91-
s.acquire();
72+
try {
73+
copy.copyFileFromPod(pod, "container", "/some/path/to/file");
74+
} catch (IOException | ApiException e) {
75+
e.printStackTrace();
76+
}
9277

9378
verify(
9479
getRequestedFor(

0 commit comments

Comments
 (0)