Skip to content

Commit

Permalink
Remove ReplicatedLog.entriesAfter
Browse files Browse the repository at this point in the history
  • Loading branch information
Taichi Yamakawa committed Jul 13, 2022
1 parent 8d2a50c commit 8a7ee3f
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ private[entityreplication] final case class ReplicatedLog private[model] (
entries.slice(toSeqIndex(from), until = toSeqIndex(to.next()))
}

def entriesAfter(index: LogEntryIndex): Iterator[LogEntry] =
entries.iterator.drop(n = toSeqIndex(index) + 1)

/** Returns the entity's entries with an index greater than or equal to `from` index
*
* If `from` index is greater than [[lastLogIndex]], this method returns empty. If `from` index is less than or equal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,48 +426,6 @@ class ReplicatedLogSpec extends WordSpecLike with Matchers {

}

"ReplicatedLog.entriesAfter" should {

"returns entries with deleted up to the specified LogEntryIndex" in {
val logEntries = Seq(
LogEntry(LogEntryIndex(1), EntityEvent(None, "a"), Term(1)),
LogEntry(LogEntryIndex(2), EntityEvent(None, "b"), Term(1)),
LogEntry(LogEntryIndex(3), EntityEvent(None, "c"), Term(1)),
)

val log = new ReplicatedLog(logEntries)

log.entriesAfter(index = LogEntryIndex.initial()).map(_.event.event).toList shouldBe List("a", "b", "c")
log.entriesAfter(index = LogEntryIndex(1)).map(_.event.event).toList shouldBe List("b", "c")
log.entriesAfter(index = LogEntryIndex(2)).map(_.event.event).toList shouldBe List("c")
log.entriesAfter(index = LogEntryIndex(3)).map(_.event.event).toList shouldBe List()
log.entriesAfter(index = LogEntryIndex(4)).map(_.event.event).toList shouldBe List()
}

"returns entries with deleted up to the specified LogEntryIndex when the log is compressed" in {
val logEntries = Seq(
LogEntry(LogEntryIndex(1), EntityEvent(None, "a"), Term(1)),
LogEntry(LogEntryIndex(2), EntityEvent(None, "b"), Term(1)),
LogEntry(LogEntryIndex(3), EntityEvent(None, "c"), Term(1)),
LogEntry(LogEntryIndex(4), EntityEvent(None, "d"), Term(1)),
LogEntry(LogEntryIndex(5), EntityEvent(None, "e"), Term(1)),
)

val log = new ReplicatedLog(logEntries).deleteOldEntries(to = LogEntryIndex(2), preserveLogSize = 3)
require(log.entries.map(_.index.underlying) == List(3, 4, 5))
require(log.entries.map(_.event.event) == List("c", "d", "e"))

log.entriesAfter(index = LogEntryIndex.initial()).map(_.event.event).toList shouldBe List("c", "d", "e")
log.entriesAfter(index = LogEntryIndex(1)).map(_.event.event).toList shouldBe List("c", "d", "e")
log.entriesAfter(index = LogEntryIndex(2)).map(_.event.event).toList shouldBe List("c", "d", "e")
log.entriesAfter(index = LogEntryIndex(3)).map(_.event.event).toList shouldBe List("d", "e")
log.entriesAfter(index = LogEntryIndex(4)).map(_.event.event).toList shouldBe List("e")
log.entriesAfter(index = LogEntryIndex(5)).map(_.event.event).toList shouldBe List()
log.entriesAfter(index = LogEntryIndex(6)).map(_.event.event).toList shouldBe List()
}

}

"ReplicatedLog.sliceEntityEntries" should {

"return empty if the given `from` is greater than `lastLogIndex`" in {
Expand Down

0 comments on commit 8a7ee3f

Please sign in to comment.