Skip to content

Commit

Permalink
Merge fe3f269 into b2c49e9
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Jun 15, 2017
2 parents b2c49e9 + fe3f269 commit 51a8036
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Expand Up @@ -2,10 +2,12 @@ language: java
install: true
jdk: oraclejdk8
env:
matrix:
- TERM=dumb
# list of compatible versions
- UNDERTOW_VERSION=1.3.15.Final
- UNDERTOW_VERSION=1.4.6.Final
before_script:
- ./gradlew --version
script: ./gradlew build
after_success:
- ./gradlew jacocoTestReport coveralls
- ./gradlew jacocoTestReport coveralls
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -28,7 +28,7 @@ configurations {

dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.8'
compile 'io.undertow:undertow-core:1.4.6.Final'
compile "io.undertow:undertow-core:${System.getenv('UNDERTOW_VERSION') ?: '1.4.6.Final'}"

compile 'ch.qos.logback:logback-classic:1.1.7'

Expand Down
22 changes: 14 additions & 8 deletions src/main/groovy/com/stehno/ersatz/ErsatzServer.groovy
Expand Up @@ -282,10 +282,12 @@ class ErsatzServer implements ServerConfig {
*/
void start() {
if (!started) {
Undertow.Builder builder = Undertow.builder().addHttpListener(EPHEMERAL_PORT, LOCALHOST)
actualHttpPort = generateRandomPort()
Undertow.Builder builder = Undertow.builder().addHttpListener(actualHttpPort, LOCALHOST)

if (httpsEnabled) {
builder.addHttpsListener(EPHEMERAL_PORT, LOCALHOST, sslContext())
actualHttpsPort = generateRandomPort()
builder.addHttpsListener(actualHttpsPort, LOCALHOST, sslContext())
}

BlockingHandler blockingHandler = new BlockingHandler(new EncodingHandler(
Expand Down Expand Up @@ -317,12 +319,6 @@ class ErsatzServer implements ServerConfig {

server.start()

actualHttpPort = (server.listenerInfo[0].address as InetSocketAddress).port

if (httpsEnabled) {
actualHttpsPort = (server.listenerInfo[1].address as InetSocketAddress).port
}

started = true
}
}
Expand Down Expand Up @@ -392,6 +388,16 @@ class ErsatzServer implements ServerConfig {
exchange.responseSender.send(responseContent)
}

private static int generateRandomPort() {
ServerSocket httpTestSocket = null
try {
httpTestSocket = new ServerSocket(EPHEMERAL_PORT)
return httpTestSocket.getLocalPort()
} finally {
httpTestSocket?.close()
}
}

@CompileStatic(TypeCheckingMode.SKIP)
private SSLContext sslContext() {
KeyStore keyStore = KeyStore.getInstance('JKS')
Expand Down

0 comments on commit 51a8036

Please sign in to comment.