-
Notifications
You must be signed in to change notification settings - Fork 3.6k
=per #15212 Avoid half written snapshots in LocalSnapshotStore #15302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bantonsson
merged 1 commit into
release-2.3
from
wip-15212-make-LocalSnapshotStore-more-robust-ban
May 30, 2014
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
akka-persistence/src/test/scala/akka/persistence/SnapshotFailureRobustnessSpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /** | ||
| * Copyright (C) 2009-2014 Typesafe Inc. <http://www.typesafe.com> | ||
| */ | ||
|
|
||
| package akka.persistence | ||
|
|
||
| import akka.actor.{ Props, ActorRef } | ||
| import akka.testkit.{ TestEvent, EventFilter, ImplicitSender, AkkaSpec } | ||
| import scala.concurrent.duration._ | ||
| import akka.persistence.snapshot.local.LocalSnapshotStore | ||
| import akka.persistence.serialization.Snapshot | ||
| import akka.event.Logging | ||
|
|
||
| import scala.language.postfixOps | ||
|
|
||
| object SnapshotFailureRobustnessSpec { | ||
|
|
||
| class SaveSnapshotTestProcessor(name: String, probe: ActorRef) extends NamedProcessor(name) { | ||
| def receive = { | ||
| case Persistent(payload, snr) ⇒ saveSnapshot(payload) | ||
| case SaveSnapshotSuccess(md) ⇒ probe ! md.sequenceNr | ||
| case SnapshotOffer(md, s) ⇒ probe ! ((md, s)) | ||
| case other ⇒ probe ! other | ||
| } | ||
| } | ||
|
|
||
| class LoadSnapshotTestProcessor(name: String, probe: ActorRef) extends NamedProcessor(name) { | ||
| def receive = { | ||
| case Persistent(payload, snr) ⇒ probe ! s"${payload}-${snr}" | ||
| case SnapshotOffer(md, s) ⇒ probe ! ((md, s)) | ||
| case other ⇒ probe ! other | ||
| } | ||
| override def preStart() = () | ||
| } | ||
|
|
||
| class FailingLocalSnapshotStore extends LocalSnapshotStore { | ||
| override def save(metadata: SnapshotMetadata, snapshot: Any): Unit = { | ||
| if (metadata.sequenceNr == 2) { | ||
| val bytes = "b0rk".getBytes("UTF-8") | ||
| withOutputStream(metadata)(_.write(bytes)) | ||
| } else super.save(metadata, snapshot) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class SnapshotFailureRobustnessSpec extends AkkaSpec(PersistenceSpec.config("leveldb", "SnapshotFailureRobustnessSpec", serialization = "off", extraConfig = Some( | ||
| """ | ||
| |akka.persistence.snapshot-store.local.class = "akka.persistence.SnapshotFailureRobustnessSpec$FailingLocalSnapshotStore" | ||
| """.stripMargin))) with PersistenceSpec with ImplicitSender { | ||
|
|
||
| import SnapshotFailureRobustnessSpec._ | ||
|
|
||
| "A processor with a failing snapshot" must { | ||
| "recover state starting from the most recent complete snapshot" in { | ||
| val sProcessor = system.actorOf(Props(classOf[SaveSnapshotTestProcessor], name, testActor)) | ||
| val processorId = name | ||
|
|
||
| sProcessor ! Persistent("blahonga") | ||
| expectMsg(1) | ||
| sProcessor ! Persistent("kablama") | ||
| expectMsg(2) | ||
| system.eventStream.publish(TestEvent.Mute( | ||
| EventFilter.error(start = "Error loading snapshot ["))) | ||
| system.eventStream.subscribe(testActor, classOf[Logging.Error]) | ||
| try { | ||
| val lProcessor = system.actorOf(Props(classOf[LoadSnapshotTestProcessor], name, testActor)) | ||
| lProcessor ! Recover() | ||
| expectMsgPF() { | ||
| case (SnapshotMetadata(`processorId`, 1, timestamp), state) ⇒ | ||
| state should be("blahonga") | ||
| timestamp should be > (0L) | ||
| } | ||
| expectMsg("kablama-2") | ||
| expectNoMsg(1 second) | ||
| } finally { | ||
| system.eventStream.unsubscribe(testActor, classOf[Logging.Error]) | ||
| system.eventStream.publish(TestEvent.UnMute( | ||
| EventFilter.error(start = "Error loading snapshot ["))) | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good old tmp files :-)