Permalink
Browse files

Merge remote-tracking branch 'twilio-kelvin/scala' into scala

  • Loading branch information...
2 parents 0f8b02c + 93a5f7d commit 148b046b135dbf9c5629a2f25be3fd6925ffaaf3 @kelvl kelvl committed Apr 29, 2013
Showing with 26 additions and 29 deletions.
  1. +21 −24 src/main/scala/com/twilio/shadow/UIService.scala
  2. +5 −5 src/test/scala/com/twilio/shadow/ProxySuite.scala
@@ -32,14 +32,15 @@ object JsonUtil {
def shadowEntryJson(entry: ShadowEntry) = {
val req = httpRequestToJson(entry.request)
- val json =
- ("request" -> (
- ("original" -> req) ~
- ("modified" -> req)
- )) ~
- ("results" -> List(entry.responses._1, entry.responses._2).map( x => httpResponseToJson(x._1) ~ ("elapsed_time" -> x._2) ))
-
- json
+ ("request" -> (
+ ("original" -> req) ~
+ ("modified" -> req)
+ )) ~
+ ("results" -> List(entry.responses._1, entry.responses._2)
+ .map( x => httpResponseToJson(x._1) ~ ("elapsed_time" -> x._2) )
+ )
+
+
}
def httpRequestToJson(httpRequest: HttpRequest) = {
@@ -50,25 +51,20 @@ object JsonUtil {
val queryParams = request.queryParams
- val json =
- ("url" -> request.path) ~
- ("headers" -> request.headers.map { x => x.name -> x.value }.toMap ) ~
- ("post" -> formParams) ~
- ("method" -> request.method.value) ~
- ("get" -> queryParams)
- json
+ ("url" -> request.path) ~
+ ("headers" -> request.headers.map { x => x.name -> x.value }.toMap ) ~
+ ("post" -> formParams) ~
+ ("method" -> request.method.value) ~
+ ("get" -> queryParams)
}
def httpResponseToJson(httpResponse: HttpResponse) = {
-
- val json =
- ("headers" -> httpResponse.headers.map { x => (
- (x.name -> x.value)
- ) }.toMap) ~
- ("status_code" -> httpResponse.status.value) ~
- ("type" -> "http_response") ~
- ("body" -> httpResponse.entity.asString)
- json
+ ("headers" -> httpResponse.headers.map { x => (
+ (x.name -> x.value)
+ ) }.toMap) ~
+ ("status_code" -> httpResponse.status.value) ~
+ ("type" -> "http_response") ~
+ ("body" -> httpResponse.entity.asString)
}
}
@@ -89,6 +85,7 @@ class ResponseStreamActor(val ctx: RequestContext) extends Actor with SprayActor
case HttpServer.Closed(_, reason) =>
log.warning("Stopping response streaming due to {}", reason)
+ context.system.eventStream.unsubscribe(self)
context.stop(self)
}
@@ -140,7 +140,7 @@ class ProxySuite extends FunSpec with SpanSugar with ShouldMatchers with BeforeA
Given("trueServer and shadowServer both returns 200 OK")
whenHttp(trueServer).`match`(get("/test")).then(success(), stringContent("OK")).mustHappen(1)
- whenHttp(shadowServer).`match`(startsWithUri("/test")).then(success(), stringContent("OK")).mustHappen(1)
+ whenHttp(shadowServer).`match`(get("/test")).then(success(), stringContent("OK")).mustHappen(1)
implicit val actorRefFactory: ActorRefFactory = actorSystem
@@ -173,7 +173,7 @@ class ProxySuite extends FunSpec with SpanSugar with ShouldMatchers with BeforeA
Given("trueServer returns OK but shadowServer returns a 500")
whenHttp(trueServer).`match`(get("/test")).then(success(), stringContent("OK")).mustHappen(1)
// simulate a internal server error
- whenHttp(shadowServer).`match`(startsWithUri("/test"))
+ whenHttp(shadowServer).`match`(get("/test"))
.then(status(HttpStatus.INTERNAL_SERVER_ERROR_500), stringContent("NOT-OK")).mustHappen(1)
implicit val actorRefFactory: ActorRefFactory = actorSystem
@@ -210,7 +210,7 @@ class ProxySuite extends FunSpec with SpanSugar with ShouldMatchers with BeforeA
Given("true server returns 200 OK but shadow server returns a 500 after 2 seconds")
whenHttp(trueServer).`match`(get("/test")).then(success(), stringContent("OK")).mustHappen(1)
// simulate a internal server error after a timeout
- whenHttp(shadowServer).`match`(startsWithUri("/test"))
+ whenHttp(shadowServer).`match`(get("/test"))
.then(
status(HttpStatus.INTERNAL_SERVER_ERROR_500),
stringContent("NOT-OK"),
@@ -227,11 +227,11 @@ class ProxySuite extends FunSpec with SpanSugar with ShouldMatchers with BeforeA
val respF = HttpDialog(httpClient, "localhost", proxyPort).send(Get("/test")).end
// the timeout value here ensures that we are getting the result from the true server
- // as soon as it is available and not after 5 seconds
+ // as soon as it is available and not after 2 seconds
Then("proxy server should return as soon as the true server returns")
respF.futureValue(timeout(1.seconds)).entity.asString should be ("OK")
- // this should still be filed after 5 seconds
+ // this should still be filed after 2 seconds
And("we should still get a ShadowEntry after the shadow server returns")
val entry = testProbe.expectMsgType[ShadowEntry](max = Duration(3, TimeUnit.SECONDS))

0 comments on commit 148b046

Please sign in to comment.