-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finagle-stream: ensure that the HttpDechunker sends EOF only after al…
…l messages Github-issue: twitter/finagle#84 Signed-off-by: marius a. eriksen <marius@twitter.com>
- Loading branch information
1 parent
7722dc9
commit 56a2829
Showing
2 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/scala/com/twitter/finagle/stream/HttpDechunkerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.twitter.finagle.stream | ||
|
||
import org.specs.SpecificationWithJUnit | ||
import com.twitter.finagle.{SunkChannel, SunkChannelFactory} | ||
import org.jboss.netty.buffer.ChannelBuffers | ||
import org.jboss.netty.channel.{Channels, MessageEvent} | ||
import org.jboss.netty.handler.codec.http._ | ||
import com.twitter.conversions.time._ | ||
import java.nio.charset.Charset | ||
|
||
class HttpDechunkerSpec extends SpecificationWithJUnit { | ||
|
||
"HttpDechunker" should { | ||
"wait until last message is synced before sending EOF" in { | ||
val cf = new SunkChannelFactory | ||
val pipeline = Channels.pipeline | ||
val dechunker = new HttpDechunker | ||
pipeline.addLast("dechunker", dechunker) | ||
val channel = new SunkChannel(cf, pipeline, cf.sink) | ||
|
||
val httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK) | ||
httpResponse.setChunked(true) | ||
|
||
Channels.fireMessageReceived(channel, httpResponse) | ||
|
||
val streamResponse = (channel.upstreamEvents.headOption match { | ||
case Some(m: MessageEvent) => m.getMessage match { | ||
case s: StreamResponse => s | ||
} | ||
case _ => throw new Exception("No upstream message received") | ||
}) | ||
|
||
val messages = streamResponse.messages | ||
val error = streamResponse.error | ||
|
||
Channels.fireMessageReceived(channel, new DefaultHttpChunk(ChannelBuffers.wrappedBuffer("1".getBytes))) | ||
messages.sync()(1.second).toString(Charset.defaultCharset) must_== "1" | ||
|
||
Channels.fireMessageReceived(channel, new DefaultHttpChunk(ChannelBuffers.wrappedBuffer("2".getBytes))) | ||
Channels.fireMessageReceived(channel, HttpChunk.LAST_CHUNK) | ||
val receiveError = error.sync() | ||
receiveError.isDefined must_== false | ||
messages.sync()(1.second).toString(Charset.defaultCharset) must_== "2" | ||
receiveError.isDefined must_== true | ||
receiveError(1.second) must_== EOF | ||
} | ||
} | ||
} |