(re)move akka.japi.*PartialFunction and optimize TestKit, see #2357
This commit is contained in:
parent
d4ce9e6750
commit
0f923c0978
3 changed files with 37 additions and 31 deletions
|
|
@ -15,7 +15,6 @@ import scala.annotation.tailrec
|
|||
import akka.util.{ Timeout, BoxedType }
|
||||
import scala.annotation.varargs
|
||||
import scala.reflect.ClassTag
|
||||
import akka.japi.PurePartialFunction
|
||||
|
||||
object TestActor {
|
||||
type Ignore = Option[PartialFunction[AnyRef, Boolean]]
|
||||
|
|
@ -48,6 +47,8 @@ object TestActor {
|
|||
override def msg: AnyRef = throw new IllegalActorStateException("last receive did not dequeue a message")
|
||||
override def sender: ActorRef = throw new IllegalActorStateException("last receive did not dequeue a message")
|
||||
}
|
||||
|
||||
val FALSE = (x: Any) ⇒ false
|
||||
}
|
||||
|
||||
class TestActor(queue: BlockingDeque[TestActor.Message]) extends Actor {
|
||||
|
|
@ -67,7 +68,7 @@ class TestActor(queue: BlockingDeque[TestActor.Message]) extends Actor {
|
|||
case KeepRunning ⇒ autopilot
|
||||
case other ⇒ other
|
||||
}
|
||||
val observe = ignore map (ignoreFunc ⇒ if (ignoreFunc isDefinedAt x) !ignoreFunc(x) else true) getOrElse true
|
||||
val observe = ignore map (ignoreFunc ⇒ !ignoreFunc.applyOrElse(x, FALSE)) getOrElse true
|
||||
if (observe) queue.offerLast(RealMessage(x, sender))
|
||||
}
|
||||
|
||||
|
|
@ -713,3 +714,27 @@ trait ImplicitSender { this: TestKit ⇒
|
|||
trait DefaultTimeout { this: TestKit ⇒
|
||||
implicit val timeout: Timeout = testKitSettings.DefaultTimeout
|
||||
}
|
||||
|
||||
/**
|
||||
* INTERNAL API
|
||||
*
|
||||
* This is a specialized variant of PartialFunction which is <b><i>only
|
||||
* applicable if you know that `isDefinedAt(x)` is always called before
|
||||
* `apply(x)`—with the same `x` of course.</i></b>
|
||||
*
|
||||
* `match(x)` will be called for `isDefinedAt(x)` only, and its semantics
|
||||
* are the same as for [[akka.japi.PurePartialFunction]] (apart from the
|
||||
* missing because unneeded boolean argument).
|
||||
*
|
||||
* This class is used internal to JavaTestKit and should not be extended
|
||||
* by client code directly.
|
||||
*/
|
||||
private[testkit] abstract class CachingPartialFunction[A, B <: AnyRef] extends scala.runtime.AbstractFunction1[A, B] with PartialFunction[A, B] {
|
||||
import akka.japi.JavaPartialFunction._
|
||||
|
||||
def `match`(x: A): B
|
||||
|
||||
var cache: B = _
|
||||
final def isDefinedAt(x: A): Boolean = try { cache = `match`(x); true } catch { case NoMatch ⇒ cache = null.asInstanceOf[B]; false }
|
||||
final def apply(x: A): B = cache
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue