From c5fcb6e817ffd6b4509aa156da6337c825c88578 Mon Sep 17 00:00:00 2001 From: pbernet Date: Wed, 22 May 2024 20:03:32 +0200 Subject: [PATCH] Rename --- ...yListener.scala => DirectoryWatcher.scala} | 10 +++---- .../alpakka/file/uploader/Uploader.scala | 2 +- ...rSpec.scala => DirectoryWatcherSpec.scala} | 28 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) rename src/main/scala/alpakka/file/uploader/{DirectoryListener.scala => DirectoryWatcher.scala} (94%) rename src/test/scala/alpakka/file/{DirectoryListenerSpec.scala => DirectoryWatcherSpec.scala} (80%) diff --git a/src/main/scala/alpakka/file/uploader/DirectoryListener.scala b/src/main/scala/alpakka/file/uploader/DirectoryWatcher.scala similarity index 94% rename from src/main/scala/alpakka/file/uploader/DirectoryListener.scala rename to src/main/scala/alpakka/file/uploader/DirectoryWatcher.scala index 4db64fa5..6349dbb8 100644 --- a/src/main/scala/alpakka/file/uploader/DirectoryListener.scala +++ b/src/main/scala/alpakka/file/uploader/DirectoryWatcher.scala @@ -17,7 +17,7 @@ import scala.concurrent.Future * From uploadSourceQueue do a HTTP file upload via [[Uploader]] * Finally move the file to `rootDir/processed` * - * Run with test class: [[DirectoryListenerSpec]] + * Run with test class: [[DirectoryWatcherSpec]] * * Remarks: * - [[FileAlterationListenerAdaptor]] allows to recursively listen to file changes at runtime @@ -25,7 +25,7 @@ import scala.concurrent.Future * https://discuss.lightbend.com/t/using-directorychangessource-recursively/7630 * - Alternative Impl: https://github.com/gmethvin/directory-watcher */ -class DirectoryListener(uploadDir: Path, processedDir: Path) { +class DirectoryWatcher(uploadDir: Path, processedDir: Path) { val logger: Logger = LoggerFactory.getLogger(this.getClass) implicit val system: ActorSystem = ActorSystem() @@ -120,11 +120,11 @@ class DirectoryListener(uploadDir: Path, processedDir: Path) { } def stop(): Future[Terminated] = { - logger.info("About to shutdown DirectoryListener...") + logger.info("About to shutdown DirectoryWatcher...") uploader.stop() } } -object DirectoryListener extends App { - def apply(uploadDir: Path, processedDir: Path) = new DirectoryListener(uploadDir, processedDir) +object DirectoryWatcher extends App { + def apply(uploadDir: Path, processedDir: Path) = new DirectoryWatcher(uploadDir, processedDir) } \ No newline at end of file diff --git a/src/main/scala/alpakka/file/uploader/Uploader.scala b/src/main/scala/alpakka/file/uploader/Uploader.scala index cd2e4988..118a086c 100644 --- a/src/main/scala/alpakka/file/uploader/Uploader.scala +++ b/src/main/scala/alpakka/file/uploader/Uploader.scala @@ -19,7 +19,7 @@ import scala.util.{Failure, Success} /** * Upload file, eg from file system - * Is used by [[DirectoryListener]] + * Is used by [[DirectoryWatcher]] * * Also starts a mock server to handle the uploaded files */ diff --git a/src/test/scala/alpakka/file/DirectoryListenerSpec.scala b/src/test/scala/alpakka/file/DirectoryWatcherSpec.scala similarity index 80% rename from src/test/scala/alpakka/file/DirectoryListenerSpec.scala rename to src/test/scala/alpakka/file/DirectoryWatcherSpec.scala index 79402abf..b8820482 100644 --- a/src/test/scala/alpakka/file/DirectoryListenerSpec.scala +++ b/src/test/scala/alpakka/file/DirectoryWatcherSpec.scala @@ -1,6 +1,6 @@ package alpakka.file -import alpakka.file.uploader.DirectoryListener +import alpakka.file.uploader.DirectoryWatcher import org.apache.commons.io.FileUtils import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AsyncWordSpec @@ -13,35 +13,35 @@ import scala.util.Random /** * Designed as IT test on purpose to demonstrate - * the realistic usage of [[DirectoryListener]], hence we: + * the realistic usage of [[DirectoryWatcher]], hence we: * - copy files to the file system before each test * - clean up after each test * - have a shared listener instance */ -final class DirectoryListenerSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll with BeforeAndAfterEachTestData { +final class DirectoryWatcherSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll with BeforeAndAfterEachTestData { val logger: Logger = LoggerFactory.getLogger(this.getClass) - var listener: DirectoryListener = _ + var listener: DirectoryWatcher = _ var tmpRootDir: Path = _ var parentDir: Path = _ var processedDir: Path = _ - "DirectoryListener" should { + "DirectoryWatcher" should { "detect_files_on_startup" in { - listener = DirectoryListener(parentDir, processedDir) - waitForCondition(2.seconds)(listener.countFilesProcessed() == 2) shouldBe true + listener = DirectoryWatcher(parentDir, processedDir) + waitForCondition(3.seconds)(listener.countFilesProcessed() == 2) shouldBe true } "detect_added_files_at_runtime_in_parent" in { copyTestFileToDir(parentDir) - listener = DirectoryListener(parentDir, processedDir) - waitForCondition(2.seconds)(listener.countFilesProcessed() == 2 + 1) shouldBe true + listener = DirectoryWatcher(parentDir, processedDir) + waitForCondition(3.seconds)(listener.countFilesProcessed() == 2 + 1) shouldBe true } "detect_added_files_at_runtime_in_subdir" in { copyTestFileToDir(parentDir.resolve("subdir")) - listener = DirectoryListener(parentDir, processedDir) - waitForCondition(2.seconds)(listener.countFilesProcessed() == 2 + 1) shouldBe true + listener = DirectoryWatcher(parentDir, processedDir) + waitForCondition(3.seconds)(listener.countFilesProcessed() == 2 + 1) shouldBe true } "detect_added_nested_subdir_at_runtime_with_files_in_subdir" in { @@ -55,8 +55,8 @@ final class DirectoryListenerSpec extends AsyncWordSpec with Matchers with Befor val targetDir = Files.createDirectories(parentDir.resolve("subdir").resolve("nestedDirWithFiles")) FileUtils.copyDirectory(tmpDir.toFile, targetDir.toFile) - listener = DirectoryListener(parentDir, processedDir) - waitForCondition(2.seconds)(listener.countFilesProcessed() == 2 + 2) shouldBe true + listener = DirectoryWatcher(parentDir, processedDir) + waitForCondition(3.seconds)(listener.countFilesProcessed() == 2 + 2) shouldBe true } "handle invalid parent directory path" in { @@ -64,7 +64,7 @@ final class DirectoryListenerSpec extends AsyncWordSpec with Matchers with Befor val processedDir = Files.createTempDirectory("processed") the[IllegalArgumentException] thrownBy { - listener = DirectoryListener(invalidParentDir, processedDir) + listener = DirectoryWatcher(invalidParentDir, processedDir) } should have message s"Invalid upload directory path: $invalidParentDir" } }