Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE2] #1749 Start connection upon start #1764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private class FileMonitor(mediatorRef: ActorRef) extends Runnable {
directory.register(watchService, ENTRY_MODIFY)

override def run(): Unit = {
// Upon start, we connect to the servers
mediatorRef ! ConnectionMediator.ConnectTo(readServerPeers())
try {
while (!Thread.currentThread().isInterrupted) {
// Blocks until an event happen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,38 @@ class MonitorSuite extends TestKit(ActorSystem("MonitorSuiteActorSystem")) with
testProbe.expectMsgType[Monitor.GenerateAndSendHeartbeat](timeout)
}

test("monitor should send ConnectTo() requests to ConnectionMediator upon relevant config file change") {
test("monitor should send a ConnectTo() upon creation") {
val mockConnectionMediator = TestProbe()

// Write to mock server peers config file
val mockConfig = List("mockConfig")
testWriteToServerPeersConfig(mockConfig)

val monitorRef = system.actorOf(Monitor.props(ActorRef.noSender))

// Ping monitor to inform it of ConnectionMediatorRef
mockConnectionMediator.send(monitorRef, ConnectionMediator.Ping())

// Expect first read of the server peers list
mockConnectionMediator.expectMsgType[ConnectionMediator.ConnectTo](timeout)

}

test("monitor should send ConnectTo() requests to ConnectionMediator upon relevant config file change besides first read") {
val mockConnectionMediator = TestProbe()

// Write to mock server peers config file
val mockConfig = List("mockConfig")
testWriteToServerPeersConfig(mockConfig)

val monitorRef = system.actorOf(Monitor.props(ActorRef.noSender))

// Ping monitor to inform it of ConnectionMediatorRef
mockConnectionMediator.send(monitorRef, ConnectionMediator.Ping())

// Expect first read of the server peers list
mockConnectionMediator.expectMsgType[ConnectionMediator.ConnectTo](timeout)

// Expect no message as long as the server peers list is untouched
mockConnectionMediator.expectNoMessage(timeout)

Expand All @@ -121,13 +146,20 @@ class MonitorSuite extends TestKit(ActorSystem("MonitorSuiteActorSystem")) with
mockConnectionMediator.expectMsgType[ConnectionMediator.ConnectTo](timeout)
}

test("monitor should not react upon non relevant events in config directory") {
test("monitor should not react upon non relevant events in config directory besides first read") {
val mockConnectionMediator = TestProbe()
val monitorRef = system.actorOf(Monitor.props(ActorRef.noSender))

// Write to mock server peers config file
val mockConfig = List("mockConfig")
testWriteToServerPeersConfig(mockConfig)

// Ping monitor to inform it of ConnectionMediatorRef
mockConnectionMediator.send(monitorRef, ConnectionMediator.Ping())

// Expect first read of the server peers list
mockConnectionMediator.expectMsgType[ConnectionMediator.ConnectTo](timeout)

// Create new file in the directory
val filePath = Path.of(serverPeersListPath).getParent.toString + File.separator + "DELETE_ME"
val file = new PrintWriter(filePath)
Expand Down
Loading