单元测试

  • writeInbound:将入站消息写到EmbeddedChannel中。如果可以通过readInbound()方法从EmbeddedChnnel中读取数据,则返回true。

  • readInbound:从EmbeddedChannel中读取一个入站消息。任何返回的东西都穿越了整个ChannelPipeline。如果没有任何可供读取的,则返回null。

  • writeOutbound:将出站消息写到EmbeddedChannel中。如果现在可以通过readOutbound()方法从EmbeddedChannel中读取到什么东西,则返回true。

  • readOutbound:从EmbeddedChannel中读取一个出站消息。任何返回的东西都穿越了整个ChannelPipeline。如果没有任何可供读取的,则返回null。

  • finish:将EmbeddedChannel标记为完成,并且如果有可被读取的入站数据或者出站数据,则返回true。这个方法还会调用EmbededChannel上的close方法。

我觉得EmbeddedChannel已经有点和我的直觉有点冲突了。我以为EmbeddedChannel是为了他替换底层的Channel,然后我们往其中写入一个数据,从而触发pipeline中的ChannelInboundHandler,进而触发各个业务逻辑,最终业务逻辑会往Channel中写一些数据,然后我们获取这些数据,即可以完成一个单元测试,但是实际情况好像不是这样的。