=str #19361 migrating ByteStringParserStage to graph stage
This commit is contained in:
parent
3fc332d2c9
commit
07c0da36f2
14 changed files with 184 additions and 267 deletions
|
|
@ -4,10 +4,13 @@
|
|||
|
||||
package akka.http.scaladsl.coding
|
||||
|
||||
import akka.stream.{ Attributes, FlowShape }
|
||||
import akka.stream.impl.fusing.GraphStages.SimpleLinearGraphStage
|
||||
|
||||
import scala.concurrent.duration._
|
||||
import org.scalatest.WordSpec
|
||||
import akka.util.ByteString
|
||||
import akka.stream.stage.{ SyncDirective, Context, PushStage, Stage }
|
||||
import akka.stream.stage._
|
||||
import akka.http.scaladsl.model._
|
||||
import akka.http.impl.util._
|
||||
import headers._
|
||||
|
|
@ -34,10 +37,17 @@ class DecoderSpec extends WordSpec with CodecSpecSupport {
|
|||
case object DummyDecoder extends StreamDecoder {
|
||||
val encoding = HttpEncodings.compress
|
||||
|
||||
def newDecompressorStage(maxBytesPerChunk: Int): () ⇒ Stage[ByteString, ByteString] =
|
||||
() ⇒ new PushStage[ByteString, ByteString] {
|
||||
def onPush(elem: ByteString, ctx: Context[ByteString]): SyncDirective =
|
||||
ctx.push(elem ++ ByteString("compressed"))
|
||||
override def newDecompressorStage(maxBytesPerChunk: Int): () ⇒ GraphStage[FlowShape[ByteString, ByteString]] =
|
||||
() ⇒ new SimpleLinearGraphStage[ByteString] {
|
||||
override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new GraphStageLogic(shape) {
|
||||
setHandler(in, new InHandler {
|
||||
override def onPush(): Unit = push(out, grab(in) ++ ByteString("compressed"))
|
||||
})
|
||||
setHandler(out, new OutHandler {
|
||||
override def onPull(): Unit = pull(in)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ class GzipSpec extends CoderSpec {
|
|||
}
|
||||
"throw an error if compressed data is just missing the trailer at the end" in {
|
||||
def brokenCompress(payload: String) = Gzip.newCompressor.compress(ByteString(payload, "UTF-8"))
|
||||
|
||||
val ex = the[RuntimeException] thrownBy ourDecode(brokenCompress("abcdefghijkl"))
|
||||
ex.getCause.getMessage should equal("Truncated GZIP stream")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue