Skip to content

Instantly share code, notes, and snippets.

@RayRoestenburg
Created June 10, 2011 10:11
Show Gist options
  • Save RayRoestenburg/1018581 to your computer and use it in GitHub Desktop.
Save RayRoestenburg/1018581 to your computer and use it in GitHub Desktop.
What is the expected behavior of remote bangbang?
package unit.akka
import org.junit.Test
import akka.remote.netty.NettyRemoteSupport
import akka.actor.Actor
import akka.event.slf4j.Logging
import org.scalatest.junit.{ShouldMatchersForJUnit, JUnitSuite}
import org.scalatest.BeforeAndAfterAll
import akka.actor.Actor._
import java.nio.channels.ClosedChannelException
class RemoteMailboxTest extends JUnitSuite with Logging with ShouldMatchersForJUnit with BeforeAndAfterAll {
def OptimizeLocal = false
var optimizeLocal_? = remote.asInstanceOf[NettyRemoteSupport].optimizeLocalScoped_?
override def beforeAll(configMap: Map[String, Any]) {
if (!OptimizeLocal)
remote.asInstanceOf[NettyRemoteSupport].optimizeLocal.set(false) //Can't run the test if we're eliminating all remote calls
remote.start("localhost", 2002)
}
override def afterAll(configMap: Map[String, Any]) {
if (!OptimizeLocal)
remote.asInstanceOf[NettyRemoteSupport].optimizeLocal.set(optimizeLocal_?) //Reset optimizelocal after all tests
Actor.registry.shutdownAll()
remote.shutdown()
}
// doesnt work
@Test def testRemoteBangBangTimeout() {
remote.register("strings",actorOf(new TestActor))
val actorRef = remote.actorFor("strings", "localhost",2003)
(actorRef !! "test").isDefined should be (false)
}
// doesnt work
@Test def testRemoteBangNoException() {
remote.register("strings",actorOf(new TestActor))
val actorRef = remote.actorFor("strings", "localhost",2003)
actorRef ! "test"
}
// works
@Test(expected = classOf[ClosedChannelException])
def testRemoteBangBangFailure() {
remote.register("strings",actorOf(new TestActor))
val actorRef = remote.actorFor("strings", "localhost",2003)
(actorRef !! "test").isDefined should be (false)
}
//works
@Test(expected = classOf[ClosedChannelException])
def testRemoteBangFailure() {
remote.register("strings",actorOf(new TestActor))
val actorRef = remote.actorFor("strings", "localhost",2003)
actorRef ! "test"
}
}
class TestActor extends Actor {
def receive = {
case s:String => self.reply_?(s)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment