Merge pull request #18206 from akka/wip-15889-tck-snap-patriknw

=per #15889 Add tck test for save snapshot with same seqNr
This commit is contained in:
Patrik Nordwall 2015-08-13 20:31:47 +02:00
commit 9cb5ff6a26
3 changed files with 24 additions and 17 deletions

View file

@ -77,8 +77,8 @@ abstract class SnapshotStoreSpec(config: Config) extends PluginSpec(config) {
snapshotStore.tell(LoadSnapshot(pid, SnapshotSelectionCriteria.Latest.copy(maxTimestamp = metadata(2).timestamp), 13), senderProbe.ref)
senderProbe.expectMsg(LoadSnapshotResult(Some(SelectedSnapshot(metadata(2), s"s-3")), 13))
}
"delete a single snapshot identified by snapshot metadata" in {
val md = metadata(2)
"delete a single snapshot identified by sequenceNr in snapshot metadata" in {
val md = metadata(2).copy(timestamp = 0L) // don't care about timestamp for delete of single snap
val cmd = DeleteSnapshot(md)
val sub = TestProbe()
@ -87,7 +87,7 @@ abstract class SnapshotStoreSpec(config: Config) extends PluginSpec(config) {
sub.expectMsg(cmd)
senderProbe.expectMsg(DeleteSnapshotSuccess(md))
snapshotStore.tell(LoadSnapshot(pid, SnapshotSelectionCriteria(md.sequenceNr, md.timestamp), Long.MaxValue), senderProbe.ref)
snapshotStore.tell(LoadSnapshot(pid, SnapshotSelectionCriteria(md.sequenceNr), Long.MaxValue), senderProbe.ref)
senderProbe.expectMsg(LoadSnapshotResult(Some(SelectedSnapshot(metadata(1), s"s-2")), Long.MaxValue))
}
"delete all snapshots matching upper sequence number and timestamp bounds" in {
@ -106,5 +106,16 @@ abstract class SnapshotStoreSpec(config: Config) extends PluginSpec(config) {
snapshotStore.tell(LoadSnapshot(pid, SnapshotSelectionCriteria(metadata(3).sequenceNr, metadata(3).timestamp), Long.MaxValue), senderProbe.ref)
senderProbe.expectMsg(LoadSnapshotResult(Some(SelectedSnapshot(metadata(3), s"s-4")), Long.MaxValue))
}
"save and overwrite snapshot with same sequence number" in {
val md = metadata(4)
snapshotStore.tell(SaveSnapshot(md, s"s-5-modified"), senderProbe.ref)
val md2 = senderProbe.expectMsgPF() { case SaveSnapshotSuccess(md2) md2 }
md2.sequenceNr should be(md.sequenceNr)
snapshotStore.tell(LoadSnapshot(pid, SnapshotSelectionCriteria(md.sequenceNr), Long.MaxValue), senderProbe.ref)
val result = senderProbe.expectMsgType[LoadSnapshotResult]
result.snapshot.get.snapshot should be("s-5-modified")
result.snapshot.get.metadata.sequenceNr should be(md.sequenceNr)
// metadata timestamp may have been changed
}
}
}

View file

@ -16,6 +16,16 @@ package akka.persistence
final case class SnapshotMetadata(persistenceId: String, sequenceNr: Long, timestamp: Long = 0L)
//#snapshot-metadata
object SnapshotMetadata {
implicit val ordering: Ordering[SnapshotMetadata] = Ordering.fromLessThan[SnapshotMetadata] { (a, b)
if (a eq b) false
else if (a.persistenceId != b.persistenceId) a.persistenceId.compareTo(b.persistenceId) < 0
else if (a.sequenceNr != b.sequenceNr) a.sequenceNr < b.sequenceNr
else if (a.timestamp != b.timestamp) a.timestamp < b.timestamp
else false
}
}
/**
* Sent to a [[PersistentActor]] after successful saving of a snapshot.
*

View file

@ -1,14 +0,0 @@
/**
* Copyright (C) 2009-2015 Typesafe Inc. <http://www.typesafe.com>
* Copyright (C) 2012-2013 Eligotech BV.
*/
package akka
package object persistence {
implicit val snapshotMetadataOrdering = new Ordering[SnapshotMetadata] {
def compare(x: SnapshotMetadata, y: SnapshotMetadata) =
if (x.persistenceId == y.persistenceId) math.signum(x.sequenceNr - y.sequenceNr).toInt
else x.persistenceId.compareTo(y.persistenceId)
}
}