Fixed DataBufferUtils.join leak for error in source

This commit fixes an issue where DataBufferUtils.join() would not
release databuffers that preceded an error signal.

Issue: SPR-17025
This commit is contained in:
Arjen Poutsma
2018-09-03 10:10:14 +02:00
parent 3067682347
commit 196c0adf47
2 changed files with 185 additions and 5 deletions

View File

@@ -35,6 +35,7 @@ import io.netty.buffer.ByteBuf;
import org.junit.Test;
import org.mockito.stubbing.Answer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.core.io.ClassPathResource;
@@ -338,12 +339,26 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
DataBuffer bar = stringBuffer("bar");
DataBuffer baz = stringBuffer("baz");
Flux<DataBuffer> flux = Flux.just(foo, bar, baz);
Mono<DataBuffer> result = DataBufferUtils.join(flux);
DataBuffer result = DataBufferUtils.join(flux).block(Duration.ofSeconds(5));
StepVerifier.create(result)
.consumeNextWith(dataBuffer -> {
assertEquals("foobarbaz", DataBufferTestUtils.dumpString(dataBuffer, StandardCharsets.UTF_8));
release(dataBuffer);
})
.verifyComplete();
}
assertEquals("foobarbaz", DataBufferTestUtils.dumpString(result, StandardCharsets.UTF_8));
@Test
public void joinErrors() {
DataBuffer foo = stringBuffer("foo");
DataBuffer bar = stringBuffer("bar");
Flux<DataBuffer> flux = Flux.just(foo, bar).mergeWith(Flux.error(new RuntimeException()));
Mono<DataBuffer> result = DataBufferUtils.join(flux);
release(result);
StepVerifier.create(result)
.expectError(RuntimeException.class)
.verify();
}
}