+str #15588,#17229 Java 6 Synchronous File Sink / Source

These are synchronous implementations, because we need to be Java 6
  compatible while developing on 2.3.x. However asynchronous
  implementations using AsynchronousFileChannel will come soon for JDK7
  users.

+ ActorPublisher/Subscriber now manage stopping of the actor
+ added documentation on configuring dispatcher for File IO
+ properly handle if source file does not exist
+ file sink / source come with default io dispatcher
> verified no actors are leaking
> exceptions are caught and onErrored properly
+ moved files to akka.stream.io
+ Added OutputStreamSink and InputStreamSource
This commit is contained in:
Konrad Malawski 2015-04-16 02:24:01 +02:00
parent a1639c4312
commit cebd9bf1ae
37 changed files with 1581 additions and 86 deletions

View file

@ -0,0 +1,66 @@
/**
* Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com>
*/
package akka.stream.io
import java.io.OutputStream
import akka.stream.scaladsl.Source
import akka.stream.testkit.StreamTestKit._
import akka.stream.testkit.{ AkkaSpec, StreamTestKit }
import akka.stream.{ ActorFlowMaterializer, ActorFlowMaterializerSettings }
import akka.testkit.TestProbe
import akka.util.ByteString
import scala.concurrent.Await
import scala.concurrent.duration._
class OutputStreamSinkSpec extends AkkaSpec(StreamTestKit.UnboundedMailboxConfig) {
val settings = ActorFlowMaterializerSettings(system).withDispatcher("akka.actor.default-dispatcher")
implicit val materializer = ActorFlowMaterializer(settings)
"OutputStreamSink" must {
"write bytes to void OutputStream" in checkThatAllStagesAreStopped {
val p = TestProbe()
val datas = List(ByteString("a"), ByteString("c"), ByteString("c"))
val completion = Source(datas)
.runWith(OutputStreamSink(() new OutputStream {
override def write(i: Int): Unit = ()
override def write(bytes: Array[Byte]): Unit = p.ref ! ByteString(bytes).utf8String
}))
p.expectMsg(datas(0).utf8String)
p.expectMsg(datas(1).utf8String)
p.expectMsg(datas(2).utf8String)
Await.ready(completion, 3.seconds)
}
"close underlying stream when error received" in checkThatAllStagesAreStopped {
val p = TestProbe()
Source.failed(new TE("Boom!"))
.runWith(OutputStreamSink(() new OutputStream {
override def write(i: Int): Unit = ()
override def close() = p.ref ! "closed"
}))
p.expectMsg("closed")
}
"close underlying stream when completion received" in checkThatAllStagesAreStopped {
val p = TestProbe()
Source.empty
.runWith(OutputStreamSink(() new OutputStream {
override def write(i: Int): Unit = ()
override def write(bytes: Array[Byte]): Unit = p.ref ! ByteString(bytes).utf8String
override def close() = p.ref ! "closed"
}))
p.expectMsg("closed")
}
}
}