Skip to content

Commit

Permalink
Bump versions and beautify
Browse files Browse the repository at this point in the history
  • Loading branch information
pbernet committed May 23, 2024
1 parent 3fb5ea2 commit c0fcf10
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ libraryDependencies ++= Seq(
"io.zonky.test.postgres" % "embedded-postgres-binaries-bom" % "15.4.0" % Test pomOnly(),
"io.zonky.test" % "embedded-postgres" % "2.0.4" % Test,

"org.scalatest" %% "scalatest" % "3.2.15" % Test,
"org.scalatest" %% "scalatest" % "3.2.18" % Test,
"org.apache.pekko" %% "pekko-testkit" % pekkoVersion % Test,
"org.assertj" % "assertj-core" % "3.24.2" % Test
"org.assertj" % "assertj-core" % "3.25.3" % Test
)

resolvers += "repository.jboss.org-public" at "https://repository.jboss.org/nexus/content/groups/public"
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/alpakka/file/uploader/Uploader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ class Uploader(system: ActorSystem) {

def stop(): Future[Terminated] = {
logger.info("About to shutdown Uploader...")
val fut = serverBinding.map(serverBinding => serverBinding.terminate(hardDeadline = 3.seconds))
val fut = serverBinding.map(serverBinding => serverBinding.terminate(hardDeadline = 2.seconds))
logger.info("Waiting for connections to terminate...")
val onceAllConnectionsTerminated = Await.result(fut, 10.seconds)
val onceAllConnectionsTerminated = Await.result(fut, 3.seconds)
logger.info("Connections terminated")
onceAllConnectionsTerminated.flatMap(_ => system.terminate())
}
Expand Down
24 changes: 16 additions & 8 deletions src/test/scala/alpakka/file/DirectoryWatcherSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import scala.util.Random

/**
* Designed as IT test on purpose to demonstrate
* the realistic usage of [[DirectoryWatcher]], hence we:
* - create dir structure and copy files before each test
* - clean up files after each test
* - use a shared watcher instance
* - waitForCondition with Thread.sleep()
* the realistic usage of [[DirectoryWatcher]]
* Hence we:
* - create the dir structure and copy files before each test
* - clean up dir structure after each test
* - use a shared watcher instance for all tests
*/
final class DirectoryWatcherSpec extends AsyncWordSpec with Matchers with BeforeAndAfterAll with BeforeAndAfterEachTestData {
val logger: Logger = LoggerFactory.getLogger(this.getClass)
Expand Down Expand Up @@ -75,7 +75,7 @@ final class DirectoryWatcherSpec extends AsyncWordSpec with Matchers with Before
logger.info(s"Starting test: ${testData.name}")

tmpRootDir = Files.createTempDirectory(testData.text)
logger.info(s"Created tmp dir: $tmpRootDir")
logger.info(s"Created tmp root dir: $tmpRootDir")

uploadDir = tmpRootDir.resolve("upload")
processedDir = tmpRootDir.resolve("processed")
Expand All @@ -90,8 +90,9 @@ final class DirectoryWatcherSpec extends AsyncWordSpec with Matchers with Before

override protected def afterEach(testData: TestData): Unit = {
logger.info(s"Cleaning up after test: ${testData.name}")
Await.result(watcher.stop(), 5.seconds)
if (watcher != null) Await.result(watcher.stop(), 5.seconds)
FileUtils.deleteDirectory(tmpRootDir.toFile)
logger.info(s"Finished test: ${testData.name}")
}

private def copyTestFileToDir(target: Path) = {
Expand All @@ -106,7 +107,14 @@ final class DirectoryWatcherSpec extends AsyncWordSpec with Matchers with Before
}

private def waitForCondition(maxDuration: FiniteDuration)(condition: => Boolean): Boolean = {
Thread.sleep(maxDuration.toMillis)
val startTime = System.currentTimeMillis()
var elapsed = 0.millis

while (!condition && elapsed < maxDuration) {
Thread.sleep(100)
elapsed = (System.currentTimeMillis() - startTime).millis
}
logger.info("Condition reached after: {} ms", elapsed.toMillis)
condition
}
}

0 comments on commit c0fcf10

Please sign in to comment.