@@ -1484,4 +1484,95 @@ public void accept(final Collection<NameAndTypes> local, Collection<NameAndTypes
14841484 client .dispose ();
14851485 remoteNode .dispose ();
14861486 }
1487+
1488+ @ Test
1489+ public final void testGetClientNamesAndTypesByNode () throws Exception {
1490+ final Node remoteNode = RCLJava .createNode ("test_get_client_names_and_types_remote_node" );
1491+ Client <rcljava .srv .AddTwoInts > client1 = node .<rcljava .srv .AddTwoInts >createClient (
1492+ rcljava .srv .AddTwoInts .class , "test_get_client_names_and_types_one" );
1493+ Client <rcljava .srv .AddTwoInts > client2 = node .<rcljava .srv .AddTwoInts >createClient (
1494+ rcljava .srv .AddTwoInts .class , "test_get_client_names_and_types_two" );
1495+ Client <rcljava .srv .AddTwoInts > client3 = remoteNode .<rcljava .srv .AddTwoInts >createClient (
1496+ rcljava .srv .AddTwoInts .class , "test_get_client_names_and_types_two" );
1497+ Client <rcljava .srv .AddTwoInts > client4 = remoteNode .<rcljava .srv .AddTwoInts >createClient (
1498+ rcljava .srv .AddTwoInts .class , "test_get_client_names_and_types_three" );
1499+ Service <rcljava .srv .AddTwoInts > service = node .<rcljava .srv .AddTwoInts >createService (
1500+ rcljava .srv .AddTwoInts .class , "test_get_client_names_and_types_this_should_not_appear" ,
1501+ new TriConsumer <
1502+ RMWRequestId , rcljava .srv .AddTwoInts_Request , rcljava .srv .AddTwoInts_Response >()
1503+ {
1504+ public final void accept (
1505+ final RMWRequestId header ,
1506+ final rcljava .srv .AddTwoInts_Request request ,
1507+ final rcljava .srv .AddTwoInts_Response response )
1508+ {}
1509+ });
1510+
1511+ BiConsumer <Collection <NameAndTypes >, Collection <NameAndTypes >> validateNameAndTypes =
1512+ new BiConsumer <Collection <NameAndTypes >, Collection <NameAndTypes >>() {
1513+ public void accept (final Collection <NameAndTypes > local , Collection <NameAndTypes > remote ) {
1514+ // TODO(ivanpauno): Using assertj may help a lot here https://assertj.github.io/doc/.
1515+ assertEquals (local .size (), 2 );
1516+ assertTrue (
1517+ "client 'test_get_client_names_and_types_one' was not discovered for local node" ,
1518+ local .contains (
1519+ new NameAndTypes (
1520+ "/test_get_client_names_and_types_one" ,
1521+ new ArrayList (Arrays .asList ("rcljava/srv/AddTwoInts" )))));
1522+ assertTrue (
1523+ "client 'test_get_client_names_and_types_two' was not discovered for local node" ,
1524+ local .contains (
1525+ new NameAndTypes (
1526+ "/test_get_client_names_and_types_two" ,
1527+ new ArrayList (Arrays .asList ("rcljava/srv/AddTwoInts" )))));
1528+
1529+ assertEquals (remote .size (), 2 );
1530+ assertTrue (
1531+ "client 'test_get_client_names_and_types_two' was not discovered for remote node" ,
1532+ remote .contains (
1533+ new NameAndTypes (
1534+ "/test_get_client_names_and_types_two" ,
1535+ new ArrayList (Arrays .asList ("rcljava/srv/AddTwoInts" )))));
1536+ assertTrue (
1537+ "client 'test_get_client_names_and_types_three' was not discovered for remote node" ,
1538+ remote .contains (
1539+ new NameAndTypes (
1540+ "/test_get_client_names_and_types_three" ,
1541+ new ArrayList (Arrays .asList ("rcljava/srv/AddTwoInts" )))));
1542+ }
1543+ };
1544+
1545+ long start = System .currentTimeMillis ();
1546+ boolean ok = false ;
1547+ Collection <NameAndTypes > local = null ;
1548+ Collection <NameAndTypes > remote = null ;
1549+ do {
1550+ local = this .node .getClientNamesAndTypesByNode ("test_node" , "/" );
1551+ remote = this .node .getClientNamesAndTypesByNode (
1552+ "test_get_client_names_and_types_remote_node" , "/" );
1553+ try {
1554+ validateNameAndTypes .accept (local , remote );
1555+ ok = true ;
1556+ } catch (AssertionError err ) {
1557+ // ignore here, it's going to be validated again at the end.
1558+ }
1559+ // TODO(ivanpauno): We could wait for the graph guard condition to be triggered if that
1560+ // would be available.
1561+ try {
1562+ TimeUnit .MILLISECONDS .sleep (100 );
1563+ } catch (InterruptedException err ) {
1564+ // ignore
1565+ }
1566+ } while (!ok && System .currentTimeMillis () < start + 1000 );
1567+ assertNotNull (local );
1568+ assertNotNull (remote );
1569+ validateNameAndTypes .accept (local , remote );
1570+
1571+ client1 .dispose ();
1572+ client2 .dispose ();
1573+ client3 .dispose ();
1574+ client4 .dispose ();
1575+ service .dispose ();
1576+ remoteNode .dispose ();
1577+ }
14871578}
0 commit comments