fixed TX Vector and TX Ref plus added tests + rewrote Reactor impl + added custom Actor impl(currently not used though)
This commit is contained in:
parent
74bd8dea6d
commit
167b724671
15 changed files with 1148 additions and 274 deletions
76
kernel/src/test/scala/ActorTest.scala
Normal file
76
kernel/src/test/scala/ActorTest.scala
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
package se.scalablesolutions.akka.kernel.actor
|
||||
|
||||
import concurrent.Lock
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import java.util.concurrent.TimeUnit
|
||||
import reactor._
|
||||
|
||||
import org.junit.{Test, Before}
|
||||
import org.junit.Assert._
|
||||
|
||||
class ActorTest {
|
||||
private val unit = TimeUnit.MILLISECONDS
|
||||
|
||||
class TestActor extends Actor {
|
||||
def receive: PartialFunction[Any, Unit] = {
|
||||
case "Hello" =>
|
||||
println("Hello")
|
||||
reply("World")
|
||||
case "Failure" =>
|
||||
throw new RuntimeException("expected")
|
||||
}
|
||||
def restart(config: Option[AnyRef]) = {}
|
||||
}
|
||||
|
||||
@Test
|
||||
def sendOneWay = {
|
||||
implicit val timeout = 5000L
|
||||
var oneWay = "nada"
|
||||
val actor = new Actor {
|
||||
def receive: PartialFunction[Any, Unit] = {
|
||||
case "OneWay" => oneWay = "received"
|
||||
}
|
||||
def restart(config: Option[AnyRef]) = {}
|
||||
}
|
||||
actor.start
|
||||
val result = actor ! "OneWay"
|
||||
Thread.sleep(100)
|
||||
assertEquals("received", oneWay)
|
||||
//actor.stop
|
||||
}
|
||||
|
||||
@Test
|
||||
def sendReplySync = {
|
||||
implicit val timeout = 5000L
|
||||
val actor = new TestActor
|
||||
actor.start
|
||||
val result = actor !? "Hello"
|
||||
assertEquals("World", result.get.asInstanceOf[String])
|
||||
//actor.stop
|
||||
}
|
||||
|
||||
@Test
|
||||
def sendReplyAsync = {
|
||||
implicit val timeout = 5000L
|
||||
val actor = new TestActor
|
||||
actor.start
|
||||
val result = actor !! "Hello"
|
||||
assertEquals("World", result.get.asInstanceOf[String])
|
||||
//actor.stop
|
||||
}
|
||||
|
||||
@Test
|
||||
def sendReceiveException = {
|
||||
implicit val timeout = 5000L
|
||||
val actor = new TestActor
|
||||
actor.start
|
||||
try {
|
||||
actor !! "Failure"
|
||||
fail("Should have thrown an exception")
|
||||
} catch {
|
||||
case e =>
|
||||
assertEquals("expected", e.getMessage())
|
||||
}
|
||||
//actor.stop
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue