2017-10-15 33 views
0

私はWireMockを使用しているJunitテストをいくつか持っています。ローカル(「ランダムスタートアップ上のHTTPSポートをasssign 」をドキュメントに応じた)のテストに合格し、しかし、ジェンキンスさんに、私は私がdynamicHttpsPort()を設定WireMock構成で java.lang.RuntimeException: java.net.BindException: Address already in useJenkinsのJunitのWireMock - BindException:既に使用されているアドレス

のエラーを取得してローカルで作業していて、上Jenkinsそれは失敗する。

マイWireMock構成は

@Rule 
    public WireMockRule wireMockRule = new WireMockRule(wireMockConfig() 
      .dynamicHttpsPort() 
      .keystorePath(certsDir.resolve("server.jks").toString()) 
      .keystorePassword(MY_PASS) 
      .keystoreType("JKS") 
    ); 

私は新しいWireMockRuleを作成する2つのJUnitのクラスを持っている、と彼らは同時に実行可能です。クラスの1つには4つのテストがあり、もう1つには1つのテストがあります。 5つのテストはすべて失敗します。

とフルスタックトレースは次のとおりです。

com.github.tomakehurst.wiremock.common.FatalStartupException: java.lang.RuntimeException: java.net.BindException: Address already in use 
    at com.github.tomakehurst.wiremock.WireMockServer.start(WireMockServer.java:146) 
    at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:68) 
    at org.junit.rules.RunRules.evaluate(RunRules.java:20) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) 
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) 
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) 
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172) 
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104) 
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70) 
Caused by: java.lang.RuntimeException: java.net.BindException: Address already in use 
    at com.github.tomakehurst.wiremock.jetty9.JettyHttpServer.start(JettyHttpServer.java:139) 
    at com.github.tomakehurst.wiremock.WireMockServer.start(WireMockServer.java:144) 
    ... 23 more 
Caused by: java.net.BindException: Address already in use 
    at sun.nio.ch.Net.bind0(Native Method) 
    at sun.nio.ch.Net.bind(Net.java:433) 
    at sun.nio.ch.Net.bind(Net.java:425) 
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) 
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) 
    at wiremock.org.eclipse.jetty.server.ServerConnector.open(ServerConnector.java:321) 
    at wiremock.org.eclipse.jetty.server.AbstractNetworkConnector.doStart(AbstractNetworkConnector.java:80) 
    at wiremock.org.eclipse.jetty.server.ServerConnector.doStart(ServerConnector.java:236) 
    at wiremock.org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at wiremock.org.eclipse.jetty.server.Server.doStart(Server.java:366) 
    at wiremock.org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) 
    at com.github.tomakehurst.wiremock.jetty9.JettyHttpServer.start(JettyHttpServer.java:137) 
    ... 24 more 

答えて

0

が解決here見つかり:

問題は、あなたが常にアクティブになる、のいずれかのHTTPポートを設定していないということで、 8080にデフォルト設定されています(したがって、クラッシュします)。両方の設定にdynamicPort()を追加すると、それを修正する必要があります。

のでdynamicPort()はそれを修正追加:

@Rule 
    public WireMockRule wireMockRule = new WireMockRule(wireMockConfig() 
      .dynamicPort() 
      .dynamicHttpsPort() 
      .keystorePath(certsDir.resolve("server.jks").toString()) 
      .keystorePassword(MY_PASS) 
      .keystoreType("JKS") 
    ); 
関連する問題