-
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
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
Modules/Example Replication/jvm/src/test/scala/replication/protocols/VotingTests2.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,44 @@ | ||
package replication.protocols | ||
import rdts.base.Uid | ||
import rdts.datatypes.contextual.ReplicatedSet | ||
import rdts.datatypes.{Epoch, LastWriterWins} | ||
import rdts.syntax.LocalReplicaId | ||
import rdts.time.Dots | ||
import replication.papoctokens.{Vote, Voting} | ||
import replication.papoctokens.Voting.* | ||
|
||
class VotingTests2 extends munit.FunSuite { | ||
given dots: Dots = Dots.empty | ||
// create replicas with for set of 2 participants | ||
val id1: LocalReplicaId = LocalReplicaId.gen() | ||
val id2: LocalReplicaId = LocalReplicaId.gen() | ||
var voting = Voting( | ||
rounds = Epoch.empty[ReplicatedSet[Vote]], | ||
numParticipants = LastWriterWins.now(2) | ||
) | ||
test("No initial owner") { | ||
assert(!voting.isOwner(using id1)) | ||
} | ||
test("Still not owner after one vote"){ | ||
voting = voting.merge(voting.voteFor(id1.uid)(using id1).data) | ||
assert(!voting.isOwner(using id1)) | ||
} | ||
test("Duplicate vote changes nothing"){ | ||
assertEquals(voting.merge(voting.voteFor(id1.uid)(using id1).data), voting) | ||
} | ||
test("Is owner after two votes"){ | ||
voting = voting.merge(voting.voteFor(id1.uid)(using id2).data) | ||
assert(voting.isOwner(using id1)) | ||
assert(!voting.isOwner(using id2)) | ||
} | ||
test("Is not owner for 4 participants"){ | ||
voting = voting.merge(Voting(voting.rounds, LastWriterWins.now(4))) | ||
assert(!voting.isOwner(using id1)) | ||
assert(!voting.isOwner(using id2)) | ||
} | ||
test("Is owner for 3 participants"){ | ||
voting = voting.merge(Voting(voting.rounds, LastWriterWins.now(3))) | ||
assert(voting.isOwner(using id1)) | ||
assert(!voting.isOwner(using id2)) | ||
} | ||
} |