Merging
This commit is contained in:
parent
fc1d7b3859
commit
e3c83da036
78 changed files with 804 additions and 1021 deletions
|
|
@ -4,13 +4,14 @@ import java.util.concurrent.TimeUnit
|
|||
import junit.framework.TestCase
|
||||
|
||||
import org.scalatest.junit.JUnitSuite
|
||||
import org.junit.Test
|
||||
import org.junit.{Test, Before, After}
|
||||
|
||||
import se.scalablesolutions.akka.nio.{RemoteNode, RemoteServer}
|
||||
import se.scalablesolutions.akka.remote.{RemoteServer, RemoteClient}
|
||||
import se.scalablesolutions.akka.dispatch.Dispatchers
|
||||
|
||||
object Global {
|
||||
var oneWay = "nada"
|
||||
var remoteReply = "nada"
|
||||
}
|
||||
class RemoteActorSpecActorUnidirectional extends Actor {
|
||||
dispatcher = Dispatchers.newThreadBasedDispatcher(this)
|
||||
|
|
@ -22,8 +23,6 @@ class RemoteActorSpecActorUnidirectional extends Actor {
|
|||
}
|
||||
|
||||
class RemoteActorSpecActorBidirectional extends Actor {
|
||||
dispatcher = Dispatchers.newThreadBasedDispatcher(this)
|
||||
|
||||
def receive = {
|
||||
case "Hello" =>
|
||||
reply("World")
|
||||
|
|
@ -32,23 +31,58 @@ class RemoteActorSpecActorBidirectional extends Actor {
|
|||
}
|
||||
}
|
||||
|
||||
case class Send(actor:Actor)
|
||||
|
||||
class RemoteActorSpecActorAsyncSender extends Actor {
|
||||
def receive = {
|
||||
case Send(actor:Actor) =>
|
||||
actor ! "Hello"
|
||||
case "World" =>
|
||||
Global.remoteReply = "replied"
|
||||
}
|
||||
|
||||
def send(actor:Actor) {
|
||||
this ! Send(actor)
|
||||
}
|
||||
}
|
||||
|
||||
class RemoteActorTest extends JUnitSuite {
|
||||
import Actor.Sender.Self
|
||||
|
||||
akka.Config.config
|
||||
new Thread(new Runnable() {
|
||||
def run = {
|
||||
RemoteNode.start
|
||||
}
|
||||
}).start
|
||||
Thread.sleep(1000)
|
||||
|
||||
|
||||
val HOSTNAME = "localhost"
|
||||
val PORT1 = 9990
|
||||
val PORT2 = 9991
|
||||
var s1:RemoteServer = null
|
||||
var s2:RemoteServer = null
|
||||
|
||||
@Before
|
||||
def init() {
|
||||
s1 = new RemoteServer()
|
||||
s2 = new RemoteServer()
|
||||
|
||||
s1.start(HOSTNAME, PORT1)
|
||||
s2.start(HOSTNAME, PORT2)
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
|
||||
private val unit = TimeUnit.MILLISECONDS
|
||||
|
||||
// make sure the servers shutdown cleanly after the test has
|
||||
// finished
|
||||
@After
|
||||
def finished() {
|
||||
s1.shutdown
|
||||
s2.shutdown
|
||||
RemoteClient.shutdownAll
|
||||
Thread.sleep(1000)
|
||||
}
|
||||
|
||||
@Test
|
||||
def shouldSendOneWay = {
|
||||
val actor = new RemoteActorSpecActorUnidirectional
|
||||
actor.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
||||
actor.makeRemote(HOSTNAME, PORT1)
|
||||
actor.start
|
||||
val result = actor ! "OneWay"
|
||||
Thread.sleep(100)
|
||||
|
|
@ -59,18 +93,54 @@ class RemoteActorTest extends JUnitSuite {
|
|||
@Test
|
||||
def shouldSendReplyAsync = {
|
||||
val actor = new RemoteActorSpecActorBidirectional
|
||||
actor.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
||||
actor.makeRemote(HOSTNAME, PORT1)
|
||||
actor.start
|
||||
val result = actor !! "Hello"
|
||||
assert("World" === result.get.asInstanceOf[String])
|
||||
actor.stop
|
||||
}
|
||||
|
||||
@Test
|
||||
def shouldSendRemoteReply = {
|
||||
implicit val timeout = 500000000L
|
||||
val actor = new RemoteActorSpecActorBidirectional
|
||||
actor.makeRemote(HOSTNAME, PORT2)
|
||||
actor.start
|
||||
|
||||
val sender = new RemoteActorSpecActorAsyncSender
|
||||
sender.setContactAddress(HOSTNAME, PORT1)
|
||||
sender.start
|
||||
sender.send(actor)
|
||||
Thread.sleep(500)
|
||||
assert("replied" === Global.remoteReply)
|
||||
actor.stop
|
||||
}
|
||||
|
||||
/*
|
||||
This test does not throw an exception since the
|
||||
_contactAddress is always defined via the
|
||||
global configuration if not set explicitly.
|
||||
|
||||
@Test
|
||||
def shouldSendRemoteReplyException = {
|
||||
implicit val timeout = 500000000L
|
||||
val actor = new RemoteActorSpecActorBidirectional
|
||||
actor.makeRemote(HOSTNAME, PORT1)
|
||||
actor.start
|
||||
|
||||
val sender = new RemoteActorSpecActorAsyncSender
|
||||
sender.start
|
||||
sender.send(actor)
|
||||
Thread.sleep(500)
|
||||
assert("exception" === Global.remoteReply)
|
||||
actor.stop
|
||||
}
|
||||
*/
|
||||
@Test
|
||||
def shouldSendReceiveException = {
|
||||
implicit val timeout = 500000000L
|
||||
val actor = new RemoteActorSpecActorBidirectional
|
||||
actor.makeRemote(RemoteServer.HOSTNAME, RemoteServer.PORT)
|
||||
actor.makeRemote(HOSTNAME, PORT1)
|
||||
actor.start
|
||||
try {
|
||||
actor !! "Failure"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue