Closed alexander-myltsev closed 6 years ago
Starting point to test TcpServer
:
package org.globalnames
package parser
package runner
package tcp
import akka.actor.ActorSystem
import akka.stream._
import akka.stream.scaladsl._
import akka.util._
import GnParser.Config
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
class TcpServerSpec extends WordSpecLike with Matchers with BeforeAndAfterAll with ScalaFutures {
"An Echo actor" must {
"send back messages unchanged" in {
val address = "127.0.0.1"
val port = 4356
val config = Config(simpleFormat = true, host = address, port = port)
TcpServer.run(config)
implicit val client: ActorSystem = ActorSystem("SimpleTcpClient")
implicit val materializer: ActorMaterializer = ActorMaterializer()
val connection = Tcp().outgoingConnection(address, port)
val flow = Flow[ByteString]
.via(Framing.delimiter(ByteString("\n"), maximumFrameLength = 256, allowTruncation = true))
.map(_.utf8String)
.map(println)
.map(_ => "STOP")
.map(_+"\n")
.map(ByteString(_))
whenReady(connection.join(flow).run()) { r =>
println(r)
}
}
}
}
Currently
GnParser
is tightly coupled tomain
method args. We need to extract runners (web, tcp, file) to test each of them.