-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test written using akka testing framework for actor message 🔧
- Loading branch information
1 parent
3484b2d
commit d5b7b96
Showing
8 changed files
with
178 additions
and
36 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
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
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,18 @@ | ||
{ | ||
"steps": [ | ||
{ | ||
"dotFilePath": "ExampleNetwork.dot", | ||
"isDirected": false, | ||
"createRing": false, | ||
"createClique": false, | ||
"createBinTree": true, | ||
"enableFailureDetector": true, | ||
"algorithm": "agrawal-elabbadi", | ||
"additionalParameters": { | ||
"initiators": 7, | ||
"additional": 0, | ||
"kill": 1 | ||
} | ||
} | ||
] | ||
} |
88 changes: 88 additions & 0 deletions
88
src/test/scala/com/distcomp/mutex/AgarwalElAbbadiTest.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,88 @@ | ||
package com.distcomp.mutex | ||
|
||
import akka.actor.testkit.typed.scaladsl.ActorTestKit | ||
import com.distcomp.utils.LoggingTestUtils._ | ||
import com.distcomp.utils.SimSetup | ||
import com.typesafe.config.{Config, ConfigFactory} | ||
import org.scalatest.wordspec.AnyWordSpecLike | ||
|
||
import java.io.PrintWriter | ||
|
||
|
||
class AgarwalElAbbadiTest extends AnyWordSpecLike { | ||
val config: Config = ConfigFactory.load("logback-test") | ||
val testKit: ActorTestKit = ActorTestKit("MyTestSystem", config) | ||
|
||
val clearTests: Unit = new PrintWriter("test-logs.txt").close() | ||
val mutexTestFile: String = getClass.getResource("/mutex/AgarAbbadiPlan.json").getPath | ||
|
||
val initiators: Int = SimSetup.getInitiators(mutexTestFile) | ||
|
||
// We will initialize logs once and use it across different tests | ||
lazy val logs: List[String] = SimSetup(mutexTestFile) | ||
|
||
def afterAll(): Unit = { | ||
testKit.shutdownTestKit() | ||
} | ||
|
||
"A simulation" should { | ||
"finish in time and extract logs" in { | ||
// Check if logs are extracted correctly by verifying non-empty and specific content | ||
assert(logs.nonEmpty, "Log file should not be empty") | ||
} | ||
|
||
"have all nodes ready message in logs" in { | ||
// Directly use logs which will be lazily evaluated the first time they are accessed | ||
assert(logs.exists(_.contains("All nodes are ready")), "Logs should contain a ready message") | ||
} | ||
|
||
"have initialisation message in logs" in { | ||
// Directly use logs which will be lazily evaluated the first time they are accessed | ||
assert(logs.exists(_.contains("Setting edges for")), "Logs should contain an initialisation message") | ||
} | ||
|
||
"have failure detector initiated with all heartbeats" in { | ||
assert(logs.exists(_.contains("Received initial heartbeats from all nodes, starting periodic failure check.")), "Logs should contain a message indicating that the failure detector has been initiated with all heartbeats") | ||
} | ||
|
||
"have nodes in binary tree topology" in { | ||
assert(logs.exists(_.contains("Binary Tree Network Topology (Comlete)")), "Logs should contain a message indicating that the nodes are in a binary tree topology") | ||
} | ||
|
||
"have permission grant logs" in { | ||
assert(logs.exists(_.contains("has granted permission")), "Logs should contain a message indicating that permission has been granted") | ||
} | ||
|
||
"have permission denied logs" in { | ||
assert(logs.exists(_.contains("has been denied permission")), "Logs should contain a message indicating that permission has been denied") | ||
} | ||
|
||
"have permission request logs" in { | ||
assert(logs.exists(_.contains("requesting permission")), "Logs should contain a message indicating that permission has been requested") | ||
} | ||
|
||
"have nodes releasing critical section" in { | ||
assert(logs.exists(_.contains("released critical section")), "Logs should contain a message indicating that a node has released the critical section") | ||
} | ||
|
||
"have the correct number of initiators" in { | ||
val initiatorCounts =getInitiatorCounts(logs) | ||
|
||
assert(initiatorCounts == initiators, "Initiator counts should match") | ||
} | ||
|
||
"have the correct nodes entering and exiting" in { | ||
val (initiators, enters, exits) = extractInitiatorsEntersAndExits(logs) | ||
|
||
assert(initiators == enters, "Initiators should match enters") | ||
assert(initiators == exits, "Initiators should match exits") | ||
} | ||
|
||
"have the same node exiting and entering" in { | ||
assert(verifyExitFollowedByEnterSameNode(logs), "Node should exit and enter in the same order") | ||
} | ||
|
||
|
||
} | ||
|
||
} |
24 changes: 0 additions & 24 deletions
24
src/test/scala/com/distcomp/sharedmem/PetersonTwoProcessSMTest.scala
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
src/test/scala/com/distcomp/sharedmemory/PetersonTwoProcessSMTest.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,48 @@ | ||
//#full-example | ||
package com.distcomp.sharedmemory | ||
|
||
import akka.actor.testkit.typed.scaladsl.ScalaTestWithActorTestKit | ||
import com.distcomp.common.Message | ||
import com.distcomp.common.PetersonTwoProcess._ | ||
import com.distcomp.common.PetersonTwoProcess.ReadFlagAndTurnReply | ||
import org.scalatest.wordspec.AnyWordSpecLike | ||
import com.distcomp.utils.DummyNodeActor | ||
|
||
//#definition | ||
class PetersonTwoProcessSMTest extends ScalaTestWithActorTestKit with AnyWordSpecLike { | ||
//#definition | ||
|
||
|
||
|
||
"A PetersonTwoProcSharedMemoryActor" must { | ||
val replyProbe = createTestProbe[Message]() | ||
|
||
val nodeIds: List[Int] = List(1,2) | ||
|
||
val nodeSet = nodeIds.map(id => spawn(DummyNodeActor(), s"Dummy Node $id")).toSet | ||
|
||
val underTest = spawn(PetersonSharedMemActor(nodeSet)) | ||
|
||
//#test | ||
"must reply on read flag and turn" in { | ||
underTest ! ReadFlagAndTurn(replyProbe.ref, nodeSet.head) | ||
replyProbe.expectMessage(ReadFlagAndTurnReply(false, None)) | ||
} | ||
|
||
"must set flag and turn for a node" in { | ||
underTest ! SetFlag(nodeSet.head, true) | ||
underTest ! SetTurn(nodeSet.head) | ||
underTest ! ReadFlagAndTurn(replyProbe.ref, nodeSet.head) | ||
|
||
replyProbe.expectMessage(ReadFlagAndTurnReply(true, Some(nodeSet.head))) | ||
|
||
|
||
} | ||
|
||
|
||
|
||
//#test | ||
} | ||
|
||
} | ||
//#full-example |
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,14 @@ | ||
package com.distcomp.utils | ||
import akka.actor.typed.Behavior | ||
import akka.actor.typed.scaladsl.Behaviors | ||
import com.distcomp.common.Message | ||
|
||
object DummyNodeActor { | ||
|
||
def apply(): Behavior[Message] = { | ||
Behaviors.receiveMessage { | ||
case _ => | ||
Behaviors.same | ||
} | ||
} | ||
} |
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