use of io.servicetalk.transport.netty.internal.CloseHandler.UNSUPPORTED_PROTOCOL_CLOSE_HANDLER 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());
}
}
use of io.servicetalk.transport.netty.internal.CloseHandler.UNSUPPORTED_PROTOCOL_CLOSE_HANDLER in project servicetalk by apple.
the class TcpConnectorTest method testRegisteredAndActiveEventsFired.
@Test
void testRegisteredAndActiveEventsFired() throws Exception {
final CountDownLatch registeredLatch = new CountDownLatch(1);
final CountDownLatch activeLatch = new CountDownLatch(1);
CloseHandler closeHandler = UNSUPPORTED_PROTOCOL_CLOSE_HANDLER;
NettyConnection<Buffer, Buffer> connection = TcpConnector.<NettyConnection<Buffer, Buffer>>connect(null, serverContext.listenAddress(), new TcpClientConfig().asReadOnly(), false, CLIENT_CTX, (channel, connectionObserver) -> DefaultNettyConnection.initChannel(channel, CLIENT_CTX.bufferAllocator(), CLIENT_CTX.executor(), CLIENT_CTX.ioExecutor(), closeHandler, defaultFlushStrategy(), null, channel2 -> channel2.pipeline().addLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelRegistered(ChannelHandlerContext ctx) {
registeredLatch.countDown();
ctx.fireChannelRegistered();
}
@Override
public void channelActive(ChannelHandlerContext ctx) {
activeLatch.countDown();
ctx.fireChannelActive();
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
ctx.fireChannelRead(msg);
closeHandler.protocolPayloadEndInbound(ctx);
}
}), CLIENT_CTX.executionStrategy(), mock(Protocol.class), connectionObserver, true, __ -> false), NoopTransportObserver.INSTANCE).toFuture().get();
connection.closeAsync().toFuture().get();
registeredLatch.await();
activeLatch.await();
}
use of io.servicetalk.transport.netty.internal.CloseHandler.UNSUPPORTED_PROTOCOL_CLOSE_HANDLER in project servicetalk by apple.
the class WriteStreamSubscriberFutureListenersTest method synchronousCompleteWrite.
@Test
void synchronousCompleteWrite() throws Exception {
Channel mockChannel = mock(Channel.class);
EventLoop mockEventLoop = mock(EventLoop.class);
when(mockEventLoop.inEventLoop()).thenReturn(true);
when(mockChannel.eventLoop()).thenReturn(mockEventLoop);
when(mockChannel.newSucceededFuture()).thenReturn(channel.newSucceededFuture());
doAnswer((Answer<Void>) invocation -> {
ReferenceCountUtil.release(invocation.getArgument(0));
ChannelFutureListener listener = mock(ChannelFutureListener.class);
listeners.add(listener);
ChannelPromise promise = invocation.getArgument(1);
promise.addListener(listener);
promise.setSuccess();
return null;
}).when(mockChannel).write(any(), any());
WriteDemandEstimator estimator = WriteDemandEstimators.newDefaultEstimator();
TestCompletableSubscriber completableSubscriber = new TestCompletableSubscriber();
WriteStreamSubscriber subscriber = new WriteStreamSubscriber(mockChannel, estimator, completableSubscriber, UNSUPPORTED_PROTOCOL_CLOSE_HANDLER, NoopWriteObserver.INSTANCE, identity(), false, __ -> false);
subscriber.onNext(1);
verifyListenerInvokedWithSuccess(listeners.take());
subscriber.onNext(2);
verifyListenerInvokedWithSuccess(listeners.take());
}
Aggregations