4
我使用WireMock來測試一個Spring Boot web應用程序,它本身使用Jetty,但在不同的端口上。WireMock每個測試案例設置掛在第二個測試
我所看到的是,如果我使用的基本規則配置:
@Rule
public WireMockRule wireMockRule = new WireMockRule(8006);
和我在一個@Before
方法使用stubFor
,然後馬上遵循了該存根URL的調用(通過Spring的RestTemplate
),第一個測試案例工作順利,但第二個測試案例掛起。相關堆棧跟蹤的位是:
"main" prio=10 tid=0x00007f60a4009000 nid=0xb8d0 runnable [0x00007f60abcec000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:146)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
- locked <0x00000000f33e8d00> (a java.io.BufferedInputStream)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:688)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:767)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:633)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1162)
- locked <0x00000000f33da7c8> (a sun.net.www.protocol.http.HttpURLConnection)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:397)
at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:48)
at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:33)
at org.springframework.web.client.DefaultResponseErrorHandler.getHttpStatusCode(DefaultResponseErrorHandler.java:56)
at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:50)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:542)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:502)
at org.springframework.web.client.RestTemplate.put(RestTemplate.java:381)
如果我改用'入門'頁面上顯示的靜態方法,一切正常。我很喜歡使用靜態方法,這樣WireMock就可以在每個類中啓動/停止一次,但對於我自己的啓發,我很想知道爲什麼其他情況不能按預期工作。
更新:只注意到〜200秒後,測試失敗:
nested exception is java.net.SocketException: Unexpected end of file from server
感謝, 賈斯汀