use of cn.taketoday.core.io.buffer.LeakAwareDataBufferFactory in project today-infrastructure by TAKETODAY.
the class ChannelSendOperatorTests method errorFromWriteFunctionWhileItemCached.
// gh-22720
@Test
public void errorFromWriteFunctionWhileItemCached() {
// 1. First item received
// 2. writeFunction applied and writeCompletionBarrier subscribed to it
// 3. writeFunction fails, e.g. to flush status and headers, before request(n) from server
LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(Flux.create(sink -> {
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
dataBuffer.write("foo", StandardCharsets.UTF_8);
sink.next(dataBuffer);
}), publisher -> {
publisher.subscribe(new ZeroDemandSubscriber());
return Mono.error(new IllegalStateException("err"));
});
StepVerifier.create(operator).expectErrorMessage("err").verify(Duration.ofSeconds(5));
bufferFactory.checkForLeaks();
}
use of cn.taketoday.core.io.buffer.LeakAwareDataBufferFactory in project today-framework by TAKETODAY.
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 cn.taketoday.core.io.buffer.LeakAwareDataBufferFactory in project today-framework by TAKETODAY.
the class ChannelSendOperatorTests method errorFromWriteFunctionWhileItemCached.
// gh-22720
@Test
public void errorFromWriteFunctionWhileItemCached() {
// 1. First item received
// 2. writeFunction applied and writeCompletionBarrier subscribed to it
// 3. writeFunction fails, e.g. to flush status and headers, before request(n) from server
LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(Flux.create(sink -> {
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
dataBuffer.write("foo", StandardCharsets.UTF_8);
sink.next(dataBuffer);
}), publisher -> {
publisher.subscribe(new ZeroDemandSubscriber());
return Mono.error(new IllegalStateException("err"));
});
StepVerifier.create(operator).expectErrorMessage("err").verify(Duration.ofSeconds(5));
bufferFactory.checkForLeaks();
}
use of cn.taketoday.core.io.buffer.LeakAwareDataBufferFactory in project today-framework by TAKETODAY.
the class ChannelSendOperatorTests method cancelWhileItemCached.
// gh-22720
@Test
public void cancelWhileItemCached() {
LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
ChannelSendOperator<DataBuffer> operator = new ChannelSendOperator<>(Mono.fromCallable(() -> {
DataBuffer dataBuffer = bufferFactory.allocateBuffer();
dataBuffer.write("foo", StandardCharsets.UTF_8);
return dataBuffer;
}), publisher -> {
ZeroDemandSubscriber subscriber = new ZeroDemandSubscriber();
publisher.subscribe(subscriber);
return Mono.never();
});
BaseSubscriber<Void> subscriber = new BaseSubscriber<Void>() {
};
operator.subscribe(subscriber);
subscriber.cancel();
bufferFactory.checkForLeaks();
}
use of cn.taketoday.core.io.buffer.LeakAwareDataBufferFactory in project today-framework by TAKETODAY.
the class ServerHttpResponseTests method monoResponseShouldNotLeakIfCancelled.
@Test
// gh-26232
void monoResponseShouldNotLeakIfCancelled() {
LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse(bufferFactory);
response.setWriteHandler(flux -> {
throw AbortedException.beforeSend();
});
HttpMessageWriter<Object> messageWriter = new EncoderHttpMessageWriter<>(new Jackson2JsonEncoder());
Mono<Void> result = messageWriter.write(Mono.just(Collections.singletonMap("foo", "bar")), ResolvableType.fromClass(Mono.class), ResolvableType.fromClass(Map.class), null, request, response, Collections.emptyMap());
StepVerifier.create(result).expectError(AbortedException.class).verify();
bufferFactory.checkForLeaks();
}
Aggregations