diff options
author | Jakob Odersky <jakob@odersky.com> | 2017-01-08 21:16:25 +0100 |
---|---|---|
committer | Jakob Odersky <jakob@odersky.com> | 2017-01-21 17:22:10 -0800 |
commit | 23959966760174477a6b0fcbf9dd1e8ef37c643b (patch) | |
tree | 9a0ee44eb43a8c13af57b0d06313f3aabf9e4555 /stream/src/test/scala/akka/serial/stream/SerialSpec.scala | |
parent | 6c371ba6d69c891c1f0d6df00bb643e1d543cc9d (diff) | |
download | akka-serial-23959966760174477a6b0fcbf9dd1e8ef37c643b.tar.gz akka-serial-23959966760174477a6b0fcbf9dd1e8ef37c643b.tar.bz2 akka-serial-23959966760174477a6b0fcbf9dd1e8ef37c643b.zip |
Rename project to akka-serial
Diffstat (limited to 'stream/src/test/scala/akka/serial/stream/SerialSpec.scala')
-rw-r--r-- | stream/src/test/scala/akka/serial/stream/SerialSpec.scala | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/stream/src/test/scala/akka/serial/stream/SerialSpec.scala b/stream/src/test/scala/akka/serial/stream/SerialSpec.scala new file mode 100644 index 0000000..7a64383 --- /dev/null +++ b/stream/src/test/scala/akka/serial/stream/SerialSpec.scala @@ -0,0 +1,51 @@ +package akka.serial +package stream + +import scala.concurrent.Await +import scala.concurrent.duration._ + +import akka.actor.ActorSystem +import akka.stream.ActorMaterializer +import akka.stream.scaladsl.{Keep, Sink, Source} +import akka.util.ByteString +import org.scalatest._ + +class SerialSpec extends WordSpec with BeforeAndAfterAll with PseudoTerminal { + + implicit val system = ActorSystem("akka-serial-test") + implicit val materializer = ActorMaterializer() + + override def afterAll { + system.terminate() + } + + "Serial stream" should { + val data = ByteString(("hello world").getBytes("utf-8")) + + "receive the same data it sends in an echo test" in { + withEcho { case (port, settings) => + val graph = Source.single(data) + .via(Serial().open(port, settings)) // send to echo pty + .scan(ByteString.empty)(_ ++ _) // received elements could potentially be split by OS + .dropWhile(_ != data) + .toMat(Sink.head)(Keep.right) + + Await.result(graph.run(), 2.seconds) + } + } + + "fail if the underlying pty fails" in { + val result = withEcho { case (port, settings) => + Source.single(data) + .via(Serial().open(port, settings)) + .toMat(Sink.last)(Keep.right) + .run()} + + intercept[StreamSerialException] { + Await.result(result, 10.seconds) + } + } + + } + +} |