鉴于我TcpClient
喜欢这样:
TcpClient.newClient(...)
.pipelineConfigurator(...)
.createConnectionRequest()
.flatMap(c -> c.getInput())
我想使用Netty的EmbeddedChannel
来测试它,以模拟服务器和客户端之间的交互,并在EmbeddedChannel
和TestSubscriber
上进行断言。
我正在努力寻找一种传递EmbeddedChannel
来实现这一目标的方法。我看着channelProvider()
这样做:
EmbeddedChannel channel = new EmbeddedChannel()
ChannelPorivderFactory providerFactory = (a,b,c,d) -> n -> Observable.just(channel);
TestSubscriber<Object> subscriber = new TestSubscriber<>();
TcpClient.newClient(...)
.pipelineConfigurator(...)
.channelProvider(providerFactory)
.createConnectionRequest()
.flatMap(c -> c.getInput())
.subscribe(subscriber);
embeddedChannel.writeInbound(serverMessage);
subscriber.assertValueCount(1);
我现在可以channel.writeInbound(someServerResponse)
我可以在Netty有线日志中看到写入的字节但我收到此消息
Data received on channel, but no subscriber registered. Discarding data.
我是在订阅后写的数据
我错过了什么?