<commit_before>package actors

import java.io.{File, IOException}
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.{FileVisitResult, Files, Path, SimpleFileVisitor}

import akka.actor.ActorSystem
import akka.testkit.TestKit
import base.TestBaseDefinition
import org.joda.time.LocalDateTime
import org.scalatest.WordSpecLike
import services.BackupServiceActor

import scala.util.Try

class DbBackupServiceActorSpec extends TestKit(ActorSystem("test_system")) with WordSpecLike with TestBaseDefinition {

  val srcFolder = "lwm_store"
  val destFolder = "db_backup"

  val folders = (for {
    lwm_store <- Try(Files.createDirectory(new File("test/resources", srcFolder).toPath))
    db_backup <- Try(Files.createDirectory(new File(lwm_store.getParent.toString, destFolder).toPath))
    _ <- Try(Files.createFile(new File(lwm_store.toString, "memstore.data").toPath))
  } yield List(lwm_store, db_backup)).getOrElse(List.empty)

  val actorRef = system.actorOf(BackupServiceActor.props(folders.head.toFile, folders.last.toFile))

  "A DbBackupServiceActorSpec " should {

    "successfully backup given store" in {
      import akka.testkit._
      import scala.concurrent.duration._

      10.seconds.dilated

      (0 until 10) foreach { _ => actorRef ! BackupServiceActor.BackupRequest }

      awaitAssert {
        val backups = folders.last.toFile.listFiles()

        backups should not be empty
        backups.find(_.getName.contains(srcFolder)) match {
          case Some(folder) =>
            folder.getAbsolutePath.contains(srcFolder) shouldBe true
            folder.getAbsolutePath.contains(s"${srcFolder}_${LocalDateTime.now.toString("yyyy-MM-dd_HH:mm")}") shouldBe true
            folder.listFiles.nonEmpty shouldBe true
            folder.listFiles.forall(_.getName.endsWith(".data")) shouldBe true

          case None => fail("there should be a least one backup")
        }
      }
    }
  }

  override protected def beforeAll(): Unit = {
    assert(folders.size == 2, "there should be exactly one src and dest folder")
  }

  override protected def afterAll(): Unit = {
    system.terminate

    folders.foreach { p =>
      Files.walkFileTree(p, new SimpleFileVisitor[Path] {
        override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = {
          Files.delete(file)
          FileVisitResult.CONTINUE
        }

        override def postVisitDirectory(dir: Path, exc: IOException): FileVisitResult = {
          Files.delete(dir)
          FileVisitResult.CONTINUE
        }
      })
    }
  }
}<commit_msg>accidentally removed test/resources<commit_after>package actors

import java.io.{File, IOException}
import java.nio.file.attribute.BasicFileAttributes
import java.nio.file.{FileVisitResult, Files, Path, SimpleFileVisitor}

import akka.actor.ActorSystem
import akka.testkit.TestKit
import base.TestBaseDefinition
import org.joda.time.LocalDateTime
import org.scalatest.WordSpecLike
import services.BackupServiceActor

import scala.util.Try

class DbBackupServiceActorSpec extends TestKit(ActorSystem("test_system")) with WordSpecLike with TestBaseDefinition {

  val srcFolder = "lwm_store"
  val destFolder = "db_backup"
  val resources = "test/resources"

  val folders = (for {
    test_resources <- Try(Files.createDirectory(new File(resources).toPath))
    lwm_store <- Try(Files.createDirectory(new File(test_resources.getParent.toString, srcFolder).toPath))
    db_backup <- Try(Files.createDirectory(new File(lwm_store.getParent.toString, destFolder).toPath))
    _ <- Try(Files.createFile(new File(lwm_store.toString, "memstore.data").toPath))
  } yield List(lwm_store, db_backup)).getOrElse(List.empty)

  val actorRef = system.actorOf(BackupServiceActor.props(folders.head.toFile, folders.last.toFile))

  "A DbBackupServiceActorSpec " should {

    "successfully backup given store" in {
      import akka.testkit._
      import scala.concurrent.duration._

      10.seconds.dilated

      (0 until 10) foreach { _ => actorRef ! BackupServiceActor.BackupRequest }

      awaitAssert {
        val backups = folders.last.toFile.listFiles()

        backups should not be empty
        backups.find(_.getName.contains(srcFolder)) match {
          case Some(folder) =>
            folder.getAbsolutePath.contains(srcFolder) shouldBe true
            folder.getAbsolutePath.contains(s"${srcFolder}_${LocalDateTime.now.toString("yyyy-MM-dd_HH:mm")}") shouldBe true
            folder.listFiles.nonEmpty shouldBe true
            folder.listFiles.forall(_.getName.endsWith(".data")) shouldBe true

          case None => fail("there should be a least one backup")
        }
      }
    }
  }

  override protected def beforeAll(): Unit = {
    assert(folders.size == 2, "there should be exactly one src and dest folder")
  }

  override protected def afterAll(): Unit = {
    system.terminate

    folders.+:(new File(resources).toPath).foreach { p =>
      Files.walkFileTree(p, new SimpleFileVisitor[Path] {
        override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = {
          Files.delete(file)
          FileVisitResult.CONTINUE
        }

        override def postVisitDirectory(dir: Path, exc: IOException): FileVisitResult = {
          Files.delete(dir)
          FileVisitResult.CONTINUE
        }
      })
    }
  }
}
{'fraction_non_alphanumeric': 0.1016822429906542, 'fraction_numerical': 0.0022429906542056075, 'mean_word_length': 3.496638655462185, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 11, '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': '2000575', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1539, 'n_words': 327}