Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File: Complete LogRotatorSink when consuming an empty source #1703

Merged
merged 1 commit into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ final private class LogRotatorSink[C, R](triggerGeneratorCreator: () => ByteStri
}
}

override def onUpstreamFinish(): Unit =
override def onUpstreamFinish(): Unit = {
promise.trySuccess(Done)
completeStage()
}

override def onUpstreamFailure(ex: Throwable): Unit =
failThisStage(ex)
Expand Down
13 changes: 13 additions & 0 deletions file/src/test/scala/docs/scaladsl/LogRotatorSinkSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,19 @@ class LogRotatorSinkSpec
val testByteStrings = TestLines.map(ByteString(_))

"LogRotatorSink" must {

"complete when consuming an empty source" in assertAllStagesStopped {
val triggerCreator: () => ByteString => Option[Path] = () => { element: ByteString =>
fail("trigger creator should not be called")
}

val rotatorSink: Sink[ByteString, Future[Done]] =
LogRotatorSink(triggerCreator)

val completion = Source.empty[ByteString].runWith(rotatorSink)
completion.futureValue shouldBe Done
}

"work for size-based rotation " in assertAllStagesStopped {
// #size
import akka.stream.alpakka.file.scaladsl.LogRotatorSink
Expand Down