From 4c98fee373235b1b87406e621ec883da051c6673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Wolski?= Date: Tue, 5 Mar 2024 12:21:49 +0100 Subject: [PATCH] make Bottom[LastWriterWins] not overwrite an earlier created value --- .../main/scala/rdts/datatypes/LastWriterWins.scala | 2 +- .../test/rdts/bespoke/LastWriterWinsTest.scala | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala b/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala index 1db681de3..99c3f6ea9 100644 --- a/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala +++ b/Modules/RDTs/src/main/scala/rdts/datatypes/LastWriterWins.scala @@ -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) diff --git a/Modules/RDTs/src/test/scala/test/rdts/bespoke/LastWriterWinsTest.scala b/Modules/RDTs/src/test/scala/test/rdts/bespoke/LastWriterWinsTest.scala index a4ae287d9..b3d58a366 100644 --- a/Modules/RDTs/src/test/scala/test/rdts/bespoke/LastWriterWinsTest.scala +++ b/Modules/RDTs/src/test/scala/test/rdts/bespoke/LastWriterWinsTest.scala @@ -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") + } + }