diff options
author | Anton Hrytsevich <ahrytsevich> | 2016-02-02 17:17:55 +0200 |
---|---|---|
committer | Andrey Oleynik <aoleynik@luxoft.com> | 2016-05-13 17:42:46 +0300 |
commit | a78c047a20408a67365a7c3b292a4fc75329a8f8 (patch) | |
tree | 6f11f5dced688c9e045cc47f24edc19d6fd62f80 | |
parent | 004a16c580640557e6aabb817ca68ba25d94fb56 (diff) | |
download | sdl_core-a78c047a20408a67365a7c3b292a4fc75329a8f8.tar.gz |
Fixes retry sequence implementation
Adopts changes done originally regaring issue: [APPLINK-19543]
Closes-bug: APPLINK-24295
8 files changed, 235 insertions, 167 deletions
diff --git a/src/components/application_manager/include/application_manager/policies/policy_handler.h b/src/components/application_manager/include/application_manager/policies/policy_handler.h index 1676331fbc..1fb7d68d25 100644 --- a/src/components/application_manager/include/application_manager/policies/policy_handler.h +++ b/src/components/application_manager/include/application_manager/policies/policy_handler.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Ford Motor Company + Copyright (c) 2016, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -37,6 +37,7 @@ #include <map> #include <set> #include <vector> +#include <cstdint> #include "policy/policy_manager.h" #include "application_manager/policies/policy_event_observer.h" #include "application_manager/policies/delegates/statistics_delegate.h" @@ -82,7 +83,7 @@ public: virtual void OnPermissionsUpdated(const std::string &policy_app_id, const Permissions &permissions); - virtual void OnSnapshotCreated(const BinaryMessage &pt_string); + void OnSnapshotCreated(const BinaryMessage &pt_string) OVERRIDE; bool GetPriority(const std::string &policy_app_id, std::string *priority); void CheckPermissions(const PTString &app_id, const PTString &hmi_level, @@ -101,7 +102,7 @@ public: std::string GetLockScreenIconUrl() const; void ResetRetrySequence(); - int NextRetryTimeout(); + uint32_t NextRetryTimeout(); int TimeoutExchange(); void OnExceededTimeout(); void OnSystemReady(); @@ -230,7 +231,7 @@ public: /** * @brief Send request to HMI to get update on system parameters */ - virtual void OnSystemInfoUpdateRequired(); + void OnSystemInfoUpdateRequired() OVERRIDE; /** * @brief Sends GetVehicleData request in case when Vechicle info is ready. @@ -269,19 +270,19 @@ public: std::string GetAppName(const std::string &policy_app_id); - virtual void - OnUpdateHMIAppType(std::map<std::string, StringArray> app_hmi_types); + void + OnUpdateHMIAppType(std::map<std::string, StringArray> app_hmi_types) OVERRIDE; - virtual void OnCertificateUpdated(const std::string &certificate_data); + void OnCertificateUpdated(const std::string &certificate_data) OVERRIDE; - virtual bool CanUpdate(); + bool CanUpdate() OVERRIDE; - virtual void OnDeviceConsentChanged(const std::string &device_id, - bool is_allowed); + void OnDeviceConsentChanged(const std::string &device_id, + bool is_allowed) OVERRIDE; virtual void OnPTExchangeNeeded(); - virtual void GetAvailableApps(std::queue<std::string> &apps); + void GetAvailableApps(std::queue<std::string> &apps) OVERRIDE; /** * @brief Allows to add new or update existed application during diff --git a/src/components/application_manager/src/policies/policy_handler.cc b/src/components/application_manager/src/policies/policy_handler.cc index 99750aaccc..8732a122c5 100644 --- a/src/components/application_manager/src/policies/policy_handler.cc +++ b/src/components/application_manager/src/policies/policy_handler.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2014, Ford Motor Company + Copyright (c) 2016, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -1066,7 +1066,7 @@ void PolicyHandler::ResetRetrySequence() { policy_manager_->ResetRetrySequence(); } -int PolicyHandler::NextRetryTimeout() { +uint32_t PolicyHandler::NextRetryTimeout() { POLICY_LIB_CHECK(0); return policy_manager_->NextRetryTimeout(); } diff --git a/src/components/policy/src/policy/include/policy/policy_listener.h b/src/components/policy/src/policy/include/policy/policy_listener.h index 332b50521d..9046af4201 100644 --- a/src/components/policy/src/policy/include/policy/policy_listener.h +++ b/src/components/policy/src/policy/include/policy/policy_listener.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Ford Motor Company + Copyright (c) 2016, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -39,29 +39,29 @@ namespace policy { class PolicyListener { - public: - virtual ~PolicyListener() { - } - virtual void OnPermissionsUpdated(const std::string& policy_app_id, - const Permissions& permissions, - const policy::HMILevel& default_hmi) = 0; - virtual void OnPermissionsUpdated(const std::string& policy_app_id, - const Permissions& permissions) = 0; - virtual void OnPendingPermissionChange(const std::string& policy_app_id) = 0; - virtual void OnUpdateStatusChanged(const std::string&) = 0; - virtual std::string OnCurrentDeviceIdUpdateRequired( - const std::string& policy_app_id) = 0; +public: + virtual ~PolicyListener() {} + virtual void OnPermissionsUpdated(const std::string &policy_app_id, + const Permissions &permissions, + const policy::HMILevel &default_hmi) = 0; + virtual void OnPermissionsUpdated(const std::string &policy_app_id, + const Permissions &permissions) = 0; + virtual void OnPendingPermissionChange(const std::string &policy_app_id) = 0; + virtual void OnUpdateStatusChanged(const std::string &) = 0; + virtual std::string + OnCurrentDeviceIdUpdateRequired(const std::string &policy_app_id) = 0; virtual void OnSystemInfoUpdateRequired() = 0; - virtual std::string GetAppName(const std::string& policy_app_id) = 0; - virtual void OnUpdateHMIAppType(std::map<std::string, StringArray> app_hmi_types) = 0; + virtual std::string GetAppName(const std::string &policy_app_id) = 0; + virtual void + OnUpdateHMIAppType(std::map<std::string, StringArray> app_hmi_types) = 0; - /** - * @brief CanUpdate allows to find active application - * and check whether related device consented. - * - * @return true if there are at least one application has been registered - * with consented device. - */ + /** + * @brief CanUpdate allows to find active application + * and check whether related device consented. + * + * @return true if there are at least one application has been registered + * with consented device. + */ virtual bool CanUpdate() = 0; /** @@ -69,8 +69,9 @@ class PolicyListener { * when snapshot for PTU has been created. * * @param pt_string the snapshot + * */ - virtual void OnSnapshotCreated(const BinaryMessage& pt_string) = 0; + virtual void OnSnapshotCreated(const BinaryMessage &pt_string) = 0; /** * @brief Make appropriate changes for related applications permissions and @@ -78,13 +79,13 @@ class PolicyListener { * @param device_id Unique device id, which consent had been changed * @param device_consent Device consent, which is done by user */ - virtual void OnDeviceConsentChanged(const std::string& device_id, + virtual void OnDeviceConsentChanged(const std::string &device_id, bool is_allowed) = 0; /** * @brief GetAvailableApps allows to obtain list of registered applications. */ - virtual void GetAvailableApps(std::queue<std::string>&) = 0; + virtual void GetAvailableApps(std::queue<std::string> &) = 0; /** * @brief OnCertificateUpdated the callback which signals if certificate field @@ -92,7 +93,7 @@ class PolicyListener { * * @param certificate_data the value of the updated field. */ - virtual void OnCertificateUpdated(const std::string& certificate_data) = 0; + virtual void OnCertificateUpdated(const std::string &certificate_data) = 0; }; -} // namespace policy -#endif // SRC_COMPONENTS_POLICY_INCLUDE_POLICY_LISTENER_H_ +} // namespace policy +#endif // SRC_COMPONENTS_POLICY_INCLUDE_POLICY_LISTENER_H_ diff --git a/src/components/policy/src/policy/include/policy/policy_manager.h b/src/components/policy/src/policy/include/policy/policy_manager.h index 9b77edac56..0a62c94e7d 100644 --- a/src/components/policy/src/policy/include/policy/policy_manager.h +++ b/src/components/policy/src/policy/include/policy/policy_manager.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Ford Motor Company + Copyright (c) 2016, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,6 +34,7 @@ #define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_MANAGER_H_ #include <vector> +#include <cstdint> #include "policy/policy_types.h" #include "policy/policy_listener.h" @@ -41,6 +42,7 @@ namespace policy { class PolicyManager : public usage_statistics::StatisticsManager { + public: virtual ~PolicyManager() {} @@ -90,7 +92,7 @@ public: /** * @brief PTU is needed, for this PTS has to be formed and sent. */ - virtual void RequestPTUpdate() = 0; + virtual bool RequestPTUpdate() = 0; /** * @brief Check if specified RPC for specified application @@ -143,10 +145,10 @@ public: /** * Gets timeout to wait before next retry updating PT - * If timeout is less or equal to zero then the retry sequence is not need. + * If timeout is equal to zero then the retry sequence is not need. * @return timeout in seconds */ - virtual int NextRetryTimeout() = 0; + virtual uint32_t NextRetryTimeout() = 0; /** * Gets timeout to wait until receive response diff --git a/src/components/policy/src/policy/include/policy/policy_manager_impl.h b/src/components/policy/src/policy/include/policy/policy_manager_impl.h index 1c7f0d4ed7..78688c8fd5 100644 --- a/src/components/policy/src/policy/include/policy/policy_manager_impl.h +++ b/src/components/policy/src/policy/include/policy/policy_manager_impl.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Ford Motor Company + Copyright (c) 2016, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -34,6 +34,8 @@ #define SRC_COMPONENTS_POLICY_INCLUDE_POLICY_POLICY_MANAGER_IMPL_H_ #include <list> +#include <cstdint> + #include "utils/shared_ptr.h" #include "utils/lock.h" #include "policy/policy_manager.h" @@ -42,6 +44,8 @@ #include "policy/update_status_manager.h" #include "./functions.h" #include "usage_statistics/statistics_manager.h" +#include "policy/policy_helper.h" +#include "utils/timer_thread.h" namespace policy_table = rpc::policy_table_interface_base; @@ -61,7 +65,7 @@ public: EndpointUrls &end_points); virtual std::string GetLockScreenIconUrl() const; - virtual void RequestPTUpdate(); + virtual bool RequestPTUpdate(); virtual void CheckPermissions(const PTString &app_id, const PTString &hmi_level, const PTString &rpc, const RPCParams &rpc_params, @@ -72,7 +76,7 @@ public: virtual std::string ForcePTExchange(); virtual std::string GetPolicyTableStatus() const; virtual void ResetRetrySequence(); - virtual int NextRetryTimeout(); + virtual uint32_t NextRetryTimeout(); virtual int TimeoutExchange(); virtual const std::vector<int> RetrySequenceDelaysSeconds(); virtual void OnExceededTimeout(); @@ -271,6 +275,8 @@ private: bool IsPTValid(utils::SharedPtr<policy_table::Table> policy_table, policy_table::PolicyTableType type) const; + void RetrySequence(); + private: PolicyListener *listener_; @@ -283,7 +289,7 @@ private: /** * Timeout to wait response with UpdatePT */ - int retry_sequence_timeout_; + uint32_t retry_sequence_timeout_; /** * Seconds between retries to update PT @@ -301,6 +307,11 @@ private: sync_primitives::Lock retry_sequence_lock_; /** + * Timer to retry UpdatePT + */ + timer::TimerThread<PolicyManagerImpl> timer_retry_sequence_; + + /** * Lock for guarding recording statistics */ sync_primitives::Lock statistics_lock_; diff --git a/src/components/policy/src/policy/src/policy_manager_impl.cc b/src/components/policy/src/policy/src/policy_manager_impl.cc index f304a7f553..a927621664 100644 --- a/src/components/policy/src/policy/src/policy_manager_impl.cc +++ b/src/components/policy/src/policy/src/policy_manager_impl.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2013, Ford Motor Company + Copyright (c) 2016, Ford Motor Company All rights reserved. Redistribution and use in source and binary forms, with or without @@ -43,6 +43,7 @@ #include "utils/file_system.h" #include "utils/logger.h" #include "utils/date_time.h" +#include "utils/make_shared.h" #include "policy/cache_manager.h" #include "policy/update_status_manager.h" #include "config_profile/profile.h" @@ -51,13 +52,20 @@ policy::PolicyManager *CreateManager() { return new policy::PolicyManagerImpl(); } +namespace { +const uint32_t kDefaultRetryTimeoutInSec = 60u; +} // namespace + namespace policy { CREATE_LOGGERPTR_GLOBAL(logger_, "PolicyManagerImpl") PolicyManagerImpl::PolicyManagerImpl() : PolicyManager(), listener_(NULL), cache_(new CacheManager), - retry_sequence_timeout_(60), retry_sequence_index_(0), + retry_sequence_timeout_(kDefaultRetryTimeoutInSec), + retry_sequence_index_(0), + timer_retry_sequence_("Retry sequence timer", this, + &PolicyManagerImpl::RetrySequence), ignition_check(true) {} void PolicyManagerImpl::set_listener(PolicyListener *listener) { @@ -145,6 +153,12 @@ bool PolicyManagerImpl::LoadPT(const std::string &file, update_status_manager_.OnValidUpdateReceived(); cache_->SaveUpdateRequired(false); + // Update finished, no need retry + if (timer_retry_sequence_.isRunning()) { + LOG4CXX_INFO(logger_, "Stop retry sequence"); + timer_retry_sequence_.stop(); + } + apps_registration_lock_.Acquire(); // Get current DB data, since it could be updated during awaiting of PTU @@ -226,13 +240,13 @@ void PolicyManagerImpl::GetServiceUrls(const std::string &service_type, cache_->GetServiceUrls(service_type, end_points); } -void PolicyManagerImpl::RequestPTUpdate() { +bool PolicyManagerImpl::RequestPTUpdate() { LOG4CXX_AUTO_TRACE(logger_); utils::SharedPtr<policy_table::Table> policy_table_snapshot = cache_->GenerateSnapshot(); if (!policy_table_snapshot) { LOG4CXX_ERROR(logger_, "Failed to create snapshot of policy table"); - return; + return false; } IsPTValid(policy_table_snapshot, policy_table::PT_SNAPSHOT); @@ -250,6 +264,8 @@ void PolicyManagerImpl::RequestPTUpdate() { // Need to reset update schedule since all currenly registered applications // were already added to the snapshot so no update for them required. update_status_manager_.ResetUpdateSchedule(); + + return true; } std::string PolicyManagerImpl::GetLockScreenIconUrl() const { @@ -280,7 +296,10 @@ void PolicyManagerImpl::StartPTExchange() { } if (update_status_manager_.IsUpdateRequired()) { - RequestPTUpdate(); + if (RequestPTUpdate() && !timer_retry_sequence_.isRunning()) { + LOG4CXX_DEBUG(logger_, "Starting retry sequence."); + timer_retry_sequence_.start(NextRetryTimeout()); + } } } } @@ -696,15 +715,25 @@ std::string PolicyManagerImpl::GetPolicyTableStatus() const { return update_status_manager_.StringifiedUpdateStatus(); } -int PolicyManagerImpl::NextRetryTimeout() { +uint32_t PolicyManagerImpl::NextRetryTimeout() { sync_primitives::AutoLock auto_lock(retry_sequence_lock_); LOG4CXX_DEBUG(logger_, "Index: " << retry_sequence_index_); - int next = 0; - if (!retry_sequence_seconds_.empty() && - retry_sequence_index_ < retry_sequence_seconds_.size()) { - next = retry_sequence_seconds_[retry_sequence_index_]; - ++retry_sequence_index_; + uint32_t next = 0u; + if (retry_sequence_seconds_.empty() || + retry_sequence_index_ >= retry_sequence_seconds_.size()) { + LOG4CXX_WARN(logger_, "Next retry timeout is " << next); + return next; + } + + ++retry_sequence_index_; + + for (uint32_t i = 0u; i < retry_sequence_index_; ++i) { + next += retry_sequence_seconds_[i]; + LOG4CXX_DEBUG(logger_, "Next retry timeout to add is " << next); + // According to requirement APPLINK-18244 } + next += retry_sequence_timeout_; + LOG4CXX_DEBUG(logger_, "Total retry timeout is " << next); return next; } @@ -915,4 +944,18 @@ void PolicyManagerImpl::set_cache_manager( cache_ = cache_manager; } +void PolicyManagerImpl::RetrySequence() { + LOG4CXX_INFO(logger_, "Start new retry sequence"); + RequestPTUpdate(); + + uint32_t timeout = NextRetryTimeout(); + + if (!timeout && timer_retry_sequence_.isRunning()) { + timer_retry_sequence_.stop(); + return; + } + + timer_retry_sequence_.start(timeout); +} + } // namespace policy diff --git a/src/components/policy/test/include/mock_policy_listener.h b/src/components/policy/test/include/mock_policy_listener.h index 6cbca0557a..681b85740b 100644 --- a/src/components/policy/test/include/mock_policy_listener.h +++ b/src/components/policy/test/include/mock_policy_listener.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2014, Ford Motor Company +/* Copyright (c) 2016, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,6 @@ #ifndef SRC_COMPONENTS_POLICY_TEST_POLICY_INCLUDE_MOCK_POLICY_LISTENER_H_ #define SRC_COMPONENTS_POLICY_TEST_POLICY_INCLUDE_MOCK_POLICY_LISTENER_H_ - #include <string> #include "gmock/gmock.h" @@ -46,42 +45,31 @@ namespace policy_table = ::rpc::policy_table_interface_base; namespace policy { class MockPolicyListener : public PolicyListener { - public: - MOCK_METHOD3(OnPermissionsUpdated, - void(const std::string& policy_app_id, - const Permissions& permissions, - const policy::HMILevel& default_hmi)); - MOCK_METHOD2(OnPermissionsUpdated, - void(const std::string& policy_app_id, - const Permissions& permissions)); +public: + MOCK_METHOD3(OnPermissionsUpdated, void(const std::string &policy_app_id, + const Permissions &permissions, + const policy::HMILevel &default_hmi)); + MOCK_METHOD2(OnPermissionsUpdated, void(const std::string &policy_app_id, + const Permissions &permissions)); MOCK_METHOD1(OnPendingPermissionChange, - void(const std::string& policy_app_id)); - MOCK_METHOD1(OnUpdateStatusChanged, - void(const std::string& status)); + void(const std::string &policy_app_id)); + MOCK_METHOD1(OnUpdateStatusChanged, void(const std::string &status)); MOCK_METHOD1(OnCurrentDeviceIdUpdateRequired, - std::string(const std::string& policy_app_id)); - MOCK_METHOD0(OnSystemInfoUpdateRequired, - void()); - MOCK_METHOD1(GetAppName, - std::string(const std::string& policy_app_id)); - MOCK_METHOD0(OnUserRequestedUpdateCheckRequired, - void()); + std::string(const std::string &policy_app_id)); + MOCK_METHOD0(OnSystemInfoUpdateRequired, void()); + MOCK_METHOD1(GetAppName, std::string(const std::string &policy_app_id)); + MOCK_METHOD0(OnUserRequestedUpdateCheckRequired, void()); MOCK_METHOD2(OnDeviceConsentChanged, - void(const std::string& device_id, - bool is_allowed)); - MOCK_METHOD1(OnUpdateHMIAppType, - void(std::map<std::string, StringArray>)); - MOCK_METHOD1(GetAvailableApps, - void(std::queue<std::string>&)); - MOCK_METHOD3(OnSnapshotCreated, - void(const BinaryMessage& pt_string, - const std::vector<int>& retry_seconds, - int timeout_exceed)); - MOCK_METHOD0(CanUpdate, - bool()); - MOCK_METHOD1(OnCertificateUpdated, void (const std::string&)); + void(const std::string &device_id, bool is_allowed)); + MOCK_METHOD1(OnUpdateHMIAppType, void(std::map<std::string, StringArray>)); + MOCK_METHOD1(GetAvailableApps, void(std::queue<std::string> &)); + MOCK_METHOD1(OnSnapshotCreated, void(const BinaryMessage &pt_string)); + MOCK_METHOD0(CanUpdate, bool()); + MOCK_METHOD1(OnCertificateUpdated, void(const std::string &)); + MOCK_CONST_METHOD2(SendOnAppPermissionsChanged, + void(const AppPermissions &, const std::string &)); }; -} // namespace policy +} // namespace policy -#endif // SRC_COMPONENTS_POLICY_TEST_POLICY_INCLUDE_MOCK_POLICY_LISTENER_H_ +#endif // SRC_COMPONENTS_POLICY_TEST_POLICY_INCLUDE_MOCK_POLICY_LISTENER_H_ diff --git a/src/components/policy/test/policy_manager_impl_test.cc b/src/components/policy/test/policy_manager_impl_test.cc index 84fbcf1116..9bc30b3508 100644 --- a/src/components/policy/test/policy_manager_impl_test.cc +++ b/src/components/policy/test/policy_manager_impl_test.cc @@ -1,4 +1,5 @@ -/* Copyright (c) 2014, Ford Motor Company +/* + * Copyright (c) 2016, Ford Motor Company * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -64,11 +65,11 @@ namespace components { namespace policy { class PolicyManagerImplTest : public ::testing::Test { - protected: - PolicyManagerImpl* manager; - MockCacheManagerInterface* cache_manager; +protected: + PolicyManagerImpl *manager; + MockCacheManagerInterface *cache_manager; MockUpdateStatusManager update_manager; - MockPolicyListener* listener; + MockPolicyListener *listener; void SetUp() { manager = new PolicyManagerImpl(); @@ -85,7 +86,7 @@ class PolicyManagerImplTest : public ::testing::Test { delete listener; } - ::testing::AssertionResult IsValid(const policy_table::Table& table) { + ::testing::AssertionResult IsValid(const policy_table::Table &table) { if (table.is_valid()) { return ::testing::AssertionSuccess(); } else { @@ -96,23 +97,25 @@ class PolicyManagerImplTest : public ::testing::Test { } }; -TEST_F(PolicyManagerImplTest, RefreshRetrySequence_SetSecondsBetweenRetries_ExpectRetryTimeoutSequenceWithSameSeconds) { +TEST_F( + PolicyManagerImplTest, + RefreshRetrySequence_SetSecondsBetweenRetries_ExpectRetryTimeoutSequenceWithSameSeconds) { - //arrange + // arrange std::vector<int> seconds; seconds.push_back(50); seconds.push_back(100); seconds.push_back(200); - //assert + // assert EXPECT_CALL(*cache_manager, TimeoutResponse()).WillOnce(Return(60)); - EXPECT_CALL(*cache_manager, SecondsBetweenRetries(_)).WillOnce( - DoAll(SetArgReferee<0>(seconds), Return(true))); + EXPECT_CALL(*cache_manager, SecondsBetweenRetries(_)) + .WillOnce(DoAll(SetArgReferee<0>(seconds), Return(true))); - //act + // act manager->RefreshRetrySequence(); - //assert + // assert EXPECT_EQ(50, manager->NextRetryTimeout()); EXPECT_EQ(100, manager->NextRetryTimeout()); EXPECT_EQ(200, manager->NextRetryTimeout()); @@ -121,23 +124,22 @@ TEST_F(PolicyManagerImplTest, RefreshRetrySequence_SetSecondsBetweenRetries_Expe TEST_F(PolicyManagerImplTest, DISABLED_GetUpdateUrl) { - EXPECT_CALL(*cache_manager, GetServiceUrls("7",_)); - EXPECT_CALL(*cache_manager, GetServiceUrls("4",_)); + EXPECT_CALL(*cache_manager, GetServiceUrls("7", _)); + EXPECT_CALL(*cache_manager, GetServiceUrls("4", _)); EndpointUrls ep_7; manager->GetServiceUrls("7", ep_7); - EXPECT_EQ("http://policies.telematics.ford.com/api/policies", ep_7[0].url[0] ); + EXPECT_EQ("http://policies.telematics.ford.com/api/policies", ep_7[0].url[0]); EndpointUrls ep_4; manager->GetServiceUrls("4", ep_4); EXPECT_EQ("http://policies.ford.com/api/policies", ep_4[0].url[0]); - } - TEST_F(PolicyManagerImplTest, ResetPT) { - EXPECT_CALL(*cache_manager, ResetPT("filename")).WillOnce(Return(true)) + EXPECT_CALL(*cache_manager, ResetPT("filename")) + .WillOnce(Return(true)) .WillOnce(Return(false)); EXPECT_CALL(*cache_manager, TimeoutResponse()); EXPECT_CALL(*cache_manager, SecondsBetweenRetries(_)); @@ -146,24 +148,25 @@ TEST_F(PolicyManagerImplTest, ResetPT) { EXPECT_FALSE(manager->ResetPT("filename")); } -TEST_F(PolicyManagerImplTest, CheckPermissions_SetHmiLevelFullForAlert_ExpectAllowedPermissions) { +TEST_F(PolicyManagerImplTest, + CheckPermissions_SetHmiLevelFullForAlert_ExpectAllowedPermissions) { - //arrange + // arrange ::policy::CheckPermissionResult expected; expected.hmi_level_permitted = ::policy::kRpcAllowed; expected.list_of_allowed_params.push_back("speed"); expected.list_of_allowed_params.push_back("gps"); - //assert - EXPECT_CALL(*cache_manager, CheckPermissions("12345678", "FULL", "Alert", _)). - WillOnce(SetArgReferee<3>(expected)); + // assert + EXPECT_CALL(*cache_manager, CheckPermissions("12345678", "FULL", "Alert", _)) + .WillOnce(SetArgReferee<3>(expected)); - //act + // act ::policy::RPCParams input_params; ::policy::CheckPermissionResult output; manager->CheckPermissions("12345678", "FULL", "Alert", input_params, output); - //assert + // assert EXPECT_EQ(::policy::kRpcAllowed, output.hmi_level_permitted); ASSERT_TRUE(!output.list_of_allowed_params.empty()); @@ -174,17 +177,17 @@ TEST_F(PolicyManagerImplTest, CheckPermissions_SetHmiLevelFullForAlert_ExpectAll TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { - //arrange + // arrange Json::Value table(Json::objectValue); table["policy_table"] = Json::Value(Json::objectValue); - Json::Value& policy_table = table["policy_table"]; + Json::Value &policy_table = table["policy_table"]; policy_table["module_config"] = Json::Value(Json::objectValue); policy_table["functional_groupings"] = Json::Value(Json::objectValue); policy_table["consumer_friendly_messages"] = Json::Value(Json::objectValue); policy_table["app_policies"] = Json::Value(Json::objectValue); - Json::Value& module_config = policy_table["module_config"]; + Json::Value &module_config = policy_table["module_config"]; module_config["preloaded_pt"] = Json::Value(true); module_config["exchange_after_x_ignition_cycles"] = Json::Value(10); module_config["exchange_after_x_kilometers"] = Json::Value(100); @@ -197,10 +200,10 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { module_config["endpoints"] = Json::Value(Json::objectValue); module_config["endpoints"]["0x00"] = Json::Value(Json::objectValue); module_config["endpoints"]["0x00"]["default"] = Json::Value(Json::arrayValue); - module_config["endpoints"]["0x00"]["default"][0] = Json::Value( - "http://ford.com/cloud/default"); - module_config["notifications_per_minute_by_priority"] = Json::Value( - Json::objectValue); + module_config["endpoints"]["0x00"]["default"][0] = + Json::Value("http://ford.com/cloud/default"); + module_config["notifications_per_minute_by_priority"] = + Json::Value(Json::objectValue); module_config["notifications_per_minute_by_priority"]["emergency"] = Json::Value(1); module_config["notifications_per_minute_by_priority"]["navigation"] = @@ -209,17 +212,17 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { Json::Value(3); module_config["notifications_per_minute_by_priority"]["communication"] = Json::Value(4); - module_config["notifications_per_minute_by_priority"]["normal"] = Json::Value( - 5); - module_config["notifications_per_minute_by_priority"]["none"] = Json::Value( - 6); + module_config["notifications_per_minute_by_priority"]["normal"] = + Json::Value(5); + module_config["notifications_per_minute_by_priority"]["none"] = + Json::Value(6); module_config["vehicle_make"] = Json::Value("MakeT"); module_config["vehicle_model"] = Json::Value("ModelT"); module_config["vehicle_year"] = Json::Value("2014"); - Json::Value& functional_groupings = policy_table["functional_groupings"]; + Json::Value &functional_groupings = policy_table["functional_groupings"]; functional_groupings["default"] = Json::Value(Json::objectValue); - Json::Value& default_group = functional_groupings["default"]; + Json::Value &default_group = functional_groupings["default"]; default_group["rpcs"] = Json::Value(Json::objectValue); default_group["rpcs"]["Update"] = Json::Value(Json::objectValue); default_group["rpcs"]["Update"]["hmi_levels"] = Json::Value(Json::arrayValue); @@ -227,11 +230,11 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { default_group["rpcs"]["Update"]["parameters"] = Json::Value(Json::arrayValue); default_group["rpcs"]["Update"]["parameters"][0] = Json::Value("speed"); - Json::Value& consumer_friendly_messages = + Json::Value &consumer_friendly_messages = policy_table["consumer_friendly_messages"]; consumer_friendly_messages["version"] = Json::Value("1.2"); - Json::Value& app_policies = policy_table["app_policies"]; + Json::Value &app_policies = policy_table["app_policies"]; app_policies["default"] = Json::Value(Json::objectValue); app_policies["default"]["memory_kb"] = Json::Value(50); app_policies["default"]["heart_beat_timeout_ms"] = Json::Value(100); @@ -256,18 +259,17 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { policy_table::Table update(&table); update.SetPolicyTableType(rpc::policy_table_interface_base::PT_UPDATE); - //assert + // assert ASSERT_TRUE(IsValid(update)); - - //act + // act std::string json = table.toStyledString(); ::policy::BinaryMessage msg(json.begin(), json.end()); - utils::SharedPtr<policy_table::Table> snapshot = new policy_table::Table( - update.policy_table); + utils::SharedPtr<policy_table::Table> snapshot = + new policy_table::Table(update.policy_table); - //assert + // assert EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(snapshot)); EXPECT_CALL(*cache_manager, ApplyUpdate(_)).WillOnce(Return(true)); EXPECT_CALL(*listener, GetAppName("1234")).WillOnce(Return("")); @@ -276,36 +278,56 @@ TEST_F(PolicyManagerImplTest, LoadPT_SetPT_PTIsLoaded) { EXPECT_CALL(*cache_manager, TimeoutResponse()); EXPECT_CALL(*cache_manager, SecondsBetweenRetries(_)); - EXPECT_TRUE(manager->LoadPT("file_pt_update.json", msg)); -} - -TEST_F(PolicyManagerImplTest, RequestPTUpdate_SetPT_GeneratedSnapshotAndPTUpdate) { - - //arrange - ::utils::SharedPtr< ::policy_table::Table > p_table = - new ::policy_table::Table(); - - //assert - EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(p_table)); + TEST_F(PolicyManagerImplTest2, NextRetryTimeout_ExpectTimeoutsFromPT) { + // Arrange + std::ifstream ifile("sdl_preloaded_pt.json"); + Json::Reader reader; + Json::Value root(Json::objectValue); + if (ifile.is_open() && reader.parse(ifile, root, true)) { + Json::Value seconds_between_retries = Json::Value(Json::arrayValue); + seconds_between_retries = + root["policy_table"]["module_config"]["seconds_between_retries"]; + uint32_t size = seconds_between_retries.size(); + CreateLocalPT("sdl_preloaded_pt.json"); + + uint32_t waiting_timeout = 0u; + + for (uint32_t retry_number = 0u; retry_number < size; ++retry_number) { + waiting_timeout += seconds_between_retries[retry_number].asInt(); + waiting_timeout += manager->TimeoutExchange(); + + // it's in miliseconds + EXPECT_EQ(waiting_timeout * date_time::DateTime::MILLISECONDS_IN_SECOND, + manager->NextRetryTimeout()); + } + } + } - //act - manager->RequestPTUpdate(); -} + TEST_F(PolicyManagerImplTest, + RequestPTUpdate_SetPT_GeneratedSnapshotAndPTUpdate) { + // arrange + ::utils::SharedPtr<::policy_table::Table> p_table = + new ::policy_table::Table(); -TEST_F(PolicyManagerImplTest, DISABLED_AddApplication) { - // TODO(AOleynik): Implementation of method should be changed to avoid - // using of snapshot - //manager->AddApplication("12345678"); -} + // assert + EXPECT_CALL(*cache_manager, GenerateSnapshot()).WillOnce(Return(p_table)); -TEST_F(PolicyManagerImplTest, DISABLED_GetPolicyTableStatus) { - // TODO(AOleynik): Test is not finished, to be continued - //manager->GetPolicyTableStatus(); -} + // act + manager->RequestPTUpdate(); + } + TEST_F(PolicyManagerImplTest, DISABLED_AddApplication) { + // TODO(AOleynik): Implementation of method should be changed to avoid + // using of snapshot + // manager->AddApplication("12345678"); + } + TEST_F(PolicyManagerImplTest, DISABLED_GetPolicyTableStatus) { + // TODO(AOleynik): Test is not finished, to be continued + // manager->GetPolicyTableStatus(); + } } // namespace policy -}// namespace components -} // namespace test +} // namespace components +} // namespace test |