parent
35b4da09dd
commit
630e712b9f
2 changed files with 40 additions and 26 deletions
|
|
@ -153,7 +153,7 @@ class InputStreamSinkSpec extends StreamSpec(UnboundedMailboxConfig) {
|
||||||
an[IllegalArgumentException] shouldBe thrownBy(inputStream.read(buf, -1, 2))
|
an[IllegalArgumentException] shouldBe thrownBy(inputStream.read(buf, -1, 2))
|
||||||
an[IllegalArgumentException] shouldBe thrownBy(inputStream.read(buf, 0, 5))
|
an[IllegalArgumentException] shouldBe thrownBy(inputStream.read(buf, 0, 5))
|
||||||
an[IllegalArgumentException] shouldBe thrownBy(inputStream.read(new Array[Byte](0), 0, 1))
|
an[IllegalArgumentException] shouldBe thrownBy(inputStream.read(new Array[Byte](0), 0, 1))
|
||||||
an[IllegalArgumentException] shouldBe thrownBy(inputStream.read(buf, 0, 0))
|
an[IllegalArgumentException] shouldBe thrownBy(inputStream.read(buf, 0, -1))
|
||||||
inputStream.close()
|
inputStream.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -275,6 +275,18 @@ class InputStreamSinkSpec extends StreamSpec(UnboundedMailboxConfig) {
|
||||||
}
|
}
|
||||||
thrown.getCause should ===(error)
|
thrown.getCause should ===(error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"a read of length 0 should not request bytes from upstream" in assertAllStagesStopped {
|
||||||
|
val (probe, inputStream) = TestSource.probe[ByteString].toMat(StreamConverters.asInputStream())(Keep.both).run()
|
||||||
|
probe.ensureSubscription()
|
||||||
|
probe.expectRequest()
|
||||||
|
|
||||||
|
inputStream.read(new Array[Byte](byteString.size), 0, 0) should ===(0)
|
||||||
|
probe.expectNoMessage()
|
||||||
|
|
||||||
|
inputStream.close()
|
||||||
|
probe.expectCancellation()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -148,9 +148,11 @@ private[stream] object InputStreamSinkStage {
|
||||||
override def read(a: Array[Byte], begin: Int, length: Int): Int = {
|
override def read(a: Array[Byte], begin: Int, length: Int): Int = {
|
||||||
require(a.length > 0, "array size must be >= 0")
|
require(a.length > 0, "array size must be >= 0")
|
||||||
require(begin >= 0, "begin must be >= 0")
|
require(begin >= 0, "begin must be >= 0")
|
||||||
require(length > 0, "length must be > 0")
|
require(length >= 0, "length must be >= 0")
|
||||||
require(begin + length <= a.length, "begin + length must be smaller or equal to the array length")
|
require(begin + length <= a.length, "begin + length must be smaller or equal to the array length")
|
||||||
|
|
||||||
|
if (length == 0) 0
|
||||||
|
else
|
||||||
executeIfNotClosed(() =>
|
executeIfNotClosed(() =>
|
||||||
if (isStageAlive) {
|
if (isStageAlive) {
|
||||||
detachedChunk match {
|
detachedChunk match {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue