Merge pull request #1906 from akka/wip-3797-persistence-tests-patriknw

=per #3797 Additional hardening of persistence tests
This commit is contained in:
Patrik Nordwall 2013-12-31 07:25:35 -08:00
commit e25455e935
4 changed files with 16 additions and 21 deletions

View file

@ -68,12 +68,7 @@ trait Cleanup { this: AkkaSpec ⇒
}
override protected def afterTermination() {
storageLocations.foreach { dir
if (dir.exists && !FileUtils.deleteQuietly(dir)) {
println(s"Failed to delete [$dir], will try again on exit")
FileUtils.forceDeleteOnExit(dir)
}
}
storageLocations.foreach(FileUtils.deleteDirectory)
}
}

View file

@ -4,6 +4,7 @@
package akka.persistence
import scala.concurrent.duration._
import scala.collection.immutable.Seq
import com.typesafe.config._
@ -146,7 +147,7 @@ abstract class ProcessorSpec(config: Config) extends AkkaSpec(config) with Persi
processor ! Persistent("a")
processor ! Persistent("b")
processor ! GetState
expectMsg(List("a-1", "b-2"))
expectMsg(5.seconds, List("a-1", "b-2"))
}
"A processor" must {

View file

@ -4,6 +4,7 @@
package akka.persistence.journal.leveldb
import scala.concurrent.duration._
import com.typesafe.config.ConfigFactory
import akka.actor._
@ -43,7 +44,7 @@ object SharedLeveldbJournalSpec {
}
}
class ExampleApp(probe: ActorRef, port: Int) extends Actor {
class ExampleApp(probe: ActorRef, storePath: ActorPath) extends Actor {
val processor = context.actorOf(Props(classOf[ExampleProcessor], probe, context.system.name))
def receive = {
@ -52,23 +53,19 @@ object SharedLeveldbJournalSpec {
}
override def preStart(): Unit = {
context.actorSelection(s"akka.tcp://store@127.0.0.1:${port}/user/store") ! Identify(1)
context.actorSelection(storePath) ! Identify(1)
}
}
def port(system: ActorSystem) =
system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress.port.get
}
class SharedLeveldbJournalSpec extends AkkaSpec(SharedLeveldbJournalSpec.config) with Cleanup {
import SharedLeveldbJournalSpec._
val storeSystem = ActorSystem("store", ConfigFactory.parseString(SharedLeveldbJournalSpec.config))
val processorASystem = ActorSystem("processorA", ConfigFactory.parseString(SharedLeveldbJournalSpec.config))
val processorBSystem = ActorSystem("processorB", ConfigFactory.parseString(SharedLeveldbJournalSpec.config))
val processorASystem = ActorSystem("processorA", system.settings.config)
val processorBSystem = ActorSystem("processorB", system.settings.config)
override protected def afterTermination() {
shutdown(storeSystem)
shutdown(processorASystem)
shutdown(processorBSystem)
super.afterTermination()
@ -80,19 +77,20 @@ class SharedLeveldbJournalSpec extends AkkaSpec(SharedLeveldbJournalSpec.config)
val processorAProbe = new TestProbe(processorASystem)
val processorBProbe = new TestProbe(processorBSystem)
storeSystem.actorOf(Props[SharedLeveldbStore], "store")
system.actorOf(Props[SharedLeveldbStore], "store")
val storePath = RootActorPath(system.asInstanceOf[ExtendedActorSystem].provider.getDefaultAddress) / "user" / "store"
val appA = processorASystem.actorOf(Props(classOf[ExampleApp], processorAProbe.ref, port(storeSystem)))
val appB = processorBSystem.actorOf(Props(classOf[ExampleApp], processorBProbe.ref, port(storeSystem)))
val appA = processorASystem.actorOf(Props(classOf[ExampleApp], processorAProbe.ref, storePath))
val appB = processorBSystem.actorOf(Props(classOf[ExampleApp], processorBProbe.ref, storePath))
appA ! Persistent("a1")
appB ! Persistent("b1")
processorAProbe.expectMsg("a1")
processorAProbe.expectMsg(5.seconds, "a1")
processorBProbe.expectMsg("b1")
val recoveredAppA = processorASystem.actorOf(Props(classOf[ExampleApp], processorAProbe.ref, port(storeSystem)))
val recoveredAppB = processorBSystem.actorOf(Props(classOf[ExampleApp], processorBProbe.ref, port(storeSystem)))
val recoveredAppA = processorASystem.actorOf(Props(classOf[ExampleApp], processorAProbe.ref, storePath))
val recoveredAppB = processorBSystem.actorOf(Props(classOf[ExampleApp], processorBProbe.ref, storePath))
recoveredAppA ! Persistent("a2")
recoveredAppB ! Persistent("b2")

View file

@ -284,6 +284,7 @@ object AkkaBuild extends Build {
dependencies = Seq(actor, remote % "test->test", testkit % "test->test"),
settings = defaultSettings ++ formatSettings ++ scaladocSettings ++ experimentalSettings ++ javadocSettings ++ OSGi.persistence ++ Seq(
fork in Test := true,
javaOptions in Test := defaultMultiJvmOptions,
libraryDependencies ++= Dependencies.persistence,
previousArtifact := akkaPreviousArtifact("akka-persistence")
)