Skip to content

Commit

Permalink
changed how to handle federation messages in the db
Browse files Browse the repository at this point in the history
  • Loading branch information
onsriahi14 committed Jun 30, 2024
1 parent e6bf5e1 commit b358e61
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
22 changes: 6 additions & 16 deletions be2-scala/src/main/scala/ch/epfl/pop/storage/DbActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -857,15 +857,9 @@ final case class DbActor(

@throws[DbActorNAckException]
private def readFederationMessages(channel: Channel, key: String): Option[Message] = {
channel.extractLaoChannel match {
case Some(mainLaoChannel) =>
storage.read(storage.DATA_KEY + key + channel.toString) match {
case Some(msgId) => read(mainLaoChannel, Hash(Base64Data(msgId)))
case _ => None
}
case _ =>
log.info("Error : Trying to read a federationMessage from an invalid channel")
None
storage.read(storage.DATA_KEY + key + channel.toString) match {
case Some(msgId) => read(channel, Hash(Base64Data(msgId)))
case _ => None
}
}

Expand Down Expand Up @@ -896,14 +890,10 @@ final case class DbActor(

@throws[DbActorNAckException]
private def writeFederationMessages(channel: Channel, key: String, message: Message): Unit = {
channel.extractLaoChannel match {
case Some(mainLaoChannel) =>
createChannel(channel, ObjectType.federation)
storage.write((storage.DATA_KEY + key + channel.toString, message.message_id.toString()))
writeAndPropagate(mainLaoChannel, message)
createChannel(channel, ObjectType.federation)
storage.write((storage.DATA_KEY + key + channel.toString, message.message_id.toString()))
write(channel, message)

case _ => log.info("Error : Trying to write a federationMessage on an invalid channel")
}
}

@throws[DbActorNAckException]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,17 +1195,13 @@ class DbActorSuite extends TestKit(ActorSystem("DbActorSuiteActorSystem")) with

writeAnswer shouldBe a[DbActor.DbActorAck]

val successReadAsk = dbActor ? DbActor.Read(channel.extractLaoChannel.get, message.message_id)
val failingReadAsk = dbActor ? DbActor.Read(channel, message.message_id)
val successReadAsk = dbActor ? DbActor.Read(channel, message.message_id)

val successAnswer = Await.result(successReadAsk, duration)
val failingAnswer = Await.result(failingReadAsk, duration)

val successMessage = successAnswer.asInstanceOf[DbActor.DbActorReadAck].message
val failingMessage = failingAnswer.asInstanceOf[DbActor.DbActorReadAck].message

successMessage should equal(Some(message))
failingMessage should equal(None)
}

test("can read and write a federation message correctly") {
Expand Down

0 comments on commit b358e61

Please sign in to comment.