Skip to content

Commit

Permalink
make Bottom[LastWriterWins] not overwrite an earlier created value
Browse files Browse the repository at this point in the history
  • Loading branch information
Locke committed Mar 25, 2024
1 parent 4bc3247 commit 4c98fee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ case class LastWriterWins[+A](timestamp: CausalTime, payload: A) {

object LastWriterWins {

def empty[A: Bottom]: LastWriterWins[A] = now(Bottom.empty)
def empty[A: Bottom]: LastWriterWins[A] = LastWriterWins(Bottom[CausalTime].empty, Bottom[A].empty)

def fallback[A](v: A): LastWriterWins[A] =
LastWriterWins(rdts.time.CausalTime(Long.MinValue, 0, CausalTime.countedTime()), v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,17 @@ class LastWriterWinsTest extends munit.FunSuite {
assertEquals(merged.read, "Hello Distributed World")
}

test("newer Bottom does not overwrite an earlier initial value") {
import LastWriterWins.given

val lww1 = LastWriterWins.now("Hello Distributed World")
val lww2 = Bottom[LastWriterWins[String]].empty

assertNotEquals(lww1.timestamp, lww2.timestamp)

val merged = lww1 merge lww2

assertEquals(merged.read, "Hello Distributed World")
}

}

0 comments on commit 4c98fee

Please sign in to comment.