Fix failing test in CancelWithoutDemandCodecTests
The test started failing after recent commit
e370c15bc6.
See gh-29038
This commit is contained in:
parent
6d5fa89efe
commit
02f61e3aae
|
|
@ -36,7 +36,6 @@ import com.fasterxml.jackson.databind.ObjectWriter;
|
||||||
import com.fasterxml.jackson.databind.SequenceWriter;
|
import com.fasterxml.jackson.databind.SequenceWriter;
|
||||||
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
|
import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
|
||||||
import com.fasterxml.jackson.databind.ser.FilterProvider;
|
import com.fasterxml.jackson.databind.ser.FilterProvider;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.reactivestreams.Publisher;
|
import org.reactivestreams.Publisher;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
@ -182,20 +181,23 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
||||||
// Do not prepend JSON array prefix until first signal is known, onNext vs onError
|
// Do not prepend JSON array prefix until first signal is known, onNext vs onError
|
||||||
// Keeps response not committed for error handling
|
// Keeps response not committed for error handling
|
||||||
|
|
||||||
Flux<DataBuffer> flux1 = helper.getPrefix(bufferFactory, hints, logger)
|
dataBufferFlux = Flux.from(inputStream)
|
||||||
.concatWith(Flux.just(EMPTY_BUFFER).repeat());
|
.map(value -> {
|
||||||
|
byte[] prefix = helper.getPrefix();
|
||||||
|
byte[] delimiter = helper.getDelimiter();
|
||||||
|
|
||||||
Flux<DataBuffer> flux2 = Flux.from(inputStream).map(value -> encodeStreamingValue(
|
DataBuffer dataBuffer = encodeStreamingValue(
|
||||||
value, bufferFactory, hints, sequenceWriter, byteBuilder, helper.getDelimiter(), EMPTY_BYTES));
|
value, bufferFactory, hints, sequenceWriter, byteBuilder, delimiter, EMPTY_BYTES);
|
||||||
|
|
||||||
dataBufferFlux = Flux.zip(flux1, flux2, (buffer1, buffer2) ->
|
return (prefix.length > 0 ?
|
||||||
(buffer1 != EMPTY_BUFFER ?
|
bufferFactory.join(Arrays.asList(bufferFactory.wrap(prefix), dataBuffer)) :
|
||||||
bufferFactory.join(Arrays.asList(buffer1, buffer2)) :
|
dataBuffer);
|
||||||
buffer2))
|
})
|
||||||
.concatWith(helper.getSuffix(bufferFactory, hints, logger));
|
.concatWith(Mono.fromCallable(() -> bufferFactory.wrap(helper.getSuffix())));
|
||||||
}
|
}
|
||||||
|
|
||||||
return dataBufferFlux
|
return dataBufferFlux
|
||||||
|
.doOnNext(dataBuffer -> Hints.touchDataBuffer(dataBuffer, hints, logger))
|
||||||
.doAfterTerminate(() -> {
|
.doAfterTerminate(() -> {
|
||||||
try {
|
try {
|
||||||
byteBuilder.release();
|
byteBuilder.release();
|
||||||
|
|
@ -420,33 +422,22 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple
|
||||||
|
|
||||||
private static final byte[] CLOSE_BRACKET = {']'};
|
private static final byte[] CLOSE_BRACKET = {']'};
|
||||||
|
|
||||||
|
private boolean firstItemEmitted;
|
||||||
private boolean afterFirstItem = false;
|
|
||||||
|
|
||||||
public byte[] getDelimiter() {
|
public byte[] getDelimiter() {
|
||||||
if (this.afterFirstItem) {
|
if (this.firstItemEmitted) {
|
||||||
return COMMA_SEPARATOR;
|
return COMMA_SEPARATOR;
|
||||||
}
|
}
|
||||||
this.afterFirstItem = true;
|
this.firstItemEmitted = true;
|
||||||
return EMPTY_BYTES;
|
return EMPTY_BYTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<DataBuffer> getPrefix(DataBufferFactory factory, @Nullable Map<String, Object> hints, Log logger) {
|
public byte[] getPrefix() {
|
||||||
return wrapBytes(OPEN_BRACKET, factory, hints, logger);
|
return (this.firstItemEmitted ? EMPTY_BYTES : OPEN_BRACKET);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mono<DataBuffer> getSuffix(DataBufferFactory factory, @Nullable Map<String, Object> hints, Log logger) {
|
public byte[] getSuffix() {
|
||||||
return wrapBytes(CLOSE_BRACKET, factory, hints, logger);
|
return CLOSE_BRACKET;
|
||||||
}
|
|
||||||
|
|
||||||
private Mono<DataBuffer> wrapBytes(
|
|
||||||
byte[] bytes, DataBufferFactory bufferFactory, @Nullable Map<String, Object> hints, Log logger) {
|
|
||||||
|
|
||||||
return Mono.fromCallable(() -> {
|
|
||||||
DataBuffer buffer = bufferFactory.wrap(bytes);
|
|
||||||
Hints.touchDataBuffer(buffer, hints, logger);
|
|
||||||
return buffer;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue