when the connection is established optimistically try reading before registering ReadInterest

This commit is contained in:
Johannes Rudolph 2013-01-23 15:28:14 +01:00
parent f138dbd6b4
commit 3e78247cc8
2 changed files with 19 additions and 1 deletions

View file

@ -59,6 +59,24 @@ class TcpConnectionSpec extends AkkaSpec("akka.io.tcp.register-timeout = 500ms")
expectReceivedString("testdata2testdata3")
}
"receive data directly when the connection is established" in withUnacceptedConnection() { unregisteredSetup
import unregisteredSetup._
localServer.configureBlocking(true)
val serverSideChannel = localServer.accept()
serverSideChannel must not be (null)
serverSideChannel.write(ByteBuffer.wrap("immediatedata".getBytes("ASCII")))
serverSideChannel.configureBlocking(false)
selector.send(connectionActor, ChannelConnectable)
userHandler.expectMsg(Connected(serverAddress, clientSideChannel.socket.getLocalSocketAddress.asInstanceOf[InetSocketAddress]))
// we unrealistically register the selector here so that we can observe
// the ordering between Received and ReadInterest
userHandler.send(connectionActor, Register(selector.ref))
selector.expectMsgType[Received].data.decodeString("ASCII") must be("immediatedata")
selector.expectMsg(ReadInterest)
}
"write data to network (and acknowledge)" in withEstablishedConnection() { setup
import setup._