2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2019-01-02 18:55:26 +08:00
|
|
|
* Copyright (C) 2009-2019 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 = {
|
2019-02-09 15:25:39 +01:00
|
|
|
case SnapshotOffer(md, s) => probe ! ((md, s))
|
2014-12-08 11:02:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override def receiveCommand = {
|
2019-02-09 15:25:39 +01:00
|
|
|
case s: String => saveSnapshot(s)
|
|
|
|
|
case SaveSnapshotSuccess(md) => probe ! md.sequenceNr
|
|
|
|
|
case other => probe ! other
|
2014-05-28 11:54:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2018-07-25 20:38:27 +09:00
|
|
|
override protected def atStartup(): Unit = {
|
2014-05-28 11:54:28 +02:00
|
|
|
if (!file.createNewFile()) throw new IOException(s"Failed to create test file [${file.getCanonicalFile}]")
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-25 20:38:27 +09:00
|
|
|
override protected def afterTermination(): Unit = {
|
2014-05-28 11:54:28 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|