2015-11-17 16:50:54 +02:00
|
|
|
/**
|
2016-02-23 12:58:39 +01:00
|
|
|
* Copyright (C) 2009-2016 Lightbend Inc. <http://www.lightbend.com>
|
2015-11-17 16:50:54 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.persistence.journal.leveldb
|
|
|
|
|
|
|
|
|
|
import akka.actor._
|
|
|
|
|
import akka.persistence._
|
|
|
|
|
import akka.persistence.journal.PersistencePluginProxy
|
|
|
|
|
import akka.testkit.{ TestProbe, AkkaSpec }
|
|
|
|
|
import com.typesafe.config.ConfigFactory
|
|
|
|
|
|
|
|
|
|
object PersistencePluginProxySpec {
|
|
|
|
|
lazy val config = ConfigFactory.parseString(
|
|
|
|
|
"""
|
|
|
|
|
akka {
|
|
|
|
|
actor {
|
2016-06-10 15:04:13 +02:00
|
|
|
provider = remote
|
2015-11-17 16:50:54 +02:00
|
|
|
}
|
|
|
|
|
persistence {
|
|
|
|
|
journal {
|
|
|
|
|
plugin = "akka.persistence.journal.proxy"
|
|
|
|
|
proxy.target-journal-plugin = "akka.persistence.journal.inmem"
|
|
|
|
|
}
|
|
|
|
|
snapshot-store {
|
|
|
|
|
plugin = "akka.persistence.snapshot-store.proxy"
|
|
|
|
|
proxy.target-snapshot-store-plugin = "akka.persistence.snapshot-store.local"
|
|
|
|
|
local.dir = target/snapshots-PersistencePluginProxySpec
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
remote {
|
|
|
|
|
enabled-transports = ["akka.remote.netty.tcp"]
|
|
|
|
|
netty.tcp {
|
|
|
|
|
hostname = "127.0.0.1"
|
|
|
|
|
port = 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
loglevel = ERROR
|
|
|
|
|
log-dead-letters = 0
|
|
|
|
|
log-dead-letters-during-shutdown = off
|
|
|
|
|
test.single-expect-default = 10s
|
|
|
|
|
}
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
lazy val startTargetConfig = ConfigFactory.parseString(
|
|
|
|
|
"""
|
|
|
|
|
|akka.extensions = ["akka.persistence.journal.PersistencePluginProxyExtension"]
|
|
|
|
|
|akka.persistence {
|
|
|
|
|
| journal.proxy.start-target-journal = on
|
|
|
|
|
| snapshot-store.proxy.start-target-snapshot-store = on
|
|
|
|
|
|}
|
|
|
|
|
""".stripMargin)
|
|
|
|
|
|
|
|
|
|
def targetAddressConfig(system: ActorSystem) = ConfigFactory.parseString(
|
|
|
|
|
s"""
|
2015-12-23 13:46:50 +02:00
|
|
|
|akka.extensions = ["akka.persistence.Persistence"]
|
|
|
|
|
|akka.persistence.journal.auto-start-journals = [""]
|
2015-11-17 16:50:54 +02:00
|
|
|
|akka.persistence.journal.proxy.target-journal-address = "${system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress}"
|
|
|
|
|
|akka.persistence.snapshot-store.proxy.target-snapshot-store-address = "${system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress}"
|
|
|
|
|
""".stripMargin)
|
|
|
|
|
|
|
|
|
|
class ExamplePersistentActor(probe: ActorRef, name: String) extends NamedPersistentActor(name) {
|
|
|
|
|
override def receiveRecover = {
|
|
|
|
|
case RecoveryCompleted ⇒ // ignore
|
|
|
|
|
case payload ⇒
|
|
|
|
|
probe ! payload
|
|
|
|
|
}
|
|
|
|
|
override def receiveCommand = {
|
|
|
|
|
case payload ⇒
|
|
|
|
|
persist(payload) { _ ⇒
|
|
|
|
|
probe ! payload
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ExampleApp(probe: ActorRef) extends Actor {
|
|
|
|
|
val p = context.actorOf(Props(classOf[ExamplePersistentActor], probe, context.system.name))
|
|
|
|
|
|
|
|
|
|
def receive = {
|
|
|
|
|
case m ⇒ p forward m
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class PersistencePluginProxySpec extends AkkaSpec(PersistencePluginProxySpec.startTargetConfig withFallback PersistencePluginProxySpec.config) with Cleanup {
|
|
|
|
|
import PersistencePluginProxySpec._
|
|
|
|
|
|
|
|
|
|
val systemA = ActorSystem("SysA", config)
|
|
|
|
|
val systemB = ActorSystem("SysB", targetAddressConfig(system) withFallback PersistencePluginProxySpec.config)
|
|
|
|
|
|
|
|
|
|
override protected def afterTermination() {
|
|
|
|
|
shutdown(systemA)
|
|
|
|
|
shutdown(systemB)
|
|
|
|
|
super.afterTermination()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"A persistence proxy" can {
|
|
|
|
|
"be shared by multiple actor systems" in {
|
|
|
|
|
|
|
|
|
|
val address = system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress
|
|
|
|
|
|
|
|
|
|
val probeA = new TestProbe(systemA)
|
|
|
|
|
val probeB = new TestProbe(systemB)
|
|
|
|
|
|
|
|
|
|
PersistencePluginProxy.setTargetLocation(systemA, address)
|
|
|
|
|
|
|
|
|
|
val appA = systemA.actorOf(Props(classOf[ExampleApp], probeA.ref))
|
|
|
|
|
val appB = systemB.actorOf(Props(classOf[ExampleApp], probeB.ref))
|
|
|
|
|
|
|
|
|
|
appA ! "a1"
|
|
|
|
|
appB ! "b1"
|
|
|
|
|
|
|
|
|
|
probeA.expectMsg("a1")
|
|
|
|
|
probeB.expectMsg("b1")
|
|
|
|
|
|
|
|
|
|
val recoveredAppA = systemA.actorOf(Props(classOf[ExampleApp], probeA.ref))
|
|
|
|
|
val recoveredAppB = systemB.actorOf(Props(classOf[ExampleApp], probeB.ref))
|
|
|
|
|
|
|
|
|
|
recoveredAppA ! "a2"
|
|
|
|
|
recoveredAppB ! "b2"
|
|
|
|
|
|
|
|
|
|
probeA.expectMsg("a1")
|
|
|
|
|
probeA.expectMsg("a2")
|
|
|
|
|
|
|
|
|
|
probeB.expectMsg("b1")
|
|
|
|
|
probeB.expectMsg("b2")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|