Complete unfinished ConsistentHashingRouterDocSpec, see #944
This commit is contained in:
parent
48d8a09075
commit
50fc5a03a2
3 changed files with 24 additions and 11 deletions
|
|
@ -19,7 +19,7 @@ object ConsistentHashingRouterDocSpec {
|
|||
def receive = {
|
||||
case Entry(key, value) ⇒ cache += (key -> value)
|
||||
case Get(key) ⇒ sender ! cache.get(key)
|
||||
case Evict(key) => cache -= key
|
||||
case Evict(key) ⇒ cache -= key
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -30,10 +30,6 @@ object ConsistentHashingRouterDocSpec {
|
|||
}
|
||||
|
||||
case class Entry(key: String, value: String)
|
||||
case class EntryEnvelope(entry: Entry) extends ConsistentHashableEnvelope {
|
||||
override def consistentHashKey: Any = entry.key
|
||||
override def message: Any = entry
|
||||
}
|
||||
//#cache-actor
|
||||
|
||||
}
|
||||
|
|
@ -47,16 +43,31 @@ class ConsistentHashingRouterDocSpec extends AkkaSpec with ImplicitSender {
|
|||
//#consistent-hashing-router
|
||||
import akka.actor.Props
|
||||
import akka.routing.ConsistentHashingRouter
|
||||
import akka.routing.ConsistentHashingRouter.ConsistentHashRoute
|
||||
import akka.routing.ConsistentHashingRouter.ConsistentHashableEnvelope
|
||||
|
||||
val cache = system.actorOf(Props[Cache].withRouter(ConsistentHashingRouter(10)), "cache")
|
||||
def consistentHashRoute: ConsistentHashingRouter.ConsistentHashRoute = {
|
||||
case Evict(key) ⇒ key
|
||||
}
|
||||
|
||||
cache ! EntryEnvelope(Entry("hello", "HELLO"))
|
||||
cache ! EntryEnvelope(Entry("hi", "HI"))
|
||||
val cache = system.actorOf(Props[Cache].withRouter(ConsistentHashingRouter(10,
|
||||
consistentHashRoute = consistentHashRoute)), name = "cache")
|
||||
|
||||
cache ! ConsistentHashableEnvelope(
|
||||
message = Entry("hello", "HELLO"), consistentHashKey = "hello")
|
||||
cache ! ConsistentHashableEnvelope(
|
||||
message = Entry("hi", "HI"), consistentHashKey = "hi")
|
||||
|
||||
cache ! Get("hello")
|
||||
cache ! Get("hi")
|
||||
expectMsg(Some("HELLO"))
|
||||
|
||||
cache ! Get("hi")
|
||||
expectMsg(Some("HI"))
|
||||
|
||||
cache ! Evict("hi")
|
||||
cache ! Get("hi")
|
||||
expectMsg(None)
|
||||
|
||||
//#consistent-hashing-router
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue