I guess I still don't know what I'm doing. ;)

I have this very simple one-file server:

object MyMain extends App
{
  implicit val system = ActorSystem()
  implicit val materializer = ActorMaterializer()
...
  val requestHandler: HttpRequest => Future[HttpResponse] = { ....}
  Http().bindAndHandleAsync(requestHandler, "localhost", 9999)
}

that works ok.. then I try to write the test:

class TestSpecextends FunSuite  with Matchers with  ScalaFutures with 
BeforeAndAfterAll {
  override def beforeAll = { }
  override def afterAll = system.shutdown()

  def sendRequest(req: HttpRequest) =
    Source.single(req).via(
      Http(system).outgoingConnection(host = "localhost",  port = 
9999)).runWith(Sink.head)

  test ("TESTING") {
    val request = sendRequest(HttpRequest(uri = "/shouldnotexist"))
    whenReady(request) { response =>
      response.status shouldBe StatusCodes.NotFound
    }
  
  }
}


I got two problems:
1. Resolving the conflict between the ActorSystem/Materializer in my MyMain 
and the one in the test spec.
2. Starting my server on demand. I tried various refactorings of my main 
such as moving the code to a companion trait, but when I initialize it that 
way, it also causes my Object to initialize and I end up with two copies of 
the service running.

Anyway, I'm pretty new to this, so hopefully this doesn't sound too dumb -- 
cuz i sure sounds dumb to me! How should I rewrite my test to initialize my 
server in beforeAll(), run my test, and end it in afterAll()?



On Thursday, September 10, 2015 at 11:30:22 PM UTC-5, Val P wrote:
>
> Hi,
>
> Can the akka-http 1.0 low level api be tested using Akka-http-testkit?
> So far, It appears only the high level api (using the routing dsl) can be 
> tested?
>
> Could someone be kind enough to point me or show me how to write unit 
> tests for the low level API?
>
>
>
>
>
>

-- 
>>>>>>>>>>      Read the docs: http://akka.io/docs/
>>>>>>>>>>      Check the FAQ: 
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>>      Search the archives: https://groups.google.com/group/akka-user
--- 
You received this message because you are subscribed to the Google Groups "Akka 
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to akka-user+unsubscr...@googlegroups.com.
To post to this group, send email to akka-user@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to