=doc #3782 Make IODocSpec say what went wrong

This commit is contained in:
Björn Antonsson 2013-12-13 12:16:25 +01:00
parent 4972c7780c
commit 5935e2e2b7

View file

@ -78,7 +78,7 @@ class Client(remote: InetSocketAddress, listener: ActorRef) extends Actor {
def receive = { def receive = {
case CommandFailed(_: Connect) => case CommandFailed(_: Connect) =>
listener ! "failed" listener ! "connect failed"
context stop self context stop self
case c @ Connected(remote, local) => case c @ Connected(remote, local) =>
@ -86,11 +86,18 @@ class Client(remote: InetSocketAddress, listener: ActorRef) extends Actor {
val connection = sender val connection = sender
connection ! Register(self) connection ! Register(self)
context become { context become {
case data: ByteString => connection ! Write(data) case data: ByteString =>
case CommandFailed(w: Write) => // O/S buffer was full connection ! Write(data)
case Received(data) => listener ! data case CommandFailed(w: Write) =>
case "close" => connection ! Close // O/S buffer was full
case _: ConnectionClosed => context stop self listener ! "write failed"
case Received(data) =>
listener ! data
case "close" =>
connection ! Close
case _: ConnectionClosed =>
listener ! "connection closed"
context stop self
} }
} }
} }
@ -110,6 +117,8 @@ class IODocSpec extends AkkaSpec {
val listen = expectMsgType[Tcp.Bound].localAddress val listen = expectMsgType[Tcp.Bound].localAddress
val client = system.actorOf(Client.props(listen, testActor), "client1") val client = system.actorOf(Client.props(listen, testActor), "client1")
watch(client)
val c1, c2 = expectMsgType[Tcp.Connected] val c1, c2 = expectMsgType[Tcp.Connected]
c1.localAddress must be(c2.remoteAddress) c1.localAddress must be(c2.remoteAddress)
c2.localAddress must be(c1.remoteAddress) c2.localAddress must be(c1.remoteAddress)
@ -117,8 +126,8 @@ class IODocSpec extends AkkaSpec {
client ! ByteString("hello") client ! ByteString("hello")
expectMsgType[ByteString].utf8String must be("hello") expectMsgType[ByteString].utf8String must be("hello")
watch(client)
client ! "close" client ! "close"
expectMsg("connection closed")
expectTerminated(client, 1.second) expectTerminated(client, 1.second)
} }