Skip to content

Commit

Permalink
Make all tests pass with JDK 21
Browse files Browse the repository at this point in the history
Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Sep 22, 2023
1 parent 52167b8 commit 0763363
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
19 changes: 7 additions & 12 deletions utils/src/main/scala/com/reactific/riddl/utils/FileWatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ object FileWatcher {
key: WatchKey,
events: Seq[WatchEvent[?]],
interval: Int
)(onEvents: Seq[WatchEvent[?]] => Boolean
)(notOnEvents: => Boolean
): Unit = {
)(onEvents: Seq[WatchEvent[?]] => Boolean)(notOnEvents: => Boolean): Unit = {
events match {
case x: Seq[WatchEvent[?]] if x.isEmpty =>
if notOnEvents then {
Expand All @@ -67,11 +65,8 @@ object FileWatcher {
path: Path,
periodInSeconds: Int,
intervalInMillis: Int
)(onEvents: Seq[WatchEvent[?]] => Boolean
)(notOnEvents: => Boolean
): Boolean = {
val deadline = Instant.now().plus(periodInSeconds, ChronoUnit.SECONDS)
.toEpochMilli
)(onEvents: Seq[WatchEvent[?]] => Boolean)(notOnEvents: => Boolean): Boolean = {
val deadline = Instant.now().plus(periodInSeconds, ChronoUnit.SECONDS).toEpochMilli
val watchService: WatchService = FileSystems.getDefault.newWatchService()
try {
registerRecursively(path, watchService)
Expand All @@ -81,13 +76,13 @@ object FileWatcher {
case key: WatchKey if key != null =>
saveKey = key
val events = key.pollEvents().asScala.toSeq
handlePolledEvents(key, events, intervalInMillis)(onEvents)(
notOnEvents
)
handlePolledEvents(key, events, intervalInMillis)(onEvents)(notOnEvents)
case _ =>
notOnEvents
}
}
System.currentTimeMillis() < deadline
val current = System.currentTimeMillis()
current < deadline
} finally { watchService.close() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ class FileWatcherTest extends AnyWordSpec with Matchers {
if Files.exists(changeFile) then { Files.delete(changeFile) }
// watch for changes
val f = Future[Boolean] {
FileWatcher.watchForChanges(dir, 2, 10)(onEvents)(notOnEvents)
FileWatcher.watchForChanges(dir, 4, 50)(onEvents)(notOnEvents)
}
Thread.sleep(800)
Files.createFile(changeFile)
Thread.sleep(100)
require(Files.exists(changeFile), "File should exist")
Thread.sleep(200)
val result = Await.result(f, Duration(60, "seconds"))
Files.delete(changeFile)
val result = Await.result(f, Duration(3, "seconds"))
result must be(true)
}
}
Expand Down

0 comments on commit 0763363

Please sign in to comment.