1818import static com .github .tomakehurst .wiremock .client .WireMock .getRequestedFor ;
1919import static com .github .tomakehurst .wiremock .client .WireMock .urlPathEqualTo ;
2020import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
21+ import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
2122
2223import com .github .tomakehurst .wiremock .junit .WireMockRule ;
2324import com .github .tomakehurst .wiremock .matching .AnythingPattern ;
2930import io .kubernetes .client .util .exception .CopyNotSupportedException ;
3031import java .io .File ;
3132import java .io .IOException ;
32- import java .io .InputStream ;
3333import java .nio .file .Paths ;
34- import java .util .concurrent .Semaphore ;
3534import org .junit .Before ;
3635import org .junit .Rule ;
3736import 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