use of io.servicetalk.concurrent.CompletableSource.Processor in project servicetalk by apple.
the class CompletableProcessorBenchmark method stAdd20Complete.
@Benchmark
public void stAdd20Complete() throws InterruptedException {
Processor processor = newCompletableProcessor();
final int subscribers = 20;
CountDownLatch latch = new CountDownLatch(subscribers);
TerminateCountDownSubscriber subscriber = new TerminateCountDownSubscriber(latch);
for (int i = 0; i < subscribers; ++i) {
processor.subscribe(subscriber);
}
processor.onComplete();
latch.await();
}
use of io.servicetalk.concurrent.CompletableSource.Processor in project servicetalk by apple.
the class CompletableProcessorBenchmark method stAdd3Complete.
@Benchmark
public void stAdd3Complete() throws InterruptedException {
Processor processor = newCompletableProcessor();
CountDownLatch latch = new CountDownLatch(3);
TerminateCountDownSubscriber subscriber = new TerminateCountDownSubscriber(latch);
processor.subscribe(subscriber);
processor.subscribe(subscriber);
processor.subscribe(subscriber);
processor.onComplete();
latch.await();
}
use of io.servicetalk.concurrent.CompletableSource.Processor in project servicetalk by apple.
the class CompletableProcessorBenchmark method mtAdd3Complete.
@Benchmark
public void mtAdd3Complete() throws InterruptedException {
Processor processor = newCompletableProcessor();
CountDownLatch latch = new CountDownLatch(3);
TerminateCountDownSubscriber subscriber = new TerminateCountDownSubscriber(latch);
// execute before to race with subscribe
executorService.execute(processor::onComplete);
processor.subscribe(subscriber);
processor.subscribe(subscriber);
processor.subscribe(subscriber);
latch.await();
}
use of io.servicetalk.concurrent.CompletableSource.Processor in project servicetalk by apple.
the class HttpRequestEncoderTest method protocolPayloadEndOutboundShouldNotTriggerOnFailedFlush.
@Test
void protocolPayloadEndOutboundShouldNotTriggerOnFailedFlush() throws Exception {
AtomicReference<CloseHandler> closeHandlerRef = new AtomicReference<>();
try (CompositeCloseable resources = newCompositeCloseable()) {
Processor serverCloseTrigger = newCompletableProcessor();
CountDownLatch serverChannelLatch = new CountDownLatch(1);
AtomicReference<Channel> serverChannelRef = new AtomicReference<>();
ReadOnlyTcpServerConfig sConfig = new TcpServerConfig().asReadOnly();
ServerContext serverContext = resources.prepend(TcpServerBinder.bind(localAddress(0), sConfig, false, SEC, null, (channel, observer) -> DefaultNettyConnection.initChannel(channel, SEC.bufferAllocator(), SEC.executor(), SEC.ioExecutor(), forPipelinedRequestResponse(false, channel.config()), defaultFlushStrategy(), null, new TcpServerChannelInitializer(sConfig, observer).andThen(channel2 -> {
serverChannelRef.compareAndSet(null, channel2);
serverChannelLatch.countDown();
}), defaultStrategy(), mock(Protocol.class), observer, false, __ -> false), connection -> {
}).toFuture().get());
ReadOnlyHttpClientConfig cConfig = new HttpClientConfig().asReadOnly();
assert cConfig.h1Config() != null;
NettyConnection<Object, Object> conn = resources.prepend(TcpConnector.connect(null, serverHostAndPort(serverContext), cConfig.tcpConfig(), false, CEC, (channel, connectionObserver) -> {
CloseHandler closeHandler = spy(forPipelinedRequestResponse(true, channel.config()));
closeHandlerRef.compareAndSet(null, closeHandler);
return DefaultNettyConnection.initChannel(channel, CEC.bufferAllocator(), CEC.executor(), CEC.ioExecutor(), closeHandler, defaultFlushStrategy(), null, new TcpClientChannelInitializer(cConfig.tcpConfig(), connectionObserver).andThen(new HttpClientChannelInitializer(getByteBufAllocator(CEC.bufferAllocator()), cConfig.h1Config(), closeHandler)).andThen(channel2 -> channel2.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
// Propagate the user event in the pipeline before
// triggering the test condition.
ctx.fireUserEventTriggered(evt);
if (evt instanceof ChannelInputShutdownReadComplete) {
serverCloseTrigger.onComplete();
}
}
})), defaultStrategy(), HTTP_1_1, connectionObserver, true, __ -> false);
}, NoopTransportObserver.INSTANCE).toFuture().get());
// The server needs to wait to close the conneciton until after the client has established the connection.
serverChannelLatch.await();
Channel serverChannel = serverChannelRef.get();
assertNotNull(serverChannel);
assumeFalse(serverChannel instanceof NioSocketChannel, "Windows doesn't emit ChannelInputShutdownReadComplete. Investigation Required.");
((SocketChannel) serverChannel).config().setSoLinger(0);
// Close and send RST concurrently with client write
serverChannel.close();
StreamingHttpRequest request = reqRespFactory.post("/closeme");
fromSource(serverCloseTrigger).toFuture().get();
Completable write = conn.write(from(request, allocator.fromAscii("Bye"), EmptyHttpHeaders.INSTANCE));
assertThrows(ExecutionException.class, () -> write.toFuture().get());
CloseHandler closeHandler = closeHandlerRef.get();
assertNotNull(closeHandler);
verify(closeHandler, never()).protocolPayloadEndOutbound(any(), any());
}
}
use of io.servicetalk.concurrent.CompletableSource.Processor in project servicetalk by apple.
the class WriteStreamSubscriberOutOfEventloopTest method testTerminalOrder.
@Test
void testTerminalOrder() throws Exception {
Processor subject = newCompletableProcessor();
CompletableSource.Subscriber subscriber = new CompletableSource.Subscriber() {
@Override
public void onSubscribe(Cancellable cancellable) {
// noop
}
@Override
public void onComplete() {
subject.onComplete();
}
@Override
public void onError(Throwable t) {
if (pendingFlush.contains(1)) {
subject.onError(t);
} else {
subject.onError(new IllegalStateException("The expected object wasn't written before termination!", t));
}
}
};
WriteDemandEstimator demandEstimator = mock(WriteDemandEstimator.class);
this.subscriber = new WriteStreamSubscriber(channel, demandEstimator, subscriber, UNSUPPORTED_PROTOCOL_CLOSE_HANDLER, NoopWriteObserver.INSTANCE, identity(), false, __ -> false);
this.subscriber.onNext(1);
this.subscriber.onError(DELIBERATE_EXCEPTION);
try {
fromSource(subject).toFuture().get();
fail();
} catch (ExecutionException cause) {
assertSame(DELIBERATE_EXCEPTION, cause.getCause());
}
}
Aggregations