2013-01-30 18:10:45 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
package akka.io
|
|
|
|
|
|
|
|
|
|
import akka.testkit.{ TestProbe, ImplicitSender, AkkaSpec }
|
|
|
|
|
import akka.io.UdpFF._
|
|
|
|
|
import TestUtils._
|
|
|
|
|
import akka.util.ByteString
|
|
|
|
|
import java.net.InetSocketAddress
|
|
|
|
|
import akka.actor.ActorRef
|
|
|
|
|
|
|
|
|
|
class UdpFFIntegrationSpec extends AkkaSpec("akka.loglevel = INFO") with ImplicitSender {
|
|
|
|
|
|
2013-02-22 14:14:13 +01:00
|
|
|
val addresses = temporaryServerAddresses(3)
|
|
|
|
|
|
|
|
|
|
def bindUdp(address: InetSocketAddress, handler: ActorRef): ActorRef = {
|
2013-01-30 18:10:45 +01:00
|
|
|
val commander = TestProbe()
|
|
|
|
|
commander.send(IO(UdpFF), Bind(handler, address))
|
|
|
|
|
commander.expectMsg(Bound)
|
2013-02-22 14:14:13 +01:00
|
|
|
commander.sender
|
2013-01-30 18:10:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val simpleSender: ActorRef = {
|
|
|
|
|
val commander = TestProbe()
|
2013-02-12 13:08:41 +01:00
|
|
|
commander.send(IO(UdpFF), SimpleSender)
|
2013-01-30 18:10:45 +01:00
|
|
|
commander.expectMsg(SimpleSendReady)
|
|
|
|
|
commander.sender
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"The UDP Fire-and-Forget implementation" must {
|
|
|
|
|
|
|
|
|
|
"be able to send without binding" in {
|
2013-02-22 14:14:13 +01:00
|
|
|
val serverAddress = addresses(0)
|
|
|
|
|
val server = bindUdp(serverAddress, testActor)
|
2013-01-30 18:10:45 +01:00
|
|
|
val data = ByteString("To infinity and beyond!")
|
|
|
|
|
simpleSender ! Send(data, serverAddress)
|
|
|
|
|
|
2013-02-10 13:52:52 +01:00
|
|
|
expectMsgType[Received].data must be === data
|
|
|
|
|
|
2013-01-30 18:10:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"be able to send with binding" in {
|
2013-02-22 14:14:13 +01:00
|
|
|
val serverAddress = addresses(1)
|
|
|
|
|
val clientAddress = addresses(2)
|
|
|
|
|
val server = bindUdp(serverAddress, testActor)
|
|
|
|
|
val client = bindUdp(clientAddress, testActor)
|
2013-01-30 18:10:45 +01:00
|
|
|
val data = ByteString("Fly little packet!")
|
|
|
|
|
|
|
|
|
|
client ! Send(data, serverAddress)
|
|
|
|
|
|
|
|
|
|
expectMsgPF() {
|
|
|
|
|
case Received(d, a) ⇒
|
|
|
|
|
d must be === data
|
|
|
|
|
a must be === clientAddress
|
|
|
|
|
}
|
2013-02-07 17:54:42 +01:00
|
|
|
server ! Send(data, clientAddress)
|
|
|
|
|
expectMsgPF() {
|
|
|
|
|
case Received(d, a) ⇒
|
|
|
|
|
d must be === data
|
|
|
|
|
a must be === serverAddress
|
|
|
|
|
}
|
2013-01-30 18:10:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|