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