18
18
import static com .github .tomakehurst .wiremock .client .WireMock .getRequestedFor ;
19
19
import static com .github .tomakehurst .wiremock .client .WireMock .urlPathEqualTo ;
20
20
import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
21
+ import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
21
22
22
23
import com .github .tomakehurst .wiremock .junit .WireMockRule ;
23
24
import com .github .tomakehurst .wiremock .matching .AnythingPattern ;
29
30
import io .kubernetes .client .util .exception .CopyNotSupportedException ;
30
31
import java .io .File ;
31
32
import java .io .IOException ;
32
- import java .io .InputStream ;
33
33
import java .nio .file .Paths ;
34
- import java .util .concurrent .Semaphore ;
35
34
import org .junit .Before ;
36
35
import org .junit .Rule ;
37
36
import org .junit .Test ;
@@ -45,13 +44,12 @@ public class CopyTest {
45
44
46
45
private ApiClient client ;
47
46
48
- private static final int PORT = 8089 ;
49
- @ Rule public WireMockRule wireMockRule = new WireMockRule (PORT );
47
+ @ Rule public WireMockRule wireMockRule = new WireMockRule (wireMockConfig ().dynamicPort ());
50
48
@ Rule public TemporaryFolder folder = new TemporaryFolder ();
51
49
52
50
@ Before
53
51
public void setup () throws IOException {
54
- client = new ClientBuilder ().setBasePath ("http://localhost:" + PORT ).build ();
52
+ client = new ClientBuilder ().setBasePath ("http://localhost:" + wireMockRule . port () ).build ();
55
53
56
54
namespace = "default" ;
57
55
podName = "apod" ;
@@ -71,24 +69,11 @@ public void testUrl() throws IOException, ApiException, InterruptedException {
71
69
.withHeader ("Content-Type" , "application/json" )
72
70
.withBody ("{}" )));
73
71
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
+ }
92
77
93
78
verify (
94
79
getRequestedFor (
0 commit comments