2013-01-18 13:20:17 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.io
|
|
|
|
|
|
2013-01-22 13:48:36 +01:00
|
|
|
import akka.testkit.AkkaSpec
|
2013-01-18 13:20:17 +01:00
|
|
|
import akka.util.ByteString
|
|
|
|
|
import Tcp._
|
|
|
|
|
import TestUtils._
|
|
|
|
|
|
2013-01-22 13:48:36 +01:00
|
|
|
class IntegrationSpec extends AkkaSpec("akka.loglevel = INFO") with IntegrationSpecSupport {
|
2013-01-18 13:20:17 +01:00
|
|
|
|
|
|
|
|
"The TCP transport implementation" should {
|
|
|
|
|
|
|
|
|
|
"properly bind a test server" in new TestSetup
|
|
|
|
|
|
|
|
|
|
"allow connecting to and disconnecting from the test server" in new TestSetup {
|
|
|
|
|
val (clientHandler, clientConnection, serverHandler, serverConnection) = establishNewClientConnection()
|
|
|
|
|
clientHandler.send(clientConnection, Close)
|
|
|
|
|
clientHandler.expectMsg(Closed)
|
|
|
|
|
serverHandler.expectMsg(PeerClosed)
|
|
|
|
|
verifyActorTermination(clientConnection)
|
|
|
|
|
verifyActorTermination(serverConnection)
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 17:41:51 +01:00
|
|
|
"properly handle connection abort from one side" in new TestSetup {
|
|
|
|
|
val (clientHandler, clientConnection, serverHandler, serverConnection) = establishNewClientConnection()
|
|
|
|
|
clientHandler.send(clientConnection, Abort)
|
|
|
|
|
clientHandler.expectMsg(Aborted)
|
2013-01-23 11:47:12 +01:00
|
|
|
serverHandler.expectMsgType[ErrorClosed]
|
2013-01-21 17:41:51 +01:00
|
|
|
verifyActorTermination(clientConnection)
|
|
|
|
|
verifyActorTermination(serverConnection)
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-18 13:20:17 +01:00
|
|
|
"properly complete one client/server request/response cycle" in new TestSetup {
|
|
|
|
|
val (clientHandler, clientConnection, serverHandler, serverConnection) = establishNewClientConnection()
|
|
|
|
|
|
2013-01-22 13:48:36 +01:00
|
|
|
clientHandler.send(clientConnection, Write(ByteString("Captain on the bridge!"), 'Aye))
|
|
|
|
|
clientHandler.expectMsg('Aye)
|
2013-01-18 13:20:17 +01:00
|
|
|
serverHandler.expectMsgType[Received].data.decodeString("ASCII") must be("Captain on the bridge!")
|
|
|
|
|
|
2013-01-22 13:48:36 +01:00
|
|
|
serverHandler.send(serverConnection, Write(ByteString("For the king!"), 'Yes))
|
|
|
|
|
serverHandler.expectMsg('Yes)
|
2013-01-18 13:20:17 +01:00
|
|
|
clientHandler.expectMsgType[Received].data.decodeString("ASCII") must be("For the king!")
|
|
|
|
|
|
|
|
|
|
serverHandler.send(serverConnection, Close)
|
|
|
|
|
serverHandler.expectMsg(Closed)
|
|
|
|
|
clientHandler.expectMsg(PeerClosed)
|
|
|
|
|
|
|
|
|
|
verifyActorTermination(clientConnection)
|
|
|
|
|
verifyActorTermination(serverConnection)
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-22 13:48:36 +01:00
|
|
|
"support waiting for writes with backpressure" in new TestSetup {
|
2013-01-21 17:41:51 +01:00
|
|
|
val (clientHandler, clientConnection, serverHandler, serverConnection) = establishNewClientConnection()
|
|
|
|
|
|
2013-01-22 13:48:36 +01:00
|
|
|
serverHandler.send(serverConnection, Write(ByteString(Array.fill[Byte](100000)(0)), 'Ack))
|
|
|
|
|
serverHandler.expectMsg('Ack)
|
2013-01-21 17:41:51 +01:00
|
|
|
|
|
|
|
|
expectReceivedData(clientHandler, 100000)
|
|
|
|
|
|
2013-01-22 13:48:36 +01:00
|
|
|
override def bindOptions = List(SO.SendBufferSize(1024))
|
|
|
|
|
override def connectOptions = List(SO.ReceiveBufferSize(1024))
|
2013-01-18 13:20:17 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-21 17:41:51 +01:00
|
|
|
}
|