Add multinode maps and type specific maps.
This lets us do things like remap timing reports per node and handle
them correctly. And also only map the timing reports and not everything
on /aos. This also becomes more interesting when AOS_LOG logs, and we
have a starter which publishes statistics.
Change-Id: I2147e3b722b472d4480c86e7c8acda938aa3d1d2
diff --git a/aos/configuration_test.cc b/aos/configuration_test.cc
index 35b9daf..ff0b570 100644
--- a/aos/configuration_test.cc
+++ b/aos/configuration_test.cc
@@ -22,6 +22,9 @@
// *the* expected location for all working tests.
const char *kExpectedLocation =
"{ \"name\": \"/foo\", \"type\": \".aos.bar\", \"max_size\": 5 }";
+// And for multinode setups
+const char *kExpectedMultinodeLocation =
+ "{ \"name\": \"/foo\", \"type\": \".aos.bar\", \"max_size\": 5, \"source_node\": \"pi1\" }";
// Tests that we can read and merge a configuration.
TEST_F(ConfigurationTest, ConfigMerge) {
@@ -56,7 +59,7 @@
LOG(INFO) << "Read: " << FlatbufferToJson(config, true);
EXPECT_EQ(FlatbufferToJson(GetChannel(config, ".aos.robot_state",
- "aos.RobotState", "app1")),
+ "aos.RobotState", "app1", nullptr)),
"{ \"name\": \".aos.robot_state\", \"type\": \"aos.RobotState\", "
"\"max_size\": 5 }");
}
@@ -78,27 +81,88 @@
ReadConfig("aos/testdata/config1.json");
// Test a basic lookup first.
- EXPECT_EQ(FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app1")),
- kExpectedLocation);
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app1", nullptr)),
+ kExpectedLocation);
// Test that an invalid name results in nullptr back.
- EXPECT_EQ(GetChannel(config, "/invalid_name", ".aos.bar", "app1"), nullptr);
+ EXPECT_EQ(GetChannel(config, "/invalid_name", ".aos.bar", "app1", nullptr),
+ nullptr);
// Tests that a root map/rename works. And that they get processed from the
// bottom up.
- EXPECT_EQ(
- FlatbufferToJson(GetChannel(config, "/batman", ".aos.bar", "app1")),
- kExpectedLocation);
+ EXPECT_EQ(FlatbufferToJson(
+ GetChannel(config, "/batman", ".aos.bar", "app1", nullptr)),
+ kExpectedLocation);
// And then test that an application specific map/rename works.
- EXPECT_EQ(FlatbufferToJson(GetChannel(config, "/bar", ".aos.bar", "app1")),
- kExpectedLocation);
- EXPECT_EQ(FlatbufferToJson(GetChannel(config, "/baz", ".aos.bar", "app2")),
- kExpectedLocation);
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/bar", ".aos.bar", "app1", nullptr)),
+ kExpectedLocation);
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/baz", ".aos.bar", "app2", nullptr)),
+ kExpectedLocation);
// And then test that an invalid application name gets properly ignored.
- EXPECT_EQ(FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app3")),
- kExpectedLocation);
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app3", nullptr)),
+ kExpectedLocation);
+}
+
+// Tests that we can lookup a location with node specific maps.
+TEST_F(ConfigurationTest, GetChannelMultinode) {
+ FlatbufferDetachedBuffer<Configuration> config =
+ ReadConfig("aos/testdata/good_multinode.json");
+ const Node *pi1 = GetNode(&config.message(), "pi1");
+ const Node *pi2 = GetNode(&config.message(), "pi2");
+
+ // Test a basic lookup first.
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app1", pi1)),
+ kExpectedMultinodeLocation);
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/foo", ".aos.bar", "app1", pi2)),
+ kExpectedMultinodeLocation);
+
+ // Tests that a root map/rename works with a node specific map.
+ EXPECT_EQ(FlatbufferToJson(
+ GetChannel(config, "/batman", ".aos.bar", "app1", pi1)),
+ kExpectedMultinodeLocation);
+
+ // Tests that a root map/rename fails with a node specific map for the wrong
+ // node.
+ EXPECT_EQ(GetChannel(config, "/batman", ".aos.bar", "app1", pi2), nullptr);
+
+ // And then test that an application specific map/rename works.
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/batman2", ".aos.bar", "app1", pi1)),
+ kExpectedMultinodeLocation);
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/batman3", ".aos.bar", "app1", pi1)),
+ kExpectedMultinodeLocation);
+
+ // And then that it fails when the node changes.
+ EXPECT_EQ(GetChannel(config, "/batman3", ".aos.bar", "app1", pi2), nullptr);
+}
+
+// Tests that we can lookup a location with type specific maps.
+TEST_F(ConfigurationTest, GetChannelTypedMultinode) {
+ FlatbufferDetachedBuffer<Configuration> config =
+ ReadConfig("aos/testdata/good_multinode.json");
+ const Node *pi1 = GetNode(&config.message(), "pi1");
+
+ // Test a basic lookup first.
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/batman", ".aos.bar", "app1", pi1)),
+ kExpectedMultinodeLocation);
+
+ // Now confirm that a second message on the same name doesn't get remapped.
+ const char *kExpectedBazMultinodeLocation =
+ "{ \"name\": \"/batman\", \"type\": \".aos.baz\", \"max_size\": 5, "
+ "\"source_node\": \"pi1\" }";
+ EXPECT_EQ(
+ FlatbufferToJson(GetChannel(config, "/batman", ".aos.baz", "app1", pi1)),
+ kExpectedBazMultinodeLocation);
}
// Tests that we reject a configuration which has a nodes list, but has channels