Refine transactor doNothing (fixes #582)
This commit is contained in:
parent
c93a447bf1
commit
87138b7a0d
2 changed files with 31 additions and 1 deletions
|
|
@ -175,5 +175,8 @@ trait Transactor extends Actor {
|
|||
/**
|
||||
* Default catch-all for the different Receive methods.
|
||||
*/
|
||||
def doNothing: Receive = { case _ => }
|
||||
def doNothing: Receive = new Receive {
|
||||
def apply(any: Any) = {}
|
||||
def isDefinedAt(any: Any) = false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,8 +59,22 @@ object TransactorIncrement {
|
|||
}
|
||||
}
|
||||
|
||||
object SimpleTransactor {
|
||||
case class Set(ref: Ref[Int], value: Int, latch: CountDownLatch)
|
||||
|
||||
class Setter extends Transactor {
|
||||
def atomically = {
|
||||
case Set(ref, value, latch) => {
|
||||
ref.set(value)
|
||||
latch.countDown
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TransactorSpec extends WordSpec with MustMatchers {
|
||||
import TransactorIncrement._
|
||||
import SimpleTransactor._
|
||||
|
||||
val numCounters = 5
|
||||
val timeout = 5 seconds
|
||||
|
|
@ -97,4 +111,17 @@ class TransactorSpec extends WordSpec with MustMatchers {
|
|||
failer.stop
|
||||
}
|
||||
}
|
||||
|
||||
"Transactor" should {
|
||||
"be usable without overriding normally" in {
|
||||
val transactor = Actor.actorOf(new Setter).start
|
||||
val ref = Ref(0)
|
||||
val latch = new CountDownLatch(1)
|
||||
transactor ! Set(ref, 5, latch)
|
||||
latch.await(timeout.length, timeout.unit)
|
||||
val value = atomic { ref.get }
|
||||
value must be === 5
|
||||
transactor.stop
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue