Fix JsonObjectDecoder chunks handling

Issue: SPR-14859
This commit is contained in:
Sebastien Deleuze 2016-10-28 11:25:37 +02:00
parent d59caaa2a7
commit b1030eba3f
2 changed files with 23 additions and 0 deletions

View File

@ -118,6 +118,7 @@ class JsonObjectDecoder extends AbstractDecoder<DataBuffer> {
this.writerIndex = this.input.writerIndex();
}
else {
this.index = this.index - this.input.readerIndex();
this.input = Unpooled.copiedBuffer(this.input,
Unpooled.copiedBuffer(buffer.asByteBuffer()));
DataBufferUtils.release(buffer);

View File

@ -60,6 +60,7 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
@Test
public void decodeSingleChunkToArray() throws InterruptedException {
JsonObjectDecoder decoder = new JsonObjectDecoder();
Flux<DataBuffer> source = Flux.just(stringBuffer(
"[{\"foo\": \"foofoo\", \"bar\": \"barbar\"},{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}]"));
Flux<String> output =
@ -69,11 +70,20 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
.expectNext("{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}")
.expectComplete()
.verify(output);
source = Flux.just(stringBuffer("[{\"foo\": \"bar\"},{\"foo\": \"baz\"}]"));
output = decoder.decode(source, null, null, Collections.emptyMap()).map(JsonObjectDecoderTests::toString);
ScriptedSubscriber.<String>create()
.expectNext("{\"foo\": \"bar\"}")
.expectNext("{\"foo\": \"baz\"}")
.expectComplete()
.verify(output);
}
@Test
public void decodeMultipleChunksToArray() throws InterruptedException {
JsonObjectDecoder decoder = new JsonObjectDecoder();
Flux<DataBuffer> source =
Flux.just(stringBuffer("[{\"foo\": \"foofoo\", \"bar\""), stringBuffer(
": \"barbar\"},{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}]"));
@ -84,6 +94,18 @@ public class JsonObjectDecoderTests extends AbstractDataBufferAllocatingTestCase
.expectNext("{\"foo\": \"foofoofoo\", \"bar\": \"barbarbar\"}")
.expectComplete()
.verify(output);
source = Flux.just(
stringBuffer("[{\"foo\": \""),
stringBuffer("bar\"},{\"fo"),
stringBuffer("o\": \"baz\"}"),
stringBuffer("]"));
output = decoder.decode(source, null, null, Collections.emptyMap()).map(JsonObjectDecoderTests::toString);
ScriptedSubscriber.<String>create()
.expectNext("{\"foo\": \"bar\"}")
.expectNext("{\"foo\": \"baz\"}")
.expectComplete()
.verify(output);
}