11package com .baeldung .rsocket ;
22
3+ import java .util .ArrayList ;
34import java .util .List ;
45import org .junit .AfterClass ;
56import org .junit .BeforeClass ;
@@ -29,28 +30,35 @@ public static void tearDownClass() {
2930 }
3031
3132 @ Test
32- public void testRequestResponse () {
33+ public void whenSendingAString_thenRevceiveTheSameString () {
3334 ReqResClient client = new ReqResClient ();
3435 String string = "Hello RSocket" ;
3536 assertEquals (string , client .callBlocking (string ));
3637 client .dispose ();
3738 }
3839
3940 @ Test
40- public void testFNFAndRequestStream () {
41+ public void whenSendingStream_thenReceiveTheSameStream () {
4142 // create the client that pushes data to the server and start sending
4243 FireNForgetClient fnfClient = new FireNForgetClient ();
44+ // create a client to read a stream from the server and subscribe to events
45+ ReqStreamClient streamClient = new ReqStreamClient ();
46+
4347 // get the data that is used by the client
4448 List <Float > data = fnfClient .getData ();
49+ // create a place to count the results
50+ List <Float > dataReceived = new ArrayList <>();
4551
46- // create a client to read a stream from the server and subscribe to events
47- ReqStreamClient streamClient = new ReqStreamClient ();
4852 // assert that the data received is the same as the data sent
4953 Disposable subscription = streamClient .getDataStream ()
50- .index ()
51- .doOnNext (element -> assertEquals (data .get (element .getT1 ().intValue ()), element .getT2 ()))
52- .count ()
53- .subscribe (count -> assertEquals (data .size (), count .intValue ()));
54+ .index ()
55+ .subscribe (
56+ tuple -> {
57+ assertEquals ("Wrong value" , data .get (tuple .getT1 ().intValue ()), tuple .getT2 ());
58+ dataReceived .add (tuple .getT2 ());
59+ },
60+ err -> LOG .error (err .getMessage ())
61+ );
5462
5563 // start sending the data
5664 fnfClient .sendData ();
@@ -59,10 +67,13 @@ public void testFNFAndRequestStream() {
5967 try { Thread .sleep (500 ); } catch (Exception x ) {}
6068 subscription .dispose ();
6169 fnfClient .dispose ();
70+
71+ // verify the item count
72+ assertEquals ("Wrong data count received" , data .size (), dataReceived .size ());
6273 }
6374
6475 @ Test
65- public void testChannel () {
76+ public void whenRunningChannelGame_thenLogTheResults () {
6677 ChannelClient client = new ChannelClient ();
6778 client .playGame ();
6879 client .dispose ();
0 commit comments