Skip to content

Instantly share code, notes, and snippets.

@hierynomus
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hierynomus/9627861 to your computer and use it in GitHub Desktop.
Save hierynomus/9627861 to your computer and use it in GitHub Desktop.
Spray time-out with StatusCode 205
apply plugin: "scala"
apply plugin: "idea"
repositories {
maven { url "http://repo.spray.io" }
mavenCentral()
}
dependencies {
compile "org.scala-lang:scala-library:2.10.3"
compile "io.spray:spray-client:1.3.1"
compile "com.typesafe.akka:akka-actor_2.10:2.3.0"
compile "com.typesafe.akka:akka-slf4j_2.10:2.3.0"
testCompile "junit:junit:4.11"
testCompile "org.scalatest:scalatest_2.10:2.1.0"
testCompile "com.xebialabs.restito:restito:0.4-beta-2"
runtime "ch.qos.logback:logback-classic:1.0.9"
}
sourceSets.test.scala.srcDirs = [project.projectDir]
import org.scalatest.{BeforeAndAfterAll, ShouldMatchers, BeforeAndAfter, FunSpec}
import com.xebialabs.restito.server.StubServer
import com.xebialabs.restito.builder.stub.StubHttp._
import com.xebialabs.restito.semantics.Condition._
import com.xebialabs.restito.semantics.Action._
import org.glassfish.grizzly.http.util.HttpStatus
import akka.actor.ActorSystem
import spray.client.pipelining._
import scala.concurrent.{Await, Future}
import spray.http.{StatusCodes, HttpResponse}
import scala.concurrent.duration._
import language.postfixOps
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class Spray205Test extends FunSpec with BeforeAndAfterAll with ShouldMatchers {
var server: StubServer = _
implicit var actorSystem: ActorSystem = _
import scala.concurrent.ExecutionContext.Implicits.global
override def beforeAll() {
server = new StubServer().run()
actorSystem = ActorSystem("yakshop-tester")
whenHttp(server).`match`(post("/reset-me"), withPostBody()).`then`(status(HttpStatus.RESET_CONTENT_205))
whenHttp(server).`match`(post("/ok-me"), withPostBody()).`then`(status(HttpStatus.OK_200))
}
override def afterAll() {
server.stop()
actorSystem.shutdown()
}
describe("Spray Client") {
it("should not time out when posting and getting a '200 OK' response status") {
val future: Future[HttpResponse] = Post(s"http://localhost:${server.getPort}/ok-me", "I want to be ok") ~> sendReceive
Await.result(future, 5 seconds).status should equal(StatusCodes.OK)
}
it("should not time out when posting and getting a '205 Reset Content' response status") {
val future: Future[HttpResponse] = Post(s"http://localhost:${server.getPort}/reset-me", "I want to reset") ~> sendReceive
Await.result(future, 5 seconds).status should equal(StatusCodes.ResetContent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment