-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
54 changes: 54 additions & 0 deletions
54
Modules/RDTs/src/test/scala/test/rdts/protocols/simplified/GenPaxosTest.scala
This file contains 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,54 @@ | ||
package test.rdts.protocols.simplified | ||
|
||
import rdts.base.LocalUid | ||
import rdts.datatypes.experiments.protocols.Participants | ||
import rdts.datatypes.experiments.protocols.simplified.GeneralizedPaxos | ||
import rdts.datatypes.experiments.protocols.simplified.GeneralizedPaxos.given | ||
|
||
class GenPaxosTest extends munit.FunSuite { | ||
|
||
val id1 = LocalUid.gen() | ||
val id2 = LocalUid.gen() | ||
val id3 = LocalUid.gen() | ||
|
||
given Participants = Participants(Set(id1, id2, id3).map(_.uid)) | ||
|
||
val emptyPaxosObject: GeneralizedPaxos[Int] = GeneralizedPaxos() | ||
test("write works as expected") { | ||
var testPaxosObject = emptyPaxosObject | ||
val writeValue = 1 | ||
// replica 1 tries to write | ||
testPaxosObject = testPaxosObject.merge(testPaxosObject.write(writeValue)(using id1)) | ||
testPaxosObject = testPaxosObject.merge(testPaxosObject.upkeep()(using id1)).merge(testPaxosObject.upkeep()(using | ||
id2 | ||
)).merge(testPaxosObject.upkeep()(using id3)) | ||
assertEquals(testPaxosObject.read, None) | ||
// replica 1 tries to write again | ||
testPaxosObject = testPaxosObject.merge(testPaxosObject.write(writeValue)(using id1)) | ||
testPaxosObject = testPaxosObject.merge(testPaxosObject.upkeep()(using id1)).merge(testPaxosObject.upkeep()(using | ||
id2 | ||
)).merge(testPaxosObject.upkeep()(using id3)) | ||
assertEquals(testPaxosObject.read, Some(writeValue)) | ||
} | ||
|
||
test("concurrent writes") { | ||
var testPaxosObject = emptyPaxosObject | ||
// replica 1 and 2 try to write | ||
testPaxosObject = | ||
testPaxosObject.merge(testPaxosObject.write(1)(using id1)).merge(testPaxosObject.write(2)(using id2)) | ||
// deliver prepares | ||
testPaxosObject = testPaxosObject.merge(testPaxosObject.upkeep()(using id1)).merge(testPaxosObject.upkeep()(using | ||
id2 | ||
)).merge(testPaxosObject.upkeep()(using id3)) | ||
assertEquals(testPaxosObject.read, None) | ||
// deliver proposal | ||
testPaxosObject = testPaxosObject.merge(testPaxosObject.upkeep()(using id1)).merge(testPaxosObject.upkeep()(using | ||
id2 | ||
)).merge(testPaxosObject.upkeep()(using id3)) | ||
// deliver accepted | ||
testPaxosObject = testPaxosObject.merge(testPaxosObject.upkeep()(using id1)).merge(testPaxosObject.upkeep()(using | ||
id2 | ||
)).merge(testPaxosObject.upkeep()(using id3)) | ||
assert(clue(testPaxosObject.read) == Some(2) || clue(testPaxosObject.read) == Some(1)) | ||
} | ||
} |