0

Has anyone tried to use Awaitility to test a Netty Client and Server.

I want to test that the server has received all messages from the Client and any other tests that might be useful.

I suppose the only thing is how to get the number of messages the Server received from the Server side Handler

borjab
  • 11,149
  • 6
  • 71
  • 98
DarVar
  • 16,882
  • 29
  • 97
  • 146

1 Answers1

1

I never use "Awaitility" to test netty, but writing such a test is really straight forward. Just add a custom SimpleChannelUpstreamHandler that increment a counter on every messageReceived(..) call and then check if the count match what you expect with junit assertEquals(..)

Norman Maurer
  • 23,104
  • 2
  • 33
  • 31
  • Hi Norman, Whats the best way to then get the SimpleChannelUpstreamHandler used by the Client in the test ? My setUp method instantiates and starts the Server. Is there a way to get the specific test Client's Handler from the ServerBootstrap? – DarVar Jan 11 '12 at 18:27
  • Well you could just assign the SimpleChannelUpstreamHandler in the setUp() and store it in a private field. Then you can access it in your unit tests. – Norman Maurer Jan 13 '12 at 07:08
  • This is a full end-to-end regression test for the Client and Server. So what I did in the end is add the following to my server class to return the handler:
    `MyMessageHandler handler = channelPipelineFactory.getPipeline().get(MyMessageHandler.class);`
    It's not nice but only wait I could think of getting the Server upstream handler to test the Client messages were received.
    – DarVar Jan 13 '12 at 12:25