From 797fbc0ae0738b7bcda3b7b97c0e6b97d9f6d47c Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Thu, 20 Aug 2020 15:34:30 -0300 Subject: [PATCH 1/6] Add basic test for RequestedQosIncompatible event Signed-off-by: Ivan Santiago Paunovic --- .../subscription/SubscriptionTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/rcljava/src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java b/rcljava/src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java index 6b01a634..4f5e1ea1 100644 --- a/rcljava/src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java +++ b/rcljava/src/test/java/org/ros2/rcljava/subscription/SubscriptionTest.java @@ -23,7 +23,9 @@ import org.ros2.rcljava.RCLJava; import org.ros2.rcljava.consumers.Consumer; +import org.ros2.rcljava.events.EventHandler; import org.ros2.rcljava.node.Node; +import org.ros2.rcljava.subscription.statuses.RequestedQosIncompatible; public class SubscriptionTest { @BeforeClass @@ -53,4 +55,33 @@ public void accept(final std_msgs.msg.String msg) {} RCLJava.shutdown(); } + + @Test + public final void testCreateRequestedQosIncompatibleEvent() { + String identifier = RCLJava.getRMWIdentifier(); + if (identifier.equals("rmw_fastrtps_cpp") || identifier.equals("rmw_fastrtps_dynamic_cpp")) { + // event not supported in these implementations + return; + } + RCLJava.rclJavaInit(); + Node node = RCLJava.createNode("test_node"); + Subscription subscription = node.createSubscription( + std_msgs.msg.String.class, "test_topic", new Consumer() { + public void accept(final std_msgs.msg.String msg) {} + }); + EventHandler eventHandler = subscription.createEventHandler( + RequestedQosIncompatible.factory, new Consumer() { + public void accept(final RequestedQosIncompatible status) { + assertEquals(status.totalCount, 0); + assertEquals(status.totalCountChange, 0); + assertEquals(status.lastPolicyKind, RequestedQosIncompatible.PolicyKind.INVALID); + } + } + ); + assertNotEquals(0, eventHandler.getHandle()); + // force executing the callback, so we check that taking an event works + eventHandler.executeCallback(); + RCLJava.shutdown(); + assertEquals(0, eventHandler.getHandle()); + } } From 63435b75d464b21722fb96bc12b74b103bfc578e Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Thu, 20 Aug 2020 16:12:59 -0300 Subject: [PATCH 2/6] Test RequestedQosIncompatible subscription event with executor Signed-off-by: Ivan Santiago Paunovic --- .../test/java/org/ros2/rcljava/SpinTest.java | 93 ++++++++++++++++--- 1 file changed, 78 insertions(+), 15 deletions(-) diff --git a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java index 2562d23e..7e0a1c9f 100644 --- a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java +++ b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java @@ -41,6 +41,7 @@ import org.ros2.rcljava.qos.policies.Reliability; import org.ros2.rcljava.qos.QoSProfile; import org.ros2.rcljava.subscription.Subscription; +import org.ros2.rcljava.subscription.statuses.RequestedQosIncompatible; public class SpinTest { public static class TimerCallback implements Callback { @@ -345,7 +346,7 @@ public Node getNode() { } // custom event consumer - public static class EventConsumer implements Consumer { + public static class OfferedQosIncompatibleConsumer implements Consumer { public boolean done = false; public void accept(final OfferedQosIncompatible status) { @@ -357,35 +358,95 @@ public void accept(final OfferedQosIncompatible status) { } @Test - public final void testSpinEvent() { + public final void testSpinPublisherEvent() { String identifier = RCLJava.getRMWIdentifier(); if (identifier.equals("rmw_fastrtps_cpp") || identifier.equals("rmw_fastrtps_dynamic_cpp")) { - // OfferedQosIncompatible event not supported in these implementations + // OfferedQosIncompatible events is not supported in these implementations. return; } - final Node node = RCLJava.createNode("test_node_spin_event"); + final Node node = RCLJava.createNode("test_node_spin_publisher_event"); Publisher publisher = node.createPublisher( - std_msgs.msg.String.class, "test_topic_spin_event", new QoSProfile( + std_msgs.msg.String.class, "test_topic_spin_publisher_event", new QoSProfile( History.KEEP_LAST, 1, Reliability.BEST_EFFORT, Durability.VOLATILE, false)); // create a OfferedQoSIncompatible event handler with custom event consumer - EventConsumer eventConsumer = new EventConsumer(); + OfferedQosIncompatibleConsumer eventConsumer = new OfferedQosIncompatibleConsumer(); EventHandler eventHandler = publisher.createEventHandler( OfferedQosIncompatible.factory, eventConsumer ); // create an incompatible subscription (reliable vs best effort publisher) Subscription subscription = node.createSubscription( - std_msgs.msg.String.class, "test_topic_spin_event", - new Consumer() { - public void accept(final std_msgs.msg.String msg) {} - }, - new QoSProfile( - History.KEEP_LAST, 1, - Reliability.RELIABLE, - Durability.VOLATILE, - false)); + std_msgs.msg.String.class, "test_topic_spin_publisher_event", + new Consumer() { + public void accept(final std_msgs.msg.String msg) {} + }, + new QoSProfile( + History.KEEP_LAST, 1, + Reliability.RELIABLE, + Durability.VOLATILE, + false)); + // set up executor + ComposableNode composableNode = new ComposableNode() { + public Node getNode() { + return node; + } + }; + Executor executor = new SingleThreadedExecutor(); + executor.addNode(composableNode); + long start = System.currentTimeMillis(); + do { + executor.spinAll((1000 + System.currentTimeMillis() - start) * 1000 * 1000); + } while (!eventConsumer.done && System.currentTimeMillis() < start + 1000); + assert(eventConsumer.done); + } + + public static class RequestedQosIncompatibleConsumer + implements Consumer { + public boolean done = false; + + public void accept(final RequestedQosIncompatible status) { + assertEquals(status.totalCount, 1); + assertEquals(status.totalCountChange, 1); + assertEquals(status.lastPolicyKind, RequestedQosIncompatible.PolicyKind.RELIABILITY); + this.done = true; + } + } + + @Test + public final void testSpinSubscriptionEvent() { + String identifier = RCLJava.getRMWIdentifier(); + if (identifier.equals("rmw_fastrtps_cpp") || identifier.equals("rmw_fastrtps_dynamic_cpp")) { + // RequestedQosIncompatible events is not supported in these implementations. + return; + } + final Node node = RCLJava.createNode("test_node_spin_subscription_event"); + // create an incompatible subscription (reliable vs best effort publisher) + Subscription subscription = node.createSubscription( + std_msgs.msg.String.class, "test_topic_spin_subscription_event", + new Consumer() { + public void accept(final std_msgs.msg.String msg) {} + }, + new QoSProfile( + History.KEEP_LAST, 1, + Reliability.RELIABLE, + Durability.VOLATILE, + false)); + // create a RequestedQoSIncompatible event handler with custom event consumer + RequestedQosIncompatibleConsumer eventConsumer = new RequestedQosIncompatibleConsumer(); + System.out.print("creating event handler"); + EventHandler eventHandler = subscription.createEventHandler( + RequestedQosIncompatible.factory, eventConsumer + ); + System.out.print("created event handler"); + Publisher publisher = node.createPublisher( + std_msgs.msg.String.class, "test_topic_spin_subscription_event", new QoSProfile( + History.KEEP_LAST, 1, + Reliability.BEST_EFFORT, + Durability.VOLATILE, + false)); + // set up executor ComposableNode composableNode = new ComposableNode() { public Node getNode() { @@ -395,9 +456,11 @@ public Node getNode() { Executor executor = new SingleThreadedExecutor(); executor.addNode(composableNode); long start = System.currentTimeMillis(); + System.out.print("spinning"); do { executor.spinAll((1000 + System.currentTimeMillis() - start) * 1000 * 1000); } while (!eventConsumer.done && System.currentTimeMillis() < start + 1000); + System.out.print("done!"); assert(eventConsumer.done); } } From fdeb7d2228fd136ff52d5fc1fdc52cb2ca9e5542 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Wed, 26 Aug 2020 11:03:57 -0300 Subject: [PATCH 3/6] remove debug log Signed-off-by: Ivan Santiago Paunovic --- rcljava/src/test/java/org/ros2/rcljava/SpinTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java index 7e0a1c9f..3c7cddc8 100644 --- a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java +++ b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java @@ -435,7 +435,6 @@ public void accept(final std_msgs.msg.String msg) {} false)); // create a RequestedQoSIncompatible event handler with custom event consumer RequestedQosIncompatibleConsumer eventConsumer = new RequestedQosIncompatibleConsumer(); - System.out.print("creating event handler"); EventHandler eventHandler = subscription.createEventHandler( RequestedQosIncompatible.factory, eventConsumer ); From 80c58bcddf994623c3ee37e47566cc384377b6a3 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Wed, 26 Aug 2020 11:04:19 -0300 Subject: [PATCH 4/6] remove debug log Signed-off-by: Ivan Santiago Paunovic --- rcljava/src/test/java/org/ros2/rcljava/SpinTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java index 3c7cddc8..aea33b78 100644 --- a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java +++ b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java @@ -438,7 +438,6 @@ public void accept(final std_msgs.msg.String msg) {} EventHandler eventHandler = subscription.createEventHandler( RequestedQosIncompatible.factory, eventConsumer ); - System.out.print("created event handler"); Publisher publisher = node.createPublisher( std_msgs.msg.String.class, "test_topic_spin_subscription_event", new QoSProfile( History.KEEP_LAST, 1, From aa4c40c34d6c0f8de9a22b4c06a6f093c4cf6b67 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Wed, 26 Aug 2020 11:05:03 -0300 Subject: [PATCH 5/6] remove debug log Signed-off-by: Ivan Santiago Paunovic --- rcljava/src/test/java/org/ros2/rcljava/SpinTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java index aea33b78..f78267cb 100644 --- a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java +++ b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java @@ -454,7 +454,6 @@ public Node getNode() { Executor executor = new SingleThreadedExecutor(); executor.addNode(composableNode); long start = System.currentTimeMillis(); - System.out.print("spinning"); do { executor.spinAll((1000 + System.currentTimeMillis() - start) * 1000 * 1000); } while (!eventConsumer.done && System.currentTimeMillis() < start + 1000); From f51b9aced1905a369993231c8448b9c637f49ac6 Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Wed, 26 Aug 2020 11:05:30 -0300 Subject: [PATCH 6/6] remove debug log Signed-off-by: Ivan Santiago Paunovic --- rcljava/src/test/java/org/ros2/rcljava/SpinTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java index f78267cb..aa9b51ab 100644 --- a/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java +++ b/rcljava/src/test/java/org/ros2/rcljava/SpinTest.java @@ -457,7 +457,6 @@ public Node getNode() { do { executor.spinAll((1000 + System.currentTimeMillis() - start) * 1000 * 1000); } while (!eventConsumer.done && System.currentTimeMillis() < start + 1000); - System.out.print("done!"); assert(eventConsumer.done); } }