+per #16541 initial version of the Persistence Query module
This commit is contained in:
parent
09aff42d40
commit
f849793f36
23 changed files with 1051 additions and 14 deletions
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
|
||||
*/
|
||||
|
||||
package akka.persistence.query
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import akka.persistence.journal.{ EventAdapter, EventSeq }
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import org.scalatest.{ BeforeAndAfterAll, Matchers, WordSpecLike }
|
||||
import org.scalautils.ConversionCheckedTripleEquals
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
class PersistenceQuerySpec extends WordSpecLike with Matchers with BeforeAndAfterAll with ConversionCheckedTripleEquals {
|
||||
|
||||
val anything: Query[String, _] = null
|
||||
|
||||
val eventAdaptersConfig =
|
||||
s"""
|
||||
|akka.persistence.query.journal.mock {
|
||||
| event-adapters {
|
||||
| adapt = ${classOf[PrefixStringWithPAdapter].getCanonicalName}
|
||||
| }
|
||||
|}
|
||||
""".stripMargin
|
||||
|
||||
"ReadJournal" must {
|
||||
"be found by full config key" in {
|
||||
withActorSystem() { system ⇒
|
||||
PersistenceQuery.get(system).readJournalFor(MockReadJournal.Identifier)
|
||||
}
|
||||
}
|
||||
|
||||
"throw if unable to find query journal by config key" in {
|
||||
withActorSystem() { system ⇒
|
||||
intercept[IllegalArgumentException] {
|
||||
PersistenceQuery.get(system).readJournalFor(MockReadJournal.Identifier + "-unknown")
|
||||
}.getMessage should include("missing persistence read journal")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val systemCounter = new AtomicInteger()
|
||||
private def withActorSystem(conf: String = "")(block: ActorSystem ⇒ Unit): Unit = {
|
||||
val config =
|
||||
MockReadJournal.config
|
||||
.withFallback(ConfigFactory.parseString(conf))
|
||||
.withFallback(ConfigFactory.parseString(eventAdaptersConfig))
|
||||
.withFallback(ConfigFactory.load())
|
||||
|
||||
val sys = ActorSystem(s"sys-${systemCounter.incrementAndGet()}", config)
|
||||
try block(sys) finally Await.ready(sys.terminate(), 10.seconds)
|
||||
}
|
||||
}
|
||||
|
||||
object ExampleQueryModels {
|
||||
case class OldModel(value: String) { def promote = NewModel(value) }
|
||||
case class NewModel(value: String)
|
||||
}
|
||||
|
||||
class PrefixStringWithPAdapter extends EventAdapter {
|
||||
override def fromJournal(event: Any, manifest: String) = EventSeq.single("p-" + event)
|
||||
|
||||
override def manifest(event: Any) = ""
|
||||
override def toJournal(event: Any) = throw new Exception("toJournal should not be called by query side")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue