|
15 | 15 | #include <array>
|
16 | 16 | #include <cassert>
|
17 | 17 | #include <chrono>
|
| 18 | +#include <cstdint> |
18 | 19 | #include <forward_list>
|
19 | 20 | #include <iostream>
|
20 | 21 | #include <memory>
|
21 | 22 | #include <sstream>
|
22 | 23 | #include <thread>
|
23 | 24 | #include <type_traits>
|
24 | 25 |
|
| 26 | +#include <asio.hpp> |
| 27 | + |
25 | 28 | #include <gmock/gmock.h>
|
26 | 29 | #include <gtest/gtest.h>
|
27 | 30 |
|
28 | 31 | #include <fastcdr/Cdr.h>
|
29 | 32 |
|
30 | 33 | #include <fastdds/dds/builtin/topic/PublicationBuiltinTopicData.hpp>
|
31 |
| - |
| 34 | +#include <fastdds/dds/core/condition/WaitSet.hpp> |
32 | 35 | #include <fastdds/dds/core/Entity.hpp>
|
33 | 36 | #include <fastdds/dds/core/LoanableArray.hpp>
|
34 | 37 | #include <fastdds/dds/core/LoanableCollection.hpp>
|
35 | 38 | #include <fastdds/dds/core/LoanableSequence.hpp>
|
36 | 39 | #include <fastdds/dds/core/StackAllocatedSequence.hpp>
|
37 |
| -#include <fastdds/dds/core/condition/WaitSet.hpp> |
38 | 40 | #include <fastdds/dds/core/status/BaseStatus.hpp>
|
39 | 41 | #include <fastdds/dds/core/status/SampleRejectedStatus.hpp>
|
40 | 42 | #include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
|
41 |
| - |
42 |
| -#include <fastdds/dds/domain/DomainParticipantFactory.hpp> |
43 | 43 | #include <fastdds/dds/domain/DomainParticipant.hpp>
|
| 44 | +#include <fastdds/dds/domain/DomainParticipantFactory.hpp> |
44 | 45 | #include <fastdds/dds/domain/DomainParticipantListener.hpp>
|
45 |
| - |
| 46 | +#include <fastdds/dds/log/Log.hpp> |
46 | 47 | #include <fastdds/dds/publisher/DataWriter.hpp>
|
47 | 48 | #include <fastdds/dds/publisher/Publisher.hpp>
|
48 | 49 | #include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
|
49 | 50 | #include <fastdds/dds/publisher/qos/PublisherQos.hpp>
|
50 |
| - |
51 | 51 | #include <fastdds/dds/subscriber/DataReader.hpp>
|
52 | 52 | #include <fastdds/dds/subscriber/DataReaderListener.hpp>
|
53 |
| -#include <fastdds/dds/subscriber/SampleInfo.hpp> |
54 |
| -#include <fastdds/dds/subscriber/Subscriber.hpp> |
55 | 53 | #include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
|
56 | 54 | #include <fastdds/dds/subscriber/qos/SubscriberQos.hpp>
|
57 |
| - |
| 55 | +#include <fastdds/dds/subscriber/SampleInfo.hpp> |
| 56 | +#include <fastdds/dds/subscriber/Subscriber.hpp> |
58 | 57 | #include <fastdds/rtps/common/Locator.h>
|
59 |
| -#include <fastrtps/utils/IPLocator.h> |
60 |
| - |
61 |
| -#include "FooBoundedType.hpp" |
62 |
| -#include "FooBoundedTypeSupport.hpp" |
63 |
| - |
64 |
| -#include "FooType.hpp" |
65 |
| -#include "FooTypeSupport.hpp" |
66 |
| - |
67 |
| -#include "../../logging/mock/MockConsumer.h" |
68 |
| - |
69 | 58 | #include <fastdds/rtps/transport/test_UDPv4TransportDescriptor.h>
|
| 59 | +#include <fastrtps/utils/IPLocator.h> |
70 | 60 | #include <fastrtps/xmlparser/XMLProfileManager.h>
|
71 | 61 |
|
72 | 62 | #include "../../common/CustomPayloadPool.hpp"
|
| 63 | +#include "../../logging/mock/MockConsumer.h" |
73 | 64 | #include "fastdds/dds/common/InstanceHandle.hpp"
|
74 | 65 | #include "fastdds/dds/core/policy/QosPolicies.hpp"
|
75 |
| - |
76 |
| -#include <asio.hpp> |
| 66 | +#include "FooBoundedType.hpp" |
| 67 | +#include "FooBoundedTypeSupport.hpp" |
| 68 | +#include "FooType.hpp" |
| 69 | +#include "FooTypeSupport.hpp" |
77 | 70 |
|
78 | 71 | #if defined(__cplusplus_winrt)
|
79 | 72 | #define GET_PID GetCurrentProcessId
|
@@ -711,9 +704,13 @@ TEST_F(DataReaderTests, InvalidQos)
|
711 | 704 | qos.history().kind = KEEP_LAST_HISTORY_QOS;
|
712 | 705 | qos.history().depth = 0;
|
713 | 706 | EXPECT_EQ(inconsistent_code, data_reader_->set_qos(qos)); // KEEP LAST 0 is inconsistent
|
714 |
| - qos.history().depth = 2; |
715 |
| - qos.resource_limits().max_samples_per_instance = 1; |
716 |
| - EXPECT_EQ(inconsistent_code, data_reader_->set_qos(qos)); // KEEP LAST 2 but max_samples_per_instance 1 is inconsistent |
| 707 | + // KEEP LAST 2000 but max_samples_per_instance default (400) is inconsistent but right now it only shows a warning |
| 708 | + // In the reader, this returns RETCODE_INMUTABLE_POLICY, because the depth cannot be changed on run time. |
| 709 | + // Because of the implementation, we know de consistency is checked before the inmutability, so by checking the |
| 710 | + // return against RETCODE_INMUTABLE_POLICY we are testing that the setting are not considered inconsistent yet. |
| 711 | + // This test will fail whenever we enforce the consistency between depth and max_samples_per_instance. |
| 712 | + qos.history().depth = 2000; |
| 713 | + EXPECT_EQ(ReturnCode_t::RETCODE_IMMUTABLE_POLICY, data_reader_->set_qos(qos)); |
717 | 714 |
|
718 | 715 | /* Inmutable QoS */
|
719 | 716 | const ReturnCode_t inmutable_code = ReturnCode_t::RETCODE_IMMUTABLE_POLICY;
|
@@ -3655,6 +3652,71 @@ TEST_F(DataReaderTests, UpdateInmutableQos)
|
3655 | 3652 | DomainParticipantFactory::get_instance()->delete_participant(participant);
|
3656 | 3653 | }
|
3657 | 3654 |
|
| 3655 | +TEST_F(DataReaderTests, history_depth_max_samples_per_instance_warning) |
| 3656 | +{ |
| 3657 | + |
| 3658 | + /* Setup log so it may catch the expected warning */ |
| 3659 | + Log::ClearConsumers(); |
| 3660 | + MockConsumer* mockConsumer = new MockConsumer("RTPS_QOS_CHECK"); |
| 3661 | + Log::RegisterConsumer(std::unique_ptr<LogConsumer>(mockConsumer)); |
| 3662 | + Log::SetVerbosity(Log::Warning); |
| 3663 | + |
| 3664 | + /* Create a participant, topic, and a subscriber */ |
| 3665 | + DomainParticipant* participant = DomainParticipantFactory::get_instance()->create_participant(0, |
| 3666 | + PARTICIPANT_QOS_DEFAULT); |
| 3667 | + ASSERT_NE(participant, nullptr); |
| 3668 | + |
| 3669 | + TypeSupport type(new FooTypeSupport()); |
| 3670 | + type.register_type(participant); |
| 3671 | + |
| 3672 | + Topic* topic = participant->create_topic("footopic", type.get_type_name(), TOPIC_QOS_DEFAULT); |
| 3673 | + ASSERT_NE(topic, nullptr); |
| 3674 | + |
| 3675 | + Subscriber* subscriber = participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT); |
| 3676 | + ASSERT_NE(subscriber, nullptr); |
| 3677 | + |
| 3678 | + /* Create a datareader with the QoS that should generate a warning */ |
| 3679 | + DataReaderQos qos; |
| 3680 | + qos.history().depth = 10; |
| 3681 | + qos.resource_limits().max_samples_per_instance = 5; |
| 3682 | + DataReader* datareader_1 = subscriber->create_datareader(topic, qos); |
| 3683 | + ASSERT_NE(datareader_1, nullptr); |
| 3684 | + |
| 3685 | + /* Check that the config generated a warning */ |
| 3686 | + auto wait_for_log_entries = |
| 3687 | + [&mockConsumer](const uint32_t amount, const uint32_t retries, const uint32_t wait_ms) -> size_t |
| 3688 | + { |
| 3689 | + size_t entries = 0; |
| 3690 | + for (uint32_t i = 0; i < retries; i++) |
| 3691 | + { |
| 3692 | + entries = mockConsumer->ConsumedEntries().size(); |
| 3693 | + if (entries >= amount) |
| 3694 | + { |
| 3695 | + break; |
| 3696 | + } |
| 3697 | + std::this_thread::sleep_for(std::chrono::milliseconds(wait_ms)); |
| 3698 | + } |
| 3699 | + return entries; |
| 3700 | + }; |
| 3701 | + |
| 3702 | + const size_t expected_entries = 1; |
| 3703 | + const uint32_t retries = 4; |
| 3704 | + const uint32_t wait_ms = 25; |
| 3705 | + ASSERT_EQ(wait_for_log_entries(expected_entries, retries, wait_ms), expected_entries); |
| 3706 | + |
| 3707 | + /* Check that a correctly initialized datareader does not produce any warning */ |
| 3708 | + qos.history().depth = 10; |
| 3709 | + qos.resource_limits().max_samples_per_instance = 10; |
| 3710 | + DataReader* datareader_2 = subscriber->create_datareader(topic, qos); |
| 3711 | + ASSERT_NE(datareader_2, nullptr); |
| 3712 | + ASSERT_EQ(wait_for_log_entries(expected_entries, retries, wait_ms), expected_entries); |
| 3713 | + |
| 3714 | + /* Tear down */ |
| 3715 | + participant->delete_contained_entities(); |
| 3716 | + DomainParticipantFactory::get_instance()->delete_participant(participant); |
| 3717 | + Log::KillThread(); |
| 3718 | +} |
| 3719 | + |
3658 | 3720 | int main(
|
3659 | 3721 | int argc,
|
3660 | 3722 | char** argv)
|
|
0 commit comments