From acf8b1b27bc365e7aad031f0b3fc9de1b286834c Mon Sep 17 00:00:00 2001 From: Roman Filonenko Date: Thu, 8 Feb 2018 09:18:35 +0100 Subject: [PATCH] throw NoSuchFileException if the file is not there on FileIO.fromPath #24512 (#24513) * replace deprecated expectNoMsg with expectNoMessage in the test --- .../scala/akka/stream/io/FileSourceSpec.scala | 15 +++++++++------ .../scala/akka/stream/impl/io/IOSources.scala | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/akka-stream-tests/src/test/scala/akka/stream/io/FileSourceSpec.scala b/akka-stream-tests/src/test/scala/akka/stream/io/FileSourceSpec.scala index 54b5577f85..77a38a9896 100644 --- a/akka-stream-tests/src/test/scala/akka/stream/io/FileSourceSpec.scala +++ b/akka-stream-tests/src/test/scala/akka/stream/io/FileSourceSpec.scala @@ -4,7 +4,7 @@ package akka.stream.io import java.nio.charset.StandardCharsets.UTF_8 -import java.nio.file.Files +import java.nio.file.{ Files, NoSuchFileException } import java.util.Random import akka.actor.ActorSystem @@ -92,7 +92,7 @@ class FileSourceSpec extends StreamSpec(UnboundedMailboxConfig) { c.expectNext().utf8String should ===(nextChunk().toString) sub.request(1) c.expectNext().utf8String should ===(nextChunk().toString) - c.expectNoMsg(300.millis) + c.expectNoMessage(300.millis) sub.request(200) var expectedChunk = nextChunk().toString @@ -177,11 +177,11 @@ class FileSourceSpec extends StreamSpec(UnboundedMailboxConfig) { sub.request(demandAllButOneChunks) for (i ← 1 to demandAllButOneChunks) c.expectNext().utf8String should ===(nextChunk()) - c.expectNoMsg(300.millis) + c.expectNoMessage(300.millis) sub.request(1) c.expectNext().utf8String should ===(nextChunk()) - c.expectNoMsg(200.millis) + c.expectNoMessage(200.millis) sub.request(1) c.expectNext().utf8String should ===(nextChunk()) @@ -194,7 +194,10 @@ class FileSourceSpec extends StreamSpec(UnboundedMailboxConfig) { p.subscribe(c) c.expectSubscription() - c.expectError() + + val error = c.expectError() + error shouldBe a[NoSuchFileException] + Await.result(r, 3.seconds.dilated).status.isFailure shouldBe true } @@ -248,7 +251,7 @@ class FileSourceSpec extends StreamSpec(UnboundedMailboxConfig) { .runWith(TestSink.probe) .requestNext(ByteString(TestText, UTF_8.name)) .expectComplete() - .expectNoMsg(1.second) + .expectNoMessage(1.second) } } diff --git a/akka-stream/src/main/scala/akka/stream/impl/io/IOSources.scala b/akka-stream/src/main/scala/akka/stream/impl/io/IOSources.scala index 90958ae5d2..a5c7496df6 100644 --- a/akka-stream/src/main/scala/akka/stream/impl/io/IOSources.scala +++ b/akka-stream/src/main/scala/akka/stream/impl/io/IOSources.scala @@ -6,12 +6,11 @@ package akka.stream.impl.io import java.io.InputStream import java.nio.ByteBuffer import java.nio.channels.{ CompletionHandler, FileChannel } -import java.nio.file.{ Files, Path, StandardOpenOption } +import java.nio.file.{ Files, NoSuchFileException, Path, StandardOpenOption } import akka.Done import akka.annotation.InternalApi import akka.stream.Attributes.InputBuffer -import akka.stream.impl.Stages.DefaultAttributes import akka.stream.impl.{ ErrorPublisher, SourceModule } import akka.stream.stage._ import akka.stream.{ IOResult, _ } @@ -70,7 +69,8 @@ private[akka] final class FileSource(path: Path, chunkSize: Int, startPosition: override def preStart(): Unit = { try { // this is a bit weird but required to keep existing semantics - require(Files.exists(path), s"Path '$path' does not exist") + if (!Files.exists(path)) throw new NoSuchFileException(path.toString) + require(Files.isRegularFile(path), s"Path '$path' is not a regular file") require(Files.isReadable(path), s"Missing read permission for '$path'")