1
1
package com .baeldung .rsocket ;
2
2
3
+ import java .util .ArrayList ;
3
4
import java .util .List ;
4
5
import org .junit .AfterClass ;
5
6
import org .junit .BeforeClass ;
@@ -29,28 +30,35 @@ public static void tearDownClass() {
29
30
}
30
31
31
32
@ Test
32
- public void testRequestResponse () {
33
+ public void whenSendingAString_thenRevceiveTheSameString () {
33
34
ReqResClient client = new ReqResClient ();
34
35
String string = "Hello RSocket" ;
35
36
assertEquals (string , client .callBlocking (string ));
36
37
client .dispose ();
37
38
}
38
39
39
40
@ Test
40
- public void testFNFAndRequestStream () {
41
+ public void whenSendingStream_thenReceiveTheSameStream () {
41
42
// create the client that pushes data to the server and start sending
42
43
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
+
43
47
// get the data that is used by the client
44
48
List <Float > data = fnfClient .getData ();
49
+ // create a place to count the results
50
+ List <Float > dataReceived = new ArrayList <>();
45
51
46
- // create a client to read a stream from the server and subscribe to events
47
- ReqStreamClient streamClient = new ReqStreamClient ();
48
52
// assert that the data received is the same as the data sent
49
53
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
+ );
54
62
55
63
// start sending the data
56
64
fnfClient .sendData ();
@@ -59,10 +67,13 @@ public void testFNFAndRequestStream() {
59
67
try { Thread .sleep (500 ); } catch (Exception x ) {}
60
68
subscription .dispose ();
61
69
fnfClient .dispose ();
70
+
71
+ // verify the item count
72
+ assertEquals ("Wrong data count received" , data .size (), dataReceived .size ());
62
73
}
63
74
64
75
@ Test
65
- public void testChannel () {
76
+ public void whenRunningChannelGame_thenLogTheResults () {
66
77
ChannelClient client = new ChannelClient ();
67
78
client .playGame ();
68
79
client .dispose ();
0 commit comments