diff --git a/src/cpp/database/database.cpp b/src/cpp/database/database.cpp index 01acaa5fd..ed2ef8586 100644 --- a/src/cpp/database/database.cpp +++ b/src/cpp/database/database.cpp @@ -924,11 +924,13 @@ void Database::insert_nts( if (writer != domain_writers->second.end()) { const HistoryLatencySample& fastdds_latency = dynamic_cast(sample); - + // Reject samples with old timestamps - if (writer->second->data.history2history_latency.find(fastdds_latency.reader) != - writer->second->data.history2history_latency.end() && - fastdds_latency.src_ts <= writer->second->data.history2history_latency[fastdds_latency.reader].back().src_ts) + if (writer->second->data.history2history_latency.find(fastdds_latency.reader) != + writer->second->data.history2history_latency.end() && + fastdds_latency.src_ts <= + writer->second->data.history2history_latency[fastdds_latency.reader].back(). + src_ts) { break; } @@ -954,8 +956,10 @@ void Database::insert_nts( // Reject samples with old timestamps if (participant->second->data.network_latency_per_locator.find(network_latency.remote_locator) != - participant->second->data.network_latency_per_locator.end() && - network_latency.src_ts <= participant->second->data.network_latency_per_locator[network_latency.remote_locator].back().src_ts) + participant->second->data.network_latency_per_locator.end() && + network_latency.src_ts <= + participant->second->data.network_latency_per_locator[network_latency. + remote_locator].back().src_ts) { break; } @@ -980,10 +984,10 @@ void Database::insert_nts( { const PublicationThroughputSample& publication_throughput = dynamic_cast(sample); - + // Reject samples with old timestamps if (!writer->second->data.publication_throughput.empty() && - publication_throughput.src_ts <= writer->second->data.publication_throughput.back().src_ts) + publication_throughput.src_ts <= writer->second->data.publication_throughput.back().src_ts) { break; } @@ -1010,7 +1014,8 @@ void Database::insert_nts( // Reject samples with old timestamps if (!reader->second->data.subscription_throughput.empty() && - subscription_throughput.src_ts <= reader->second->data.subscription_throughput.back().src_ts) + subscription_throughput.src_ts <= + reader->second->data.subscription_throughput.back().src_ts) { break; } @@ -1034,11 +1039,11 @@ void Database::insert_nts( { const RtpsPacketsSentSample& rtps_packets_sent = dynamic_cast(sample); - // Reject samples with old timestamps - if (participant->second->data.rtps_packets_sent.find(rtps_packets_sent.remote_locator) != - participant->second->data.rtps_packets_sent.end() && - rtps_packets_sent.src_ts <= participant->second->data.last_reported_rtps_packets_sent_count[ - rtps_packets_sent.remote_locator].src_ts) + // Reject samples with old timestamps (unless we are loading last reported) + auto it = participant->second->data.rtps_packets_sent.find(rtps_packets_sent.remote_locator); + if (it != participant->second->data.rtps_packets_sent.end() && + rtps_packets_sent.src_ts <= it->second.back().src_ts && + !(loading && last_reported && rtps_packets_sent.src_ts == it->second.back().src_ts)) { break; } @@ -1094,11 +1099,11 @@ void Database::insert_nts( { const RtpsBytesSentSample& rtps_bytes_sent = dynamic_cast(sample); - // Reject samples with old timestamps - if (participant->second->data.rtps_bytes_sent.find(rtps_bytes_sent.remote_locator) != - participant->second->data.rtps_bytes_sent.end() && - rtps_bytes_sent.src_ts <= participant->second->data.last_reported_rtps_bytes_sent_count[ - rtps_bytes_sent.remote_locator].src_ts) + // Reject samples with old timestamps (unless we are loading last reported) + auto it = participant->second->data.rtps_bytes_sent.find(rtps_bytes_sent.remote_locator); + if (it != participant->second->data.rtps_bytes_sent.end() && + rtps_bytes_sent.src_ts <= it->second.back().src_ts && + !(loading && last_reported && rtps_bytes_sent.src_ts == it->second.back().src_ts)) { break; } @@ -1152,11 +1157,11 @@ void Database::insert_nts( { const RtpsPacketsLostSample& rtps_packets_lost = dynamic_cast(sample); - // Reject samples with old timestamps - if (participant->second->data.rtps_packets_lost.find(rtps_packets_lost.remote_locator) != - participant->second->data.rtps_packets_lost.end() && - rtps_packets_lost.src_ts <= participant->second->data.last_reported_rtps_packets_lost_count[ - rtps_packets_lost.remote_locator].src_ts) + // Reject samples with old timestamps (unless we are loading last reported) + auto it = participant->second->data.rtps_packets_lost.find(rtps_packets_lost.remote_locator); + if (it != participant->second->data.rtps_packets_lost.end() && + rtps_packets_lost.src_ts <= it->second.back().src_ts && + !(loading && last_reported && rtps_packets_lost.src_ts == it->second.back().src_ts)) { break; } @@ -1212,11 +1217,11 @@ void Database::insert_nts( { const RtpsBytesLostSample& rtps_bytes_lost = dynamic_cast(sample); - // Reject samples with old timestamps - if (participant->second->data.rtps_bytes_lost.find(rtps_bytes_lost.remote_locator) != - participant->second->data.rtps_bytes_lost.end() && - rtps_bytes_lost.src_ts <= participant->second->data.last_reported_rtps_bytes_lost_count[ - rtps_bytes_lost.remote_locator].src_ts) + // Reject samples with old timestamps (unless we are loading last reported) + auto it = participant->second->data.rtps_bytes_lost.find(rtps_bytes_lost.remote_locator); + if (it != participant->second->data.rtps_bytes_lost.end() && + rtps_bytes_lost.src_ts <= it->second.back().src_ts && + !(loading && last_reported && rtps_bytes_lost.src_ts == it->second.back().src_ts)) { break; } @@ -1270,9 +1275,11 @@ void Database::insert_nts( { const ResentDataSample& resent_datas = dynamic_cast(sample); - // Reject samples with old timestamps + // Reject samples with old timestamps (unless we are loading last reported) if (!writer->second->data.resent_datas.empty() && - resent_datas.src_ts <= writer->second->data.last_reported_resent_datas.src_ts) + resent_datas.src_ts <= writer->second->data.resent_datas.back().src_ts && + !(loading && last_reported && + resent_datas.src_ts == writer->second->data.resent_datas.back().src_ts)) { break; } @@ -1318,9 +1325,11 @@ void Database::insert_nts( { const HeartbeatCountSample& heartbeat_count = dynamic_cast(sample); - // Reject samples with old timestamps + // Reject samples with old timestamps (unless we are loading last reported) if (!writer->second->data.heartbeat_count.empty() && - heartbeat_count.src_ts <= writer->second->data.last_reported_heartbeat_count.src_ts) + heartbeat_count.src_ts <= writer->second->data.heartbeat_count.back().src_ts && + !(loading && last_reported && + heartbeat_count.src_ts == writer->second->data.heartbeat_count.back().src_ts)) { break; } @@ -1366,9 +1375,11 @@ void Database::insert_nts( { const AcknackCountSample& acknack_count = dynamic_cast(sample); - // Reject samples with old timestamps + // Reject samples with old timestamps (unless we are loading last reported) if (!reader->second->data.acknack_count.empty() && - acknack_count.src_ts <= reader->second->data.last_reported_acknack_count.src_ts) + acknack_count.src_ts <= reader->second->data.acknack_count.back().src_ts && + !(loading && last_reported && + acknack_count.src_ts == reader->second->data.acknack_count.back().src_ts)) { break; } @@ -1414,9 +1425,11 @@ void Database::insert_nts( { const NackfragCountSample& nackfrag_count = dynamic_cast(sample); - // Reject samples with old timestamps + // Reject samples with old timestamps (unless we are loading last reported) if (!reader->second->data.nackfrag_count.empty() && - nackfrag_count.src_ts <= reader->second->data.last_reported_nackfrag_count.src_ts) + nackfrag_count.src_ts <= reader->second->data.nackfrag_count.back().src_ts && + !(loading && last_reported && + nackfrag_count.src_ts == reader->second->data.nackfrag_count.back().src_ts)) { break; } @@ -1462,9 +1475,11 @@ void Database::insert_nts( { const GapCountSample& gap_count = dynamic_cast(sample); - // Reject samples with old timestamps + // Reject samples with old timestamps (unless we are loading last reported) if (!writer->second->data.gap_count.empty() && - gap_count.src_ts <= writer->second->data.last_reported_gap_count.src_ts) + gap_count.src_ts <= writer->second->data.gap_count.back().src_ts && + !(loading && last_reported && + gap_count.src_ts == writer->second->data.gap_count.back().src_ts)) { break; } @@ -1510,9 +1525,11 @@ void Database::insert_nts( { const DataCountSample& data_count = dynamic_cast(sample); - // Reject samples with old timestamps + // Reject samples with old timestamps (unless we are loading last reported) if (!writer->second->data.data_count.empty() && - data_count.src_ts <= writer->second->data.last_reported_data_count.src_ts) + data_count.src_ts <= writer->second->data.data_count.back().src_ts && + !(loading && last_reported && + data_count.src_ts == writer->second->data.data_count.back().src_ts)) { break; } @@ -1558,12 +1575,15 @@ void Database::insert_nts( { const PdpCountSample& pdp_packets = dynamic_cast(sample); - // Reject samples with old timestamps + // Reject samples with old timestamps (unless we are loading last reported) if (!participant->second->data.pdp_packets.empty() && - pdp_packets.src_ts <= participant->second->data.last_reported_pdp_packets.src_ts) + pdp_packets.src_ts <= participant->second->data.pdp_packets.back().src_ts && + !(loading && last_reported && + pdp_packets.src_ts == participant->second->data.pdp_packets.back().src_ts)) { break; } + // Check if the insertion is from the load if (loading) { @@ -1608,7 +1628,9 @@ void Database::insert_nts( // Reject samples with old timestamps if (!participant->second->data.edp_packets.empty() && - edp_packets.src_ts <= participant->second->data.last_reported_edp_packets.src_ts) + edp_packets.src_ts <= participant->second->data.edp_packets.back().src_ts && + !(loading && last_reported && + edp_packets.src_ts == participant->second->data.edp_packets.back().src_ts)) { break; } @@ -1656,8 +1678,10 @@ void Database::insert_nts( // Reject samples with old timestamps if (participant->second->data.discovered_entity.find(discovery_time.remote_entity) != - participant->second->data.discovered_entity.end() && - discovery_time.src_ts <= participant->second->data.discovered_entity[discovery_time.remote_entity].back().src_ts) + participant->second->data.discovered_entity.end() && + discovery_time.src_ts <= + participant->second->data.discovered_entity[discovery_time.remote_entity].back() + .src_ts) { break; } @@ -1683,8 +1707,9 @@ void Database::insert_nts( // Reject samples with old timestamps if (writer->second->data.sample_datas.find(sample_datas.sequence_number) != - writer->second->data.sample_datas.end() && - sample_datas.src_ts <= writer->second->data.sample_datas[sample_datas.sequence_number].back().src_ts) + writer->second->data.sample_datas.end() && + sample_datas.src_ts <= + writer->second->data.sample_datas[sample_datas.sequence_number].back().src_ts) { break; } @@ -1734,10 +1759,10 @@ bool Database::insert_nts( std::dynamic_pointer_cast(entity); std::shared_ptr participant = std::const_pointer_cast( const_participant); - + // Reject samples with old timestamps if (!participant->monitor_service_data.proxy.empty() && - proxy.src_ts <= participant->monitor_service_data.proxy.back().src_ts) + proxy.src_ts <= participant->monitor_service_data.proxy.back().src_ts) { break; } @@ -1753,7 +1778,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datareader->monitor_service_data.proxy.empty() && - proxy.src_ts <= datareader->monitor_service_data.proxy.back().src_ts) + proxy.src_ts <= datareader->monitor_service_data.proxy.back().src_ts) { break; } @@ -1769,7 +1794,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (datawriter->monitor_service_data.proxy.empty() && - proxy.src_ts <= datawriter->monitor_service_data.proxy.back().src_ts) + proxy.src_ts <= datawriter->monitor_service_data.proxy.back().src_ts) { break; } @@ -1799,11 +1824,11 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!participant->monitor_service_data.connection_list.empty() && - connection_list.src_ts <= participant->monitor_service_data.connection_list.back().src_ts) + connection_list.src_ts <= participant->monitor_service_data.connection_list.back().src_ts) { break; } - + participant->monitor_service_data.connection_list.push_back(connection_list); break; } @@ -1815,7 +1840,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datareader->monitor_service_data.connection_list.empty() && - connection_list.src_ts <= datareader->monitor_service_data.connection_list.back().src_ts) + connection_list.src_ts <= datareader->monitor_service_data.connection_list.back().src_ts) { break; } @@ -1831,7 +1856,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datawriter->monitor_service_data.connection_list.empty() && - connection_list.src_ts <= datawriter->monitor_service_data.connection_list.back().src_ts) + connection_list.src_ts <= datawriter->monitor_service_data.connection_list.back().src_ts) { break; } @@ -1860,7 +1885,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datareader->monitor_service_data.incompatible_qos.empty() && - incompatible_qos.src_ts <= datareader->monitor_service_data.incompatible_qos.back().src_ts) + incompatible_qos.src_ts <= datareader->monitor_service_data.incompatible_qos.back().src_ts) { break; } @@ -1877,7 +1902,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datawriter->monitor_service_data.incompatible_qos.empty() && - incompatible_qos.src_ts <= datawriter->monitor_service_data.incompatible_qos.back().src_ts) + incompatible_qos.src_ts <= datawriter->monitor_service_data.incompatible_qos.back().src_ts) { break; } @@ -1907,7 +1932,8 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datareader->monitor_service_data.inconsistent_topic.empty() && - inconsistent_topic.src_ts <= datareader->monitor_service_data.inconsistent_topic.back().src_ts) + inconsistent_topic.src_ts <= + datareader->monitor_service_data.inconsistent_topic.back().src_ts) { break; } @@ -1924,7 +1950,8 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datawriter->monitor_service_data.inconsistent_topic.empty() && - inconsistent_topic.src_ts <= datawriter->monitor_service_data.inconsistent_topic.back().src_ts) + inconsistent_topic.src_ts <= + datawriter->monitor_service_data.inconsistent_topic.back().src_ts) { break; } @@ -1953,7 +1980,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datawriter->monitor_service_data.liveliness_lost.empty() && - liveliness_lost.src_ts <= datawriter->monitor_service_data.liveliness_lost.back().src_ts) + liveliness_lost.src_ts <= datawriter->monitor_service_data.liveliness_lost.back().src_ts) { break; } @@ -1980,7 +2007,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datareader->monitor_service_data.liveliness_changed.empty() && - liveliness_changed.src_ts <= datareader->monitor_service_data.liveliness_changed.back().src_ts) + liveliness_changed.src_ts <= datareader->monitor_service_data.liveliness_changed.back().src_ts) { break; } @@ -2008,7 +2035,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datareader->monitor_service_data.deadline_missed.empty() && - deadline_missed.src_ts <= datareader->monitor_service_data.deadline_missed.back().src_ts) + deadline_missed.src_ts <= datareader->monitor_service_data.deadline_missed.back().src_ts) { break; } @@ -2025,7 +2052,7 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datawriter->monitor_service_data.deadline_missed.empty() && - deadline_missed.src_ts <= datawriter->monitor_service_data.deadline_missed.back().src_ts) + deadline_missed.src_ts <= datawriter->monitor_service_data.deadline_missed.back().src_ts) { break; } @@ -2053,11 +2080,11 @@ bool Database::insert_nts( // Reject samples with old timestamps if (!datareader->monitor_service_data.sample_lost.empty() && - sample_lost.src_ts <= datareader->monitor_service_data.sample_lost.back().src_ts) + sample_lost.src_ts <= datareader->monitor_service_data.sample_lost.back().src_ts) { break; } - + datareader->monitor_service_data.sample_lost.push_back(sample_lost); entity_updated = update_entity_status_nts(datareader); break; diff --git a/test/unittest/Database/DatabaseTests.cpp b/test/unittest/Database/DatabaseTests.cpp index 63c6faf5f..1910df4bc 100644 --- a/test/unittest/Database/DatabaseTests.cpp +++ b/test/unittest/Database/DatabaseTests.cpp @@ -1823,6 +1823,13 @@ TEST_F(database_tests, insert_sample_history_latency) ASSERT_EQ(writer->data.history2history_latency[reader_id].size(), 2u); ASSERT_EQ(writer->data.history2history_latency[reader_id][0], static_cast(sample)); ASSERT_EQ(writer->data.history2history_latency[reader_id][1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->data.history2history_latency[reader_id].size(), 2u); + ASSERT_EQ(writer->data.history2history_latency[reader_id][0], static_cast(sample)); + ASSERT_EQ(writer->data.history2history_latency[reader_id][1], static_cast(sample_2)); + } TEST_F(database_tests, insert_sample_history_latency_wrong_entity) @@ -1852,6 +1859,14 @@ TEST_F(database_tests, insert_sample_network_latency) static_cast(sample)); ASSERT_EQ(participant->data.network_latency_per_locator[reader_locator->id][1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->data.network_latency_per_locator[reader_locator->id].size(), 2u); + ASSERT_EQ(participant->data.network_latency_per_locator[reader_locator->id][0], + static_cast(sample)); + ASSERT_EQ(participant->data.network_latency_per_locator[reader_locator->id][1], + static_cast(sample_2)); } TEST_F(database_tests, insert_sample_network_latency_wrong_entity) @@ -1877,6 +1892,12 @@ TEST_F(database_tests, insert_sample_publication_throughput) ASSERT_EQ(writer->data.publication_throughput.size(), 2u); ASSERT_EQ(writer->data.publication_throughput[0], static_cast(sample)); ASSERT_EQ(writer->data.publication_throughput[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->data.publication_throughput.size(), 2u); + ASSERT_EQ(writer->data.publication_throughput[0], static_cast(sample)); + ASSERT_EQ(writer->data.publication_throughput[1], static_cast(sample_2)); } TEST_F(database_tests, insert_sample_publication_throughput_wrong_entity) @@ -1901,6 +1922,12 @@ TEST_F(database_tests, insert_sample_subscription_throughput) ASSERT_EQ(reader->data.subscription_throughput.size(), 2u); ASSERT_EQ(reader->data.subscription_throughput[0], static_cast(sample)); ASSERT_EQ(reader->data.subscription_throughput[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, reader_id, sample_2)); + ASSERT_EQ(reader->data.subscription_throughput.size(), 2u); + ASSERT_EQ(reader->data.subscription_throughput[0], static_cast(sample)); + ASSERT_EQ(reader->data.subscription_throughput[1], static_cast(sample_2)); } TEST_F(database_tests, insert_sample_subscription_throughput_wrong_entity) @@ -1931,6 +1958,14 @@ TEST_F(database_tests, insert_sample_rtps_packets_sent) static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(participant->data.last_reported_rtps_packets_sent_count[writer_locator->id].count, sample_2.count); + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->data.rtps_packets_sent.size(), 1u); + ASSERT_EQ(participant->data.rtps_packets_sent[writer_locator->id].size(), 2u); + ASSERT_EQ(participant->data.rtps_packets_sent[writer_locator->id][0], static_cast(sample)); + ASSERT_EQ(participant->data.rtps_packets_sent[writer_locator->id][1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(participant->data.last_reported_rtps_packets_sent_count[writer_locator->id].count, sample_2.count); } TEST_F(database_tests, insert_sample_rtps_packets_sent_wrong_entity) @@ -1982,6 +2017,17 @@ TEST_F(database_tests, insert_sample_rtps_bytes_sent) ASSERT_EQ(participant->data.last_reported_rtps_bytes_sent_count[writer_locator->id].magnitude_order, sample_2.magnitude_order); ASSERT_EQ(participant->data.last_reported_rtps_bytes_sent_count[writer_locator->id].count, sample_2.count); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->data.rtps_bytes_sent.size(), 1u); + ASSERT_EQ(participant->data.rtps_bytes_sent[writer_locator->id].size(), 2u); + ASSERT_EQ(participant->data.rtps_bytes_sent[writer_locator->id][0], static_cast(sample)); + ASSERT_EQ(participant->data.rtps_bytes_sent[writer_locator->id][1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(participant->data.last_reported_rtps_bytes_sent_count[writer_locator->id].magnitude_order, + sample_2.magnitude_order); + ASSERT_EQ(participant->data.last_reported_rtps_bytes_sent_count[writer_locator->id].count, sample_2.count); } TEST_F(database_tests, insert_sample_rtps_bytes_sent_wrong_entity) @@ -2032,6 +2078,15 @@ TEST_F(database_tests, insert_sample_rtps_packets_lost) ASSERT_EQ(participant->data.rtps_packets_lost[writer_locator->id][1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(participant->data.last_reported_rtps_packets_lost_count[writer_locator->id].count, sample_2.count); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->data.rtps_packets_lost.size(), 1u); + ASSERT_EQ(participant->data.rtps_packets_lost[writer_locator->id].size(), 2u); + ASSERT_EQ(participant->data.rtps_packets_lost[writer_locator->id][0], static_cast(sample)); + ASSERT_EQ(participant->data.rtps_packets_lost[writer_locator->id][1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(participant->data.last_reported_rtps_packets_lost_count[writer_locator->id].count, sample_2.count); } TEST_F(database_tests, insert_sample_rtps_packets_lost_wrong_entity) @@ -2083,6 +2138,17 @@ TEST_F(database_tests, insert_sample_rtps_bytes_lost) ASSERT_EQ(participant->data.last_reported_rtps_bytes_lost_count[writer_locator->id].magnitude_order, sample_2.magnitude_order); ASSERT_EQ(participant->data.last_reported_rtps_bytes_lost_count[writer_locator->id].count, sample_2.count); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->data.rtps_bytes_lost.size(), 1u); + ASSERT_EQ(participant->data.rtps_bytes_lost[writer_locator->id].size(), 2u); + ASSERT_EQ(participant->data.rtps_bytes_lost[writer_locator->id][0], static_cast(sample)); + ASSERT_EQ(participant->data.rtps_bytes_lost[writer_locator->id][1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(participant->data.last_reported_rtps_bytes_lost_count[writer_locator->id].magnitude_order, + sample_2.magnitude_order); + ASSERT_EQ(participant->data.last_reported_rtps_bytes_lost_count[writer_locator->id].count, sample_2.count); } TEST_F(database_tests, insert_sample_rtps_bytes_lost_wrong_entity) @@ -2130,6 +2196,14 @@ TEST_F(database_tests, insert_sample_resent_data) ASSERT_EQ(writer->data.resent_datas[1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(writer->data.last_reported_resent_datas, sample_2); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->data.resent_datas.size(), 2u); + ASSERT_EQ(writer->data.resent_datas[0], static_cast(sample)); + ASSERT_EQ(writer->data.resent_datas[1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(writer->data.last_reported_resent_datas, sample_2); } TEST_F(database_tests, insert_sample_resent_data_wrong_entity) @@ -2156,6 +2230,14 @@ TEST_F(database_tests, insert_sample_heartbeat_count) ASSERT_EQ(writer->data.heartbeat_count[1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(writer->data.last_reported_heartbeat_count, sample_2); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->data.heartbeat_count.size(), 2u); + ASSERT_EQ(writer->data.heartbeat_count[0], static_cast(sample)); + ASSERT_EQ(writer->data.heartbeat_count[1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(writer->data.last_reported_heartbeat_count, sample_2); } TEST_F(database_tests, insert_sample_heartbeat_count_wrong_entity) @@ -2182,6 +2264,14 @@ TEST_F(database_tests, insert_sample_acknack_count) ASSERT_EQ(reader->data.acknack_count[1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(reader->data.last_reported_acknack_count, sample_2); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, reader_id, sample_2)); + ASSERT_EQ(reader->data.acknack_count.size(), 2u); + ASSERT_EQ(reader->data.acknack_count[0], static_cast(sample)); + ASSERT_EQ(reader->data.acknack_count[1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(reader->data.last_reported_acknack_count, sample_2); } TEST_F(database_tests, insert_sample_acknack_count_wrong_entity) @@ -2208,6 +2298,14 @@ TEST_F(database_tests, insert_sample_nackfrag_count) ASSERT_EQ(reader->data.nackfrag_count[1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(reader->data.last_reported_nackfrag_count, sample_2); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, reader_id, sample_2)); + ASSERT_EQ(reader->data.nackfrag_count.size(), 2u); + ASSERT_EQ(reader->data.nackfrag_count[0], static_cast(sample)); + ASSERT_EQ(reader->data.nackfrag_count[1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(reader->data.last_reported_nackfrag_count, sample_2); } TEST_F(database_tests, insert_sample_nackfrag_count_wrong_entity) @@ -2234,6 +2332,14 @@ TEST_F(database_tests, insert_sample_gap_count) ASSERT_EQ(writer->data.gap_count[1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(writer->data.last_reported_gap_count, sample_2); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->data.gap_count.size(), 2u); + ASSERT_EQ(writer->data.gap_count[0], static_cast(sample)); + ASSERT_EQ(writer->data.gap_count[1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(writer->data.last_reported_gap_count, sample_2); } TEST_F(database_tests, insert_sample_gap_count_wrong_entity) @@ -2260,6 +2366,14 @@ TEST_F(database_tests, insert_sample_data_count) ASSERT_EQ(writer->data.data_count[1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(writer->data.last_reported_data_count, sample_2); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->data.data_count.size(), 2u); + ASSERT_EQ(writer->data.data_count[0], static_cast(sample)); + ASSERT_EQ(writer->data.data_count[1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(writer->data.last_reported_data_count, sample_2); } TEST_F(database_tests, insert_sample_data_count_wrong_entity) @@ -2286,6 +2400,14 @@ TEST_F(database_tests, insert_sample_pdp_packets) ASSERT_EQ(participant->data.pdp_packets[1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(participant->data.last_reported_pdp_packets, sample_2); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->data.pdp_packets.size(), 2u); + ASSERT_EQ(participant->data.pdp_packets[0], static_cast(sample)); + ASSERT_EQ(participant->data.pdp_packets[1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(participant->data.last_reported_pdp_packets, sample_2); } TEST_F(database_tests, insert_sample_pdp_packets_wrong_entity) @@ -2312,6 +2434,14 @@ TEST_F(database_tests, insert_sample_edp_packets) ASSERT_EQ(participant->data.edp_packets[1], static_cast(sample_2) - static_cast(sample)); ASSERT_EQ(participant->data.last_reported_edp_packets, sample_2); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->data.edp_packets.size(), 2u); + ASSERT_EQ(participant->data.edp_packets[0], static_cast(sample)); + ASSERT_EQ(participant->data.edp_packets[1], + static_cast(sample_2) - static_cast(sample)); + ASSERT_EQ(participant->data.last_reported_edp_packets, sample_2); } TEST_F(database_tests, insert_sample_edp_packets_wrong_entity) @@ -2341,6 +2471,13 @@ TEST_F(database_tests, insert_sample_discovery_time) ASSERT_EQ(participant->data.discovered_entity[writer_id].size(), 2u); ASSERT_EQ(participant->data.discovered_entity[writer_id][0], static_cast(sample)); ASSERT_EQ(participant->data.discovered_entity[writer_id][1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->data.discovered_entity.size(), 1u); + ASSERT_EQ(participant->data.discovered_entity[writer_id].size(), 2u); + ASSERT_EQ(participant->data.discovered_entity[writer_id][0], static_cast(sample)); + ASSERT_EQ(participant->data.discovered_entity[writer_id][1], static_cast(sample_2)); } TEST_F(database_tests, insert_sample_discovery_time_wrong_entity) @@ -2380,6 +2517,12 @@ TEST_F(database_tests, insert_sample_sample_datas) ASSERT_EQ(writer->data.sample_datas.size(), 2u); ASSERT_EQ(writer->data.sample_datas[sample.sequence_number].size(), 1u); ASSERT_EQ(writer->data.sample_datas[sample.sequence_number][0], static_cast(sample_3)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_3)); + ASSERT_EQ(writer->data.sample_datas.size(), 2u); + ASSERT_EQ(writer->data.sample_datas[sample.sequence_number].size(), 1u); + ASSERT_EQ(writer->data.sample_datas[sample.sequence_number][0], static_cast(sample_3)); } TEST_F(database_tests, insert_sample_sample_datas_wrong_entity) @@ -2482,6 +2625,14 @@ TEST_F(database_tests, insert_monitor_service_sample_proxy) ASSERT_EQ(reader->monitor_service_data.proxy.size(), 1u); ASSERT_EQ(participant->monitor_service_data.proxy[0], static_cast(sample)); ASSERT_EQ(participant->monitor_service_data.proxy[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->monitor_service_data.proxy.size(), 2u); + ASSERT_EQ(writer->monitor_service_data.proxy.size(), 1u); + ASSERT_EQ(reader->monitor_service_data.proxy.size(), 1u); + ASSERT_EQ(participant->monitor_service_data.proxy[0], static_cast(sample)); + ASSERT_EQ(participant->monitor_service_data.proxy[1], static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_proxy_wrong_entity) @@ -2558,6 +2709,14 @@ TEST_F(database_tests, insert_monitor_service_sample_connection_list) ASSERT_EQ(reader->monitor_service_data.connection_list.size(), 1u); ASSERT_EQ(participant->monitor_service_data.connection_list[0], static_cast(sample)); ASSERT_EQ(participant->monitor_service_data.connection_list[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, participant_id, sample_2)); + ASSERT_EQ(participant->monitor_service_data.connection_list.size(), 2u); + ASSERT_EQ(writer->monitor_service_data.connection_list.size(), 1u); + ASSERT_EQ(reader->monitor_service_data.connection_list.size(), 1u); + ASSERT_EQ(participant->monitor_service_data.connection_list[0], static_cast(sample)); + ASSERT_EQ(participant->monitor_service_data.connection_list[1], static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_connection_list_wrong_entity) @@ -2630,6 +2789,13 @@ TEST_F(database_tests, insert_monitor_service_sample_incompatible_qos) ASSERT_EQ(reader->monitor_service_data.incompatible_qos.size(), 1u); ASSERT_EQ(writer->monitor_service_data.incompatible_qos[0], static_cast(sample)); ASSERT_EQ(writer->monitor_service_data.incompatible_qos[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->monitor_service_data.incompatible_qos.size(), 2u); + ASSERT_EQ(reader->monitor_service_data.incompatible_qos.size(), 1u); + ASSERT_EQ(writer->monitor_service_data.incompatible_qos[0], static_cast(sample)); + ASSERT_EQ(writer->monitor_service_data.incompatible_qos[1], static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_incompatible_qos_wrong_entity) @@ -2680,6 +2846,13 @@ TEST_F(database_tests, insert_monitor_service_sample_inconsistent_topic) ASSERT_EQ(reader->monitor_service_data.inconsistent_topic.size(), 1u); ASSERT_EQ(writer->monitor_service_data.inconsistent_topic[0], static_cast(sample)); ASSERT_EQ(writer->monitor_service_data.inconsistent_topic[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->monitor_service_data.inconsistent_topic.size(), 2u); + ASSERT_EQ(reader->monitor_service_data.inconsistent_topic.size(), 1u); + ASSERT_EQ(writer->monitor_service_data.inconsistent_topic[0], static_cast(sample)); + ASSERT_EQ(writer->monitor_service_data.inconsistent_topic[1], static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_inconsistent_topic_wrong_entity) @@ -2721,6 +2894,12 @@ TEST_F(database_tests, insert_monitor_service_sample_liveliness_lost) ASSERT_EQ(writer->monitor_service_data.liveliness_lost.size(), 2u); ASSERT_EQ(writer->monitor_service_data.liveliness_lost[0], static_cast(sample)); ASSERT_EQ(writer->monitor_service_data.liveliness_lost[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->monitor_service_data.liveliness_lost.size(), 2u); + ASSERT_EQ(writer->monitor_service_data.liveliness_lost[0], static_cast(sample)); + ASSERT_EQ(writer->monitor_service_data.liveliness_lost[1], static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_liveliness_lost_wrong_entity) @@ -2766,6 +2945,12 @@ TEST_F(database_tests, insert_monitor_service_sample_liveliness_changed) ASSERT_EQ(reader->monitor_service_data.liveliness_changed.size(), 2u); ASSERT_EQ(reader->monitor_service_data.liveliness_changed[0], static_cast(sample)); ASSERT_EQ(reader->monitor_service_data.liveliness_changed[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, reader_id, sample_2)); + ASSERT_EQ(reader->monitor_service_data.liveliness_changed.size(), 2u); + ASSERT_EQ(reader->monitor_service_data.liveliness_changed[0], static_cast(sample)); + ASSERT_EQ(reader->monitor_service_data.liveliness_changed[1], static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_liveliness_changed_wrong_entity) @@ -2813,6 +2998,13 @@ TEST_F(database_tests, insert_monitor_service_sample_deadline_missed) ASSERT_EQ(reader->monitor_service_data.deadline_missed.size(), 1u); ASSERT_EQ(writer->monitor_service_data.deadline_missed[0], static_cast(sample)); ASSERT_EQ(writer->monitor_service_data.deadline_missed[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, writer_id, sample_2)); + ASSERT_EQ(writer->monitor_service_data.deadline_missed.size(), 2u); + ASSERT_EQ(reader->monitor_service_data.deadline_missed.size(), 1u); + ASSERT_EQ(writer->monitor_service_data.deadline_missed[0], static_cast(sample)); + ASSERT_EQ(writer->monitor_service_data.deadline_missed[1], static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_deadline_missed_wrong_entity) @@ -2855,6 +3047,12 @@ TEST_F(database_tests, insert_monitor_service_sample_sample_lost) ASSERT_EQ(reader->monitor_service_data.sample_lost.size(), 2u); ASSERT_EQ(reader->monitor_service_data.sample_lost[0], static_cast(sample)); ASSERT_EQ(reader->monitor_service_data.sample_lost[1], static_cast(sample_2)); + + // Insert old sample - should not be inserted + ASSERT_NO_THROW(db.insert(domain_id, reader_id, sample_2)); + ASSERT_EQ(reader->monitor_service_data.sample_lost.size(), 2u); + ASSERT_EQ(reader->monitor_service_data.sample_lost[0], static_cast(sample)); + ASSERT_EQ(reader->monitor_service_data.sample_lost[1], static_cast(sample_2)); } TEST_F(database_tests, insert_monitor_service_sample_sample_lost_wrong_entity)