use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class ChannelSendOperatorTests method errorFromWriteSourceWhileItemCached.
// gh-22720
@Test
public void errorFromWriteSourceWhileItemCached() {
// 1. First item received
// 2. writeFunction applied and writeCompletionBarrier subscribed to it
// 3. Write Publisher fails right after that and before request(n) from server
LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
ZeroDemandSubscriber writeSubscriber = new ZeroDemandSubscriber();
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(Flux.create(sink -> {
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
dataBuffer.write("foo", StandardCharsets.UTF_8);
sink.next(dataBuffer);
sink.error(new IllegalStateException("err"));
}), publisher -> {
publisher.subscribe(writeSubscriber);
return Mono.never();
});
operator.subscribe(new BaseSubscriber<Void>() {
});
try {
// Let cached signals ("foo" and error) be published..
writeSubscriber.signalDemand(1);
} catch (Throwable ex) {
assertThat(ex.getCause()).isNotNull();
assertThat(ex.getCause().getMessage()).isEqualTo("err");
}
bufferFactory.checkForLeaks();
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class ServerHttpResponseTests method writeWithError.
void writeWithError(Publisher<DataBuffer> body) {
TestServerHttpResponse response = new TestServerHttpResponse();
HttpHeaders headers = response.getHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set(HttpHeaders.CONTENT_ENCODING, "gzip");
headers.setContentLength(12);
response.writeWith(body).onErrorResume(ex -> Mono.empty()).block();
assertThat(response.statusCodeWritten).isFalse();
assertThat(response.headersWritten).isFalse();
assertThat(response.cookiesWritten).isFalse();
assertThat(headers).doesNotContainKeys(HttpHeaders.CONTENT_TYPE, HttpHeaders.CONTENT_LENGTH, HttpHeaders.CONTENT_ENCODING);
assertThat(response.body.isEmpty()).isTrue();
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class ListenerWriteProcessorTests method writePublisherError.
// SPR-17410
@Test
public void writePublisherError() {
// Turn off writing so next item will be cached
this.processor.setWritePossible(false);
DataBuffer buffer = mock(DataBuffer.class);
this.processor.onNext(buffer);
// Send error while item cached
this.processor.onError(new IllegalStateException());
assertThat(this.resultSubscriber.getError()).as("Error should flow to result publisher").isNotNull();
assertThat(this.processor.getDiscardedBuffers().size()).isEqualTo(1);
assertThat(this.processor.getDiscardedBuffers().get(0)).isSameAs(buffer);
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class JettyClientHttpConnector method toDataBuffer.
private DataBuffer toDataBuffer(ContentChunk chunk) {
// Originally we copy due to do:
// https://github.com/eclipse/jetty.project/issues/2429
// Now that the issue is marked fixed we need to replace the below with a
// PooledDataBuffer that adapts "release()" to "succeeded()", and also
// evaluate if the concern here is addressed.
DataBuffer buffer = this.bufferFactory.allocateBuffer(chunk.buffer.capacity());
buffer.write(chunk.buffer);
chunk.callback.succeeded();
return buffer;
}
use of org.springframework.core.io.buffer.DataBuffer in project spring-framework by spring-projects.
the class MockClientHttpResponse method setBody.
public void setBody(String body, Charset charset) {
DataBuffer buffer = toDataBuffer(body, charset);
this.body = Flux.just(buffer);
}
Aggregations