<commit_before>package justin.db

import java.util.UUID

import akka.actor.{Actor, ActorSystem}
import akka.testkit.{TestActorRef, TestKit}
import org.scalatest.{FlatSpecLike, Matchers}
import justin.db.StorageNodeActorProtocol.{StorageNodeReadData, StorageNodeReadingResult}
import org.scalatest.concurrent.ScalaFutures

class RemoteDataReadingServiceTest extends TestKit(ActorSystem("test-system"))
  with FlatSpecLike
  with Matchers
  with ScalaFutures {

  behavior of "Remote Data Reading Service"

  it should "get info back that one of the value could be found and second one is obsolete" in {
    // given
    val service = new RemoteDataReadingService()(system.dispatcher)
    val id = UUID.randomUUID()
    val storageNotFoundActorRef = testActorRef(msgBack = StorageNodeReadingResult.NotFound)
    val storageFoundActorRef    = testActorRef(msgBack = StorageNodeReadingResult.Found(Data(id, "value")))
    val storageNodeRefs         = List(storageNotFoundActorRef, storageFoundActorRef).map(StorageNodeActorRef)

    // when
    val readingResult = service.apply(storageNodeRefs, id)

    // then
    whenReady(readingResult) { _ === List(StorageNodeReadingResult.NotFound, StorageNodeReadingResult.Found(Data(id, "value"))) }
  }

  private def testActorRef(msgBack: StorageNodeReadingResult) = {
    TestActorRef(new Actor {
      override def receive: Receive = {
        case StorageNodeReadData.Local(id) => sender() ! msgBack
      }
    })
  }
}<commit_msg>test scenario of Remote Data Reading Service: "recover failed behavior of actor"<commit_after>package justin.db

import java.util.UUID

import akka.actor.{Actor, ActorSystem}
import akka.testkit.{TestActorRef, TestKit}
import org.scalatest.{FlatSpecLike, Matchers}
import justin.db.StorageNodeActorProtocol.{StorageNodeReadData, StorageNodeReadingResult}
import org.scalatest.concurrent.ScalaFutures

class RemoteDataReadingServiceTest extends TestKit(ActorSystem("test-system"))
  with FlatSpecLike
  with Matchers
  with ScalaFutures {

  behavior of "Remote Data Reading Service"

  it should "get info back that one of the value could be found and second one is obsolete" in {
    // given
    val service = new RemoteDataReadingService()(system.dispatcher)
    val id = UUID.randomUUID()
    val storageNotFoundActorRef = testActorRef(msgBack = StorageNodeReadingResult.NotFound)
    val storageFoundActorRef    = testActorRef(msgBack = StorageNodeReadingResult.Found(Data(id, "value")))
    val storageNodeRefs         = List(storageNotFoundActorRef, storageFoundActorRef).map(StorageNodeActorRef)

    // when
    val readingResult = service.apply(storageNodeRefs, id)

    // then
    whenReady(readingResult) { _ === List(StorageNodeReadingResult.NotFound, StorageNodeReadingResult.Found(Data(id, "value"))) }
  }

  it should "recover failed behavior of actor" in {
    // given
    val service = new RemoteDataReadingService()(system.dispatcher)
    val id = UUID.randomUUID()
    val storageActorRef = testActorRef(new Exception)
    val storageNodeRefs = List(StorageNodeActorRef(storageActorRef))
    // when
    val readingResult = service.apply(storageNodeRefs, id)

    // then
    whenReady(readingResult) { _ shouldBe List(StorageNodeReadingResult.FailedRead) }
  }

  private def testActorRef(msgBack: => Any) = {
    TestActorRef(new Actor {
      override def receive: Receive = {
        case StorageNodeReadData.Local(id) => sender() ! msgBack
      }
    })
  }
}
{'fraction_non_alphanumeric': 0.0886002886002886, 'fraction_numerical': 0.0, 'mean_word_length': 4.501587301587302, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6615638', 'n_tokens_mistral': 1028, 'n_tokens_neox': 991, 'n_words': 239}