@@ -1261,4 +1261,98 @@ public void accept(final Collection<NameAndTypes> local, Collection<NameAndTypes
12611261 subscription .dispose ();
12621262 remoteNode .dispose ();
12631263 }
1264+
1265+ @ Test
1266+ public final void testGetSubscriptionNamesAndTypesByNode () throws Exception {
1267+ final Node remoteNode = RCLJava .createNode ("test_get_subscription_names_and_types_remote_node" );
1268+ Subscription <rcljava .msg .Empty > subscription1 = node .<rcljava .msg .Empty >createSubscription (
1269+ rcljava .msg .Empty .class , "test_get_subscription_names_and_types_one" ,
1270+ new Consumer <rcljava .msg .Empty >() {
1271+ public void accept (final rcljava .msg .Empty msg ) {}
1272+ });
1273+ Subscription <rcljava .msg .Empty > subscription2 = node .<rcljava .msg .Empty >createSubscription (
1274+ rcljava .msg .Empty .class , "test_get_subscription_names_and_types_two" ,
1275+ new Consumer <rcljava .msg .Empty >() {
1276+ public void accept (final rcljava .msg .Empty msg ) {}
1277+ });
1278+ Subscription <rcljava .msg .Empty > subscription3 = remoteNode .<rcljava .msg .Empty >createSubscription (
1279+ rcljava .msg .Empty .class , "test_get_subscription_names_and_types_two" ,
1280+ new Consumer <rcljava .msg .Empty >() {
1281+ public void accept (final rcljava .msg .Empty msg ) {}
1282+ });
1283+ Subscription <rcljava .msg .Empty > subscription4 = remoteNode .<rcljava .msg .Empty >createSubscription (
1284+ rcljava .msg .Empty .class , "test_get_subscription_names_and_types_three" ,
1285+ new Consumer <rcljava .msg .Empty >() {
1286+ public void accept (final rcljava .msg .Empty msg ) {}
1287+ });
1288+ Publisher <rcljava .msg .UInt32 > publisher = node .<rcljava .msg .UInt32 >createPublisher (
1289+ rcljava .msg .UInt32 .class , "test_get_topic_names_and_types_this_should_not_appear" );
1290+
1291+ BiConsumer <Collection <NameAndTypes >, Collection <NameAndTypes >> validateNameAndTypes =
1292+ new BiConsumer <Collection <NameAndTypes >, Collection <NameAndTypes >>() {
1293+ public void accept (final Collection <NameAndTypes > local , Collection <NameAndTypes > remote ) {
1294+ // TODO(ivanpauno): Using assertj may help a lot here https://assertj.github.io/doc/.
1295+ assertEquals (local .size (), 2 );
1296+ assertTrue (
1297+ "topic 'test_get_subscription_names_and_types_one' was not discovered for local node" ,
1298+ local .contains (
1299+ new NameAndTypes (
1300+ "/test_get_subscription_names_and_types_one" ,
1301+ new ArrayList (Arrays .asList ("rcljava/msg/Empty" )))));
1302+ assertTrue (
1303+ "topic 'test_get_subscription_names_and_types_two' was not discovered for local node" ,
1304+ local .contains (
1305+ new NameAndTypes (
1306+ "/test_get_subscription_names_and_types_two" ,
1307+ new ArrayList (Arrays .asList ("rcljava/msg/Empty" )))));
1308+
1309+ assertEquals (remote .size (), 2 );
1310+ assertTrue (
1311+ "topic 'test_get_subscription_names_and_types_two' was not discovered for remote node" ,
1312+ remote .contains (
1313+ new NameAndTypes (
1314+ "/test_get_subscription_names_and_types_two" ,
1315+ new ArrayList (Arrays .asList ("rcljava/msg/Empty" )))));
1316+ assertTrue (
1317+ "topic 'test_get_subscription_names_and_types_three' was not discovered for remote node" ,
1318+ remote .contains (
1319+ new NameAndTypes (
1320+ "/test_get_subscription_names_and_types_three" ,
1321+ new ArrayList (Arrays .asList ("rcljava/msg/Empty" )))));
1322+ }
1323+ };
1324+
1325+ long start = System .currentTimeMillis ();
1326+ boolean ok = false ;
1327+ Collection <NameAndTypes > local = null ;
1328+ Collection <NameAndTypes > remote = null ;
1329+ do {
1330+ local = this .node .getSubscriptionNamesAndTypesByNode ("test_node" , "/" );
1331+ remote = this .node .getSubscriptionNamesAndTypesByNode (
1332+ "test_get_subscription_names_and_types_remote_node" , "/" );
1333+ try {
1334+ validateNameAndTypes .accept (local , remote );
1335+ ok = true ;
1336+ } catch (AssertionError err ) {
1337+ // ignore here, it's going to be validated again at the end.
1338+ }
1339+ // TODO(ivanpauno): We could wait for the graph guard condition to be triggered if that
1340+ // would be available.
1341+ try {
1342+ TimeUnit .MILLISECONDS .sleep (100 );
1343+ } catch (InterruptedException err ) {
1344+ // ignore
1345+ }
1346+ } while (!ok && System .currentTimeMillis () < start + 1000 );
1347+ assertNotNull (local );
1348+ assertNotNull (remote );
1349+ validateNameAndTypes .accept (local , remote );
1350+
1351+ subscription1 .dispose ();
1352+ subscription2 .dispose ();
1353+ subscription3 .dispose ();
1354+ subscription4 .dispose ();
1355+ publisher .dispose ();
1356+ remoteNode .dispose ();
1357+ }
12641358}
0 commit comments