Skip to content

Commit

Permalink
set timeout from recorder rather than explicitly passing to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
robfletcher committed Sep 15, 2011
1 parent 9e82caf commit ed5317f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/main/groovy/betamax/Recorder.groovy
Expand Up @@ -80,7 +80,7 @@ class Recorder implements MethodRule {
int proxyTimeout = DEFAULT_PROXY_TIMEOUT

private StorableTape tape
private ProxyServer proxy = new ProxyServer(proxyPort, proxyTimeout) // TODO: setting params here isn't working as it's before config parsing
private ProxyServer proxy = new ProxyServer(proxyPort) // TODO: setting params here isn't working as it's before config parsing

/**
* Inserts a tape either creating a new one or loading an existing file from `tapeRoot`.
Expand Down
7 changes: 2 additions & 5 deletions src/main/groovy/betamax/proxy/jetty/ProxyServer.groovy
Expand Up @@ -21,17 +21,14 @@ import betamax.proxy.RecordAndPlaybackProxyInterceptor

class ProxyServer extends SimpleServer {

private final int timeout

ProxyServer(int port, int timeout) {
ProxyServer(int port) {
super(port)
this.timeout = timeout
}

void start(Recorder recorder) {
def handler = new ProxyHandler()
handler.interceptor = new RecordAndPlaybackProxyInterceptor(recorder)
handler.timeout = timeout
handler.timeout = recorder.proxyTimeout

super.start(handler)
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/groovy/betamax/proxy/jetty/SimpleServer.groovy
Expand Up @@ -24,6 +24,8 @@ import org.eclipse.jetty.server.*

class SimpleServer extends AbstractLifeCycleListener {

static final int DEFAULT_PORT = 5000

private final String host
private final int port
private Server server
Expand All @@ -32,7 +34,7 @@ class SimpleServer extends AbstractLifeCycleListener {
private final log = Logger.getLogger(SimpleServer)

SimpleServer() {
this(5000)
this(DEFAULT_PORT)
}

SimpleServer(int port) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/betamax/proxy/NoTapeSpec.groovy
Expand Up @@ -3,7 +3,7 @@ package betamax.proxy
import betamax.Recorder
import betamax.util.server.EchoHandler
import org.apache.http.impl.conn.ProxySelectorRoutePlanner
import static betamax.Recorder.*
import static betamax.Recorder.DEFAULT_PROXY_PORT
import betamax.proxy.jetty.*
import groovyx.net.http.*
import static java.net.HttpURLConnection.HTTP_FORBIDDEN
Expand All @@ -13,7 +13,7 @@ import spock.lang.*
class NoTapeSpec extends Specification {

@Shared @AutoCleanup("restoreOriginalProxySettings") Recorder recorder = new Recorder()
@Shared @AutoCleanup("stop") ProxyServer proxy = new ProxyServer(DEFAULT_PROXY_PORT, DEFAULT_PROXY_TIMEOUT)
@Shared @AutoCleanup("stop") ProxyServer proxy = new ProxyServer(DEFAULT_PROXY_PORT)
@Shared @AutoCleanup("stop") SimpleServer endpoint = new SimpleServer()
RESTClient http

Expand Down
Expand Up @@ -5,7 +5,7 @@ import betamax.util.server.EchoHandler
import groovyx.net.http.RESTClient
import org.apache.http.impl.conn.ProxySelectorRoutePlanner
import org.yaml.snakeyaml.Yaml
import static betamax.Recorder.*
import static betamax.Recorder.DEFAULT_PROXY_PORT
import betamax.proxy.jetty.*
import static java.net.HttpURLConnection.HTTP_OK
import spock.lang.*
Expand All @@ -15,7 +15,7 @@ class ProxyRecordAndPlaybackSpec extends Specification {

@Shared @AutoCleanup("deleteDir") File tapeRoot = new File(System.properties."java.io.tmpdir", "tapes")
@Shared @AutoCleanup("ejectTape") Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@Shared @AutoCleanup("stop") ProxyServer proxy = new ProxyServer(DEFAULT_PROXY_PORT, DEFAULT_PROXY_TIMEOUT)
@Shared @AutoCleanup("stop") ProxyServer proxy = new ProxyServer(DEFAULT_PROXY_PORT)
@AutoCleanup("stop") SimpleServer endpoint = new SimpleServer()
RESTClient http

Expand Down Expand Up @@ -54,7 +54,6 @@ class ProxyRecordAndPlaybackSpec extends Specification {
then:
recorder.tape.interactions.size() == 1


cleanup:
recorder.tape.reset()
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/groovy/betamax/recorder/TapeModeSpec.groovy
Expand Up @@ -3,7 +3,7 @@ package betamax.recorder
import betamax.Recorder
import betamax.util.server.EchoHandler
import org.apache.http.impl.conn.ProxySelectorRoutePlanner
import static betamax.Recorder.*
import static betamax.Recorder.DEFAULT_PROXY_PORT
import static betamax.TapeMode.*
import betamax.proxy.jetty.*
import groovyx.net.http.*
Expand All @@ -14,7 +14,7 @@ class TapeModeSpec extends Specification {

@Shared @AutoCleanup("deleteDir") File tapeRoot = new File(System.properties."java.io.tmpdir", "tapes")
@Shared Recorder recorder = new Recorder(tapeRoot: tapeRoot)
@Shared @AutoCleanup("stop") ProxyServer proxy = new ProxyServer(DEFAULT_PROXY_PORT, DEFAULT_PROXY_TIMEOUT)
@Shared @AutoCleanup("stop") ProxyServer proxy = new ProxyServer(DEFAULT_PROXY_PORT)
@Shared @AutoCleanup("stop") SimpleServer endpoint = new SimpleServer()
RESTClient http

Expand Down

0 comments on commit ed5317f

Please sign in to comment.