如何将rxNetty客户端与EmbeddedChannel一起用于测试

时间:2018-05-18 11:19:54

标签: rx-java rx-netty

鉴于我TcpClient喜欢这样:

TcpClient.newClient(...)
         .pipelineConfigurator(...)
         .createConnectionRequest()
         .flatMap(c -> c.getInput())

我想使用Netty的EmbeddedChannel来测试它,以模拟服务器和客户端之间的交互,并在EmbeddedChannelTestSubscriber上进行断言。

我正在努力寻找一种传递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.

我是在订阅后写的数据

我错过了什么?

0 个答案:

没有答案