throw NoSuchFileException if the file is not there on FileIO.fromPath #24512 (#24513)

* replace deprecated expectNoMsg with expectNoMessage in the test
This commit is contained in:
Roman Filonenko 2018-02-08 09:18:35 +01:00 committed by Konrad `ktoso` Malawski
parent 6012b93c13
commit acf8b1b27b
2 changed files with 12 additions and 9 deletions

View file

@ -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)
}
}

View file

@ -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'")