@Test public void mapRetainsRefcountsForInlineBufferChanges() { ByteStream stream = new ByteStream(Flux.just(buf1, buf2, buf3)); ByteStream mapped = stream.map(buf -> buf); StepVerifier.create(Flux.from(mapped).map(this::decodeUtf8String)) .expectSubscription() .expectNextCount(3) .verifyComplete(); assertThat(buf1.delegate().refCnt(), is(1)); assertThat(buf2.delegate().refCnt(), is(1)); assertThat(buf3.delegate().refCnt(), is(1)); }
@Test public void releasesRefcountForMappedBuffers() { ByteStream stream = new ByteStream(Flux.just(buf1, buf2, buf3)); ByteStream mapped = stream.map(this::toUpperCase); StepVerifier.create(Flux.from(mapped).map(this::decodeUtf8String)) .expectSubscription() .expectNext("A", "B", "C") .verifyComplete(); assertThat(buf1.delegate().refCnt(), is(0)); assertThat(buf2.delegate().refCnt(), is(0)); assertThat(buf3.delegate().refCnt(), is(0)); }
@Test public void mapsContent() { ByteStream stream = new ByteStream(Flux.just(buf1, buf2, buf3)); ByteStream mapped = stream.map(this::toUpperCase); StepVerifier.create(Flux.from(mapped).map(this::decodeUtf8String)) .expectSubscription() .expectNext("A", "B", "C") .verifyComplete(); }
@Test public void responseBodyCannotBeChangedViaStreamingMessage() { HttpResponse original = response(OK) .body("original", UTF_8) .build(); Flux.from(original.stream() .body() .map(buf -> { buf.delegate().array()[0] = 'A'; return buf; })) .subscribe(); assertThat(original.bodyAs(UTF_8), is("original")); }
@Test public void requestBodyCannotBeChangedViaStreamingRequest() { HttpRequest original = HttpRequest.get("/foo") .body("original", UTF_8) .build(); Flux.from(original.stream() .body() .map(buffer -> { buffer.delegate().array()[0] = 'A'; return buffer; })) .subscribe(); assertThat(original.bodyAs(UTF_8), is("original")); }