Skip to content

Commit

Permalink
Modified Listeners tests and simple communication test
Browse files Browse the repository at this point in the history
Signed-off-by: Jesus Perez <[email protected]>
  • Loading branch information
jepemi committed Sep 14, 2023
1 parent f2bdef9 commit 1759caf
Show file tree
Hide file tree
Showing 6 changed files with 3,650 additions and 3,075 deletions.
5 changes: 4 additions & 1 deletion src/cpp/StatisticsBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,10 @@ void StatisticsBackend::set_alias(
{
entity->alias = alias;
std::vector<EntityId> domains = StatisticsBackend::get_entities(EntityKind::DOMAIN, entity_id);
StatisticsBackendData::get_instance()->database_->update_graph_on_updated_entity(domains[0], entity_id);
if(!domains.empty())
{
StatisticsBackendData::get_instance()->database_->update_graph_on_updated_entity(domains[0], entity_id);
}
}
}

Expand Down
128 changes: 115 additions & 13 deletions test/dds/communication/Monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ int main(
int arg_count = 1;
uint32_t seed = 7800;
unsigned int num_participants = 2;
unsigned int num_hosts = 1;
unsigned int num_users = 1;
unsigned int num_processes = 2;
unsigned int num_readers = 1;
// Each participant creates a meta traffic endpoint
unsigned int num_writers = num_participants + 1;
Expand Down Expand Up @@ -266,11 +269,20 @@ int main(
// and check that all entities are active
try
{
if (!StatisticsBackend::get_entities(EntityKind::HOST).empty() ||
!StatisticsBackend::get_entities(EntityKind::USER).empty() ||
!StatisticsBackend::get_entities(EntityKind::PROCESS).empty())
if (StatisticsBackend::get_entities(EntityKind::HOST).size() != num_hosts ||
StatisticsBackend::get_entities(EntityKind::HOST, monitor_id).size() != num_hosts)
{
throw Error("Error: database contains unexpected entities");
throw Error("Error: database contains unexpected HOST");
}
else if (StatisticsBackend::get_entities(EntityKind::USER).size() != num_users ||
StatisticsBackend::get_entities(EntityKind::USER, monitor_id).size() != num_users)
{
throw Error("Error: database contains unexpected USER");
}
else if (StatisticsBackend::get_entities(EntityKind::PROCESS).size() != num_processes ||
StatisticsBackend::get_entities(EntityKind::PROCESS, monitor_id).size() != num_processes)
{
throw Error("Error: database contains unexpected PROCESS");
}
else if (StatisticsBackend::get_entities(EntityKind::DOMAIN).size() != 1 ||
StatisticsBackend::get_entities(EntityKind::DOMAIN).begin()->value() != monitor_id)
Expand Down Expand Up @@ -327,6 +339,30 @@ int main(
entity.value()) + " is inactive after discovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::HOST, monitor_id))
{
if (!StatisticsBackend::is_active(entity))
{
throw Error("Error: HOST with id: " + std::to_string(
entity.value()) + " is inactive after discovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::USER, monitor_id))
{
if (!StatisticsBackend::is_active(entity))
{
throw Error("Error: USER with id: " + std::to_string(
entity.value()) + " is inactive after discovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::PROCESS, monitor_id))
{
if (!StatisticsBackend::is_active(entity))
{
throw Error("Error: PROCESS with id: " + std::to_string(
entity.value()) + " is inactive after discovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::DATAWRITER, monitor_id))
{
if (!StatisticsBackend::is_active(entity))
Expand Down Expand Up @@ -366,11 +402,20 @@ int main(
// and check that all entities except the monitor are inactive
try
{
if (!StatisticsBackend::get_entities(EntityKind::HOST).empty() ||
!StatisticsBackend::get_entities(EntityKind::USER).empty() ||
!StatisticsBackend::get_entities(EntityKind::PROCESS).empty())
if (StatisticsBackend::get_entities(EntityKind::HOST).size() != num_hosts ||
StatisticsBackend::get_entities(EntityKind::HOST, monitor_id).size() != num_hosts)
{
throw Error("Error: database contains unexpected entities");
throw Error("Error: database contains unexpected HOST");
}
else if (StatisticsBackend::get_entities(EntityKind::USER).size() != num_users ||
StatisticsBackend::get_entities(EntityKind::USER, monitor_id).size() != num_users)
{
throw Error("Error: database contains unexpected USER");
}
else if (StatisticsBackend::get_entities(EntityKind::PROCESS).size() != num_processes ||
StatisticsBackend::get_entities(EntityKind::PROCESS, monitor_id).size() != num_processes)
{
throw Error("Error: database contains unexpected PROCESS");
}
else if (StatisticsBackend::get_entities(EntityKind::DOMAIN).size() != 1 ||
StatisticsBackend::get_entities(EntityKind::DOMAIN).begin()->value() != monitor_id)
Expand Down Expand Up @@ -408,7 +453,7 @@ int main(
if (!StatisticsBackend::is_active(entity))
{
throw Error("Error: DOMAIN with id: " + std::to_string(
entity.value()) + " is inactive after undiscovering participants");
entity.value()) + " is active after undiscovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::TOPIC, monitor_id))
Expand All @@ -427,6 +472,30 @@ int main(
entity.value()) + " is active after undiscovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::HOST, monitor_id))
{
if (StatisticsBackend::is_active(entity))
{
throw Error("Error: HOST with id: " + std::to_string(
entity.value()) + " is active after undiscovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::USER, monitor_id))
{
if (StatisticsBackend::is_active(entity))
{
throw Error("Error: USER with id: " + std::to_string(
entity.value()) + " is active after undiscovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::PROCESS, monitor_id))
{
if (StatisticsBackend::is_active(entity))
{
throw Error("Error: PROCESS with id: " + std::to_string(
entity.value()) + " is active after undiscovering participants");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::DATAWRITER, monitor_id))
{
if (StatisticsBackend::is_active(entity))
Expand Down Expand Up @@ -468,11 +537,20 @@ int main(
// and check that all entities are inactive
try
{
if (!StatisticsBackend::get_entities(EntityKind::HOST).empty() ||
!StatisticsBackend::get_entities(EntityKind::USER).empty() ||
!StatisticsBackend::get_entities(EntityKind::PROCESS).empty())
if (StatisticsBackend::get_entities(EntityKind::HOST).size() != num_hosts ||
StatisticsBackend::get_entities(EntityKind::HOST, monitor_id).size() != num_hosts)
{
throw Error("Error: database contains unexpected entities");
throw Error("Error: database contains unexpected HOST");
}
else if (StatisticsBackend::get_entities(EntityKind::USER).size() != num_users ||
StatisticsBackend::get_entities(EntityKind::USER, monitor_id).size() != num_users)
{
throw Error("Error: database contains unexpected USER");
}
else if (StatisticsBackend::get_entities(EntityKind::PROCESS).size() != num_processes ||
StatisticsBackend::get_entities(EntityKind::PROCESS, monitor_id).size() != num_processes)
{
throw Error("Error: database contains unexpected PROCESS");
}
else if (StatisticsBackend::get_entities(EntityKind::DOMAIN).size() != 1 ||
StatisticsBackend::get_entities(EntityKind::DOMAIN).begin()->value() != monitor_id)
Expand Down Expand Up @@ -529,6 +607,30 @@ int main(
entity.value()) + " is active after stopping monitor");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::HOST, monitor_id))
{
if (StatisticsBackend::is_active(entity))
{
throw Error("Error: HOST with id: " + std::to_string(
entity.value()) + " is active after stopping monitor");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::USER, monitor_id))
{
if (StatisticsBackend::is_active(entity))
{
throw Error("Error: USER with id: " + std::to_string(
entity.value()) + " is active after stopping monitor");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::PROCESS, monitor_id))
{
if (StatisticsBackend::is_active(entity))
{
throw Error("Error: PROCESS with id: " + std::to_string(
entity.value()) + " is active after stopping monitor");
}
}
for (auto entity : StatisticsBackend::get_entities(EntityKind::DATAWRITER, monitor_id))
{
if (StatisticsBackend::is_active(entity))
Expand Down
5 changes: 3 additions & 2 deletions test/unittest/Database/DatabaseLoadTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ TEST(database_load_tests, load_and_dump_complex_erased_database)

// Check that the next_id_ is the expected
EXPECT_EQ(db.next_id(), 27);
// Check that EntityId 13 (domain_1) does not exist in the database
EXPECT_THROW(db.get_entity(13), BadParameter);
// Check that EntityId 13 (domain_1) does not contain participants nor topics
EXPECT_TRUE(std::dynamic_pointer_cast<const database::Domain>(db.get_entity(13))->participants.empty());
EXPECT_TRUE(std::dynamic_pointer_cast<const database::Domain>(db.get_entity(13))->topics.empty());

// Compare the dumps to ensure that the entities have been created with the same ids.
ASSERT_EQ(dump, loadedDump);
Expand Down
Loading

0 comments on commit 1759caf

Please sign in to comment.