2014-05-28 11:54:28 +02:00
|
|
|
/**
|
2018-01-04 17:26:29 +00:00
|
|
|
* Copyright (C) 2009-2018 Lightbend Inc. <https://www.lightbend.com>
|
2014-05-28 11:54:28 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package akka.persistence
|
|
|
|
|
|
2015-06-24 19:58:43 +02:00
|
|
|
import java.io.{ File, IOException }
|
|
|
|
|
|
|
|
|
|
import akka.actor.{ ActorInitializationException, ActorRef, Props }
|
|
|
|
|
import akka.testkit.{ AkkaSpec, EventFilter, ImplicitSender }
|
2014-05-28 11:54:28 +02:00
|
|
|
|
|
|
|
|
object SnapshotDirectoryFailureSpec {
|
|
|
|
|
val inUseSnapshotPath = "target/inUseSnapshotPath"
|
|
|
|
|
|
2015-06-24 19:58:43 +02:00
|
|
|
class TestPersistentActor(name: String, probe: ActorRef) extends PersistentActor
|
|
|
|
|
with TurnOffRecoverOnStart {
|
2014-05-28 11:54:28 +02:00
|
|
|
|
2014-06-23 14:33:35 +02:00
|
|
|
override def persistenceId: String = name
|
2014-05-28 11:54:28 +02:00
|
|
|
|
2014-12-08 11:02:14 +01:00
|
|
|
override def receiveRecover: Receive = {
|
|
|
|
|
case SnapshotOffer(md, s) ⇒ probe ! ((md, s))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override def receiveCommand = {
|
2014-05-28 11:54:28 +02:00
|
|
|
case s: String ⇒ saveSnapshot(s)
|
|
|
|
|
case SaveSnapshotSuccess(md) ⇒ probe ! md.sequenceNr
|
|
|
|
|
case other ⇒ probe ! other
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SnapshotDirectoryFailureSpec extends AkkaSpec(PersistenceSpec.config("leveldb", "SnapshotDirectoryFailureSpec", extraConfig = Some(
|
|
|
|
|
s"""
|
2014-12-08 11:02:14 +01:00
|
|
|
akka.persistence.snapshot-store.local.dir = "${SnapshotDirectoryFailureSpec.inUseSnapshotPath}"
|
|
|
|
|
"""))) with ImplicitSender {
|
2014-05-28 11:54:28 +02:00
|
|
|
|
|
|
|
|
import SnapshotDirectoryFailureSpec._
|
|
|
|
|
|
|
|
|
|
val file = new File(inUseSnapshotPath)
|
|
|
|
|
|
|
|
|
|
override protected def atStartup() {
|
|
|
|
|
if (!file.createNewFile()) throw new IOException(s"Failed to create test file [${file.getCanonicalFile}]")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override protected def afterTermination() {
|
|
|
|
|
if (!file.delete()) throw new IOException(s"Failed to delete test file [${file.getCanonicalFile}]")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
"A local snapshot store configured with an failing directory name " must {
|
|
|
|
|
"throw an exception at startup" in {
|
|
|
|
|
EventFilter[ActorInitializationException](occurrences = 1).intercept {
|
2014-12-08 11:02:14 +01:00
|
|
|
val p = system.actorOf(Props(classOf[TestPersistentActor], "SnapshotDirectoryFailureSpec-1", testActor))
|
|
|
|
|
p ! "blahonga"
|
2014-05-28 11:54:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|