From 3da2ec2149d3838b72f087774efd03df0070149d Mon Sep 17 00:00:00 2001 From: Olga Khlopkova Date: Mon, 7 Dec 2020 13:42:35 +0300 Subject: [PATCH] removal --- map/framework.cpp | 1 - routing/CMakeLists.txt | 4 - routing/online_absent_fetcher.cpp | 80 ----------------- routing/online_absent_fetcher.hpp | 47 ---------- routing/online_cross_fetcher.cpp | 89 ------------------- routing/online_cross_fetcher.hpp | 55 ------------ .../routing_integration_tests/CMakeLists.txt | 1 - .../online_cross_tests.cpp | 85 ------------------ .../routing_test_tools.cpp | 50 ----------- routing/routing_tests/CMakeLists.txt | 1 - routing/routing_tests/async_router_test.cpp | 14 --- .../online_cross_fetcher_test.cpp | 63 ------------- 12 files changed, 490 deletions(-) delete mode 100644 routing/online_absent_fetcher.cpp delete mode 100644 routing/online_absent_fetcher.hpp delete mode 100644 routing/online_cross_fetcher.cpp delete mode 100644 routing/online_cross_fetcher.hpp delete mode 100644 routing/routing_integration_tests/online_cross_tests.cpp delete mode 100644 routing/routing_tests/online_cross_fetcher_test.cpp diff --git a/map/framework.cpp b/map/framework.cpp index 7b29c506e9..15d05ad6c8 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -25,7 +25,6 @@ #include "routing/city_roads.hpp" #include "routing/index_router.hpp" -#include "routing/online_absent_fetcher.hpp" #include "routing/route.hpp" #include "routing/routing_helpers.hpp" diff --git a/routing/CMakeLists.txt b/routing/CMakeLists.txt index c445d23b47..297dd1291e 100644 --- a/routing/CMakeLists.txt +++ b/routing/CMakeLists.txt @@ -99,10 +99,6 @@ set( mwm_hierarchy_handler.hpp nearest_edge_finder.cpp nearest_edge_finder.hpp - online_absent_fetcher.cpp - online_absent_fetcher.hpp - online_cross_fetcher.cpp - online_cross_fetcher.hpp opening_hours_serdes.cpp opening_hours_serdes.hpp pedestrian_directions.cpp diff --git a/routing/online_absent_fetcher.cpp b/routing/online_absent_fetcher.cpp deleted file mode 100644 index aedcf41837..0000000000 --- a/routing/online_absent_fetcher.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include "routing/online_absent_fetcher.hpp" - -#include "routing/online_cross_fetcher.hpp" - -#include "platform/platform.hpp" -#include "platform/country_file.hpp" - -#include "base/stl_helpers.hpp" - -#include "private.h" - -using namespace std; - -using platform::CountryFile; -using platform::LocalCountryFile; - -namespace routing -{ -OnlineAbsentCountriesFetcher::OnlineAbsentCountriesFetcher( - TCountryFileFn const & countryFileFn, TCountryLocalFileFn const & countryLocalFileFn) - : m_countryFileFn(countryFileFn), m_countryLocalFileFn(countryLocalFileFn) -{ - CHECK(m_countryFileFn, ()); - CHECK(m_countryLocalFileFn, ()); -} - -void OnlineAbsentCountriesFetcher::GenerateRequest(Checkpoints const & checkpoints) -{ - if (Platform::ConnectionStatus() == Platform::EConnectionType::CONNECTION_NONE) - return; - - if (m_fetcherThread) - { - m_fetcherThread->Cancel(); - m_fetcherThread.reset(); - } - - // Single mwm case. - if (AllPointsInSameMwm(checkpoints)) - return; - - unique_ptr fetcher = - make_unique(m_countryFileFn, OSRM_ONLINE_SERVER_URL, checkpoints); - // iOS can't reuse threads. So we need to recreate the thread. - m_fetcherThread = make_unique(); - m_fetcherThread->Create(move(fetcher)); -} - -void OnlineAbsentCountriesFetcher::GetAbsentCountries(set & countries) -{ - countries.clear(); - // Check whether a request was scheduled to be run on the thread. - if (!m_fetcherThread) - return; - - m_fetcherThread->Join(); - for (auto const & point : m_fetcherThread->GetRoutineAs()->GetMwmPoints()) - { - string name = m_countryFileFn(point); - ASSERT(!name.empty(), ()); - if (name.empty() || m_countryLocalFileFn(name)) - continue; - - countries.emplace(move(name)); - } - - m_fetcherThread.reset(); -} - -bool OnlineAbsentCountriesFetcher::AllPointsInSameMwm(Checkpoints const & checkpoints) const -{ - for (size_t i = 0; i < checkpoints.GetNumSubroutes(); ++i) - { - if (m_countryFileFn(checkpoints.GetPoint(i)) != m_countryFileFn(checkpoints.GetPoint(i + 1))) - return false; - } - - return true; -} -} // namespace routing diff --git a/routing/online_absent_fetcher.hpp b/routing/online_absent_fetcher.hpp deleted file mode 100644 index 5fe98e601b..0000000000 --- a/routing/online_absent_fetcher.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "routing/checkpoints.hpp" -#include "routing/router.hpp" - -#include "geometry/point2d.hpp" - -#include "base/thread.hpp" - -#include -#include -#include -#include - -namespace routing -{ -using TCountryLocalFileFn = std::function; - -class IOnlineFetcher -{ -public: - virtual ~IOnlineFetcher() = default; - virtual void GenerateRequest(Checkpoints const &) = 0; - virtual void GetAbsentCountries(std::set & countries) = 0; -}; - -/*! - * \brief The OnlineAbsentCountriesFetcher class incapsulates async fetching the map - * names from online OSRM server routines. - */ -class OnlineAbsentCountriesFetcher : public IOnlineFetcher -{ -public: - OnlineAbsentCountriesFetcher(TCountryFileFn const &, TCountryLocalFileFn const &); - - // IOnlineFetcher overrides: - void GenerateRequest(Checkpoints const & checkpoints) override; - void GetAbsentCountries(std::set & countries) override; - -private: - bool AllPointsInSameMwm(Checkpoints const &) const; - - TCountryFileFn const m_countryFileFn; - TCountryLocalFileFn const m_countryLocalFileFn; - std::unique_ptr m_fetcherThread; -}; -} // namespace routing diff --git a/routing/online_cross_fetcher.cpp b/routing/online_cross_fetcher.cpp deleted file mode 100644 index 79e7fd7044..0000000000 --- a/routing/online_cross_fetcher.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "routing/online_cross_fetcher.hpp" - -#include "platform/http_request.hpp" -#include "platform/platform.hpp" - -#include "base/logging.hpp" -#include "base/string_utils.hpp" - -#include "3party/jansson/myjansson.hpp" - -#include "geometry/mercator.hpp" - -using namespace std; - -namespace -{ -inline string LatLonToURLArgs(ms::LatLon const & point) -{ - return strings::to_string(point.m_lat) + ','+ strings::to_string(point.m_lon); -} -} // namespace - -namespace routing -{ -bool ParseResponse(string const & serverResponse, vector & outPoints) -{ - try - { - base::Json parser(serverResponse.c_str()); - - json_t const * countries = json_object_get(parser.get(), "used_mwms"); - size_t const pointsCount = json_array_size(countries); - for (size_t i = 0; i < pointsCount; ++i) - { - json_t * pointArray = json_array_get(countries, i); - outPoints.push_back({json_number_value(json_array_get(pointArray, 0)), - json_number_value(json_array_get(pointArray, 1))}); - } - return pointsCount > 0; - } - catch (base::Json::Exception const & exception) - { - LOG(LWARNING, ("Can't parse server response:", exception.what())); - LOG(LWARNING, ("Response body:", serverResponse)); - return false; - } -} - -string GenerateOnlineRequest(string const & serverURL, ms::LatLon const & startPoint, - ms::LatLon const & finalPoint) -{ - return serverURL + "/mapsme?loc=" + LatLonToURLArgs(startPoint) + "&loc=" + - LatLonToURLArgs(finalPoint); -} - -OnlineCrossFetcher::OnlineCrossFetcher(TCountryFileFn const & countryFileFn, - string const & serverURL, Checkpoints const & checkpoints) - : m_countryFileFn(countryFileFn), m_serverURL(serverURL), m_checkpoints(checkpoints) -{ - CHECK(m_countryFileFn, ()); -} - -void OnlineCrossFetcher::Do() -{ - m_mwmPoints.clear(); - - for (size_t i = 0; i < m_checkpoints.GetNumSubroutes(); ++i) - { - m2::PointD const & pointFrom = m_checkpoints.GetPoint(i); - m2::PointD const & pointTo = m_checkpoints.GetPoint(i + 1); - - string const mwmFrom = m_countryFileFn(pointFrom); - string const mwmTo = m_countryFileFn(pointTo); - if (mwmFrom == mwmTo) - continue; - - string const url = GenerateOnlineRequest(m_serverURL, mercator::ToLatLon(pointFrom), - mercator::ToLatLon(pointTo)); - platform::HttpClient request(url); - request.SetRawHeader("User-Agent", GetPlatform().GetAppUserAgent()); - LOG(LINFO, ("Check mwms by URL: ", url)); - - if (request.RunHttpRequest() && request.ErrorCode() == 200 && !request.WasRedirected()) - ParseResponse(request.ServerResponse(), m_mwmPoints); - else - LOG(LWARNING, ("Can't get OSRM server response. Code: ", request.ErrorCode())); - } -} -} // namespace routing diff --git a/routing/online_cross_fetcher.hpp b/routing/online_cross_fetcher.hpp deleted file mode 100644 index f3b91395f7..0000000000 --- a/routing/online_cross_fetcher.hpp +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include "routing/checkpoints.hpp" -#include "routing/router.hpp" - -#include "platform/http_client.hpp" - -#include "geometry/point2d.hpp" -#include "geometry/latlon.hpp" - -#include "base/thread.hpp" - -#include -#include - -namespace routing -{ -/// URL string generator for MAPS.ME OSRM server request. -/// \param serverURL http server url with protocol, name and port if needed. For example: -/// http://mail.ru:12345 -/// \param startPoint Coordinates of a start point. -/// \param finalPoint Coordinates of a finish point. -/// \return URL for OSRM MAPS.ME server request. -/// \see MapsMePlugin.hpp for REST protocol. -std::string GenerateOnlineRequest(std::string const & serverURL, ms::LatLon const & startPoint, - ms::LatLon const & finalPoint); - -/// \brief ParseResponse MAPS.ME OSRM server response parser. -/// \param serverResponse Server response data. -/// \param outPoints Mwm map points. -/// \return true if there are some maps in a server's response. -bool ParseResponse(std::string const & serverResponse, std::vector & outPoints); - -class OnlineCrossFetcher : public threads::IRoutine -{ -public: - /// \brief OnlineCrossFetcher helper class to make request to online OSRM server - /// and get mwm names list - OnlineCrossFetcher(TCountryFileFn const & countryFileFn, std::string const & serverURL, - Checkpoints const & checkpoints); - - /// Overrides threads::IRoutine processing procedure. Calls online OSRM server and parses response. - void Do() override; - - /// \brief GetMwmPoints returns mwm representation points list. - /// \return Mwm points to build route from startPt to finishPt. Empty list if there were errors. - std::vector const & GetMwmPoints() { return m_mwmPoints; } - -private: - TCountryFileFn const m_countryFileFn; - std::string const m_serverURL; - Checkpoints const m_checkpoints; - std::vector m_mwmPoints; -}; -} diff --git a/routing/routing_integration_tests/CMakeLists.txt b/routing/routing_integration_tests/CMakeLists.txt index f794387891..d3b9ffbf2f 100644 --- a/routing/routing_integration_tests/CMakeLists.txt +++ b/routing/routing_integration_tests/CMakeLists.txt @@ -23,7 +23,6 @@ set( cross_country_routing_tests.cpp get_altitude_test.cpp guides_tests.cpp - online_cross_tests.cpp pedestrian_route_test.cpp road_graph_tests.cpp roundabouts_tests.cpp diff --git a/routing/routing_integration_tests/online_cross_tests.cpp b/routing/routing_integration_tests/online_cross_tests.cpp deleted file mode 100644 index 0425c3ac12..0000000000 --- a/routing/routing_integration_tests/online_cross_tests.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "testing/testing.hpp" - -#include "routing/routing_integration_tests/routing_test_tools.hpp" - -namespace -{ -// Separately tests only fetcher. Other tests will test both fetcher and raw code. -UNIT_TEST(OnlineCrossFetcherSmokeTest) -{ - integration::IRouterComponents & routerComponents = - integration::GetVehicleComponents(VehicleType::Car); - TestOnlineFetcher({61.76, 34.45}, {45.07, 38.94}, - {"Russia_Republic of Karelia_South", "Russia_Leningradskaya Oblast_Southeast", - "Russia_Novgorod Oblast", "Russia_Tver Oblast", "Russia_Moscow Oblast_West", - "Russia_Moscow", "Russia_Moscow Oblast_East", "Russia_Tula Oblast", - "Russia_Lipetsk Oblast", "Russia_Voronezh Oblast", "Russia_Rostov Oblast", - "Russia_Krasnodar Krai"}, - routerComponents); -} - -UNIT_TEST(OnlineRussiaNorthToSouthTest) -{ - integration::IRouterComponents & routerComponents = - integration::GetVehicleComponents(VehicleType::Car); - TestOnlineCrosses({61.76, 34.45}, {45.07, 38.94}, - {"Russia_Republic of Karelia_South", "Russia_Leningradskaya Oblast_Southeast", - "Russia_Novgorod Oblast", "Russia_Tver Oblast", "Russia_Moscow Oblast_East", - "Russia_Moscow Oblast_West", "Russia_Moscow", "Russia_Tula Oblast", - "Russia_Lipetsk Oblast", "Russia_Voronezh Oblast", "Russia_Rostov Oblast", - "Russia_Krasnodar Krai"}, - routerComponents); -} - -UNIT_TEST(OnlineRoadToSeaCenterTest) -{ - integration::IRouterComponents & routerComponents = - integration::GetVehicleComponents(VehicleType::Car); - TestOnlineCrosses({61.76, 34.45}, {42.25,30.10}, {}, routerComponents); -} - -UNIT_TEST(OnlineEuropeTestNurnbergToMoscow) -{ - integration::IRouterComponents & routerComponents = - integration::GetVehicleComponents(VehicleType::Car); - TestOnlineCrosses( - {49.45, 11.082}, {55.74, 37.56}, - {"Germany_Free State of Bavaria_Middle Franconia", - "Germany_Free State of Bavaria_Upper Franconia", "Germany_Saxony_Leipzig", - "Germany_Saxony_Dresden", "Poland_Lower Silesian Voivodeship", - "Poland_Greater Poland Voivodeship", "Poland_Lodz Voivodeship", "Poland_Lublin Voivodeship", - "Poland_Masovian Voivodeship", "Belarus_Brest Region", "Belarus_Hrodna Region", - "Belarus_Minsk Region", "Belarus_Vitebsk Region", "Russia_Smolensk Oblast", - "Russia_Moscow Oblast_West", "Russia_Moscow"}, - routerComponents); -} - -UNIT_TEST(OnlineAmericanTestOttawaToWashington) -{ - integration::IRouterComponents & routerComponents = - integration::GetVehicleComponents(VehicleType::Car); - TestOnlineCrosses({45.38, -75.69}, {38.91, -77.031}, - {"Canada_Ontario_Kingston", "US_New York_North", "US_New York_West", - "US_Pennsylvania_Scranton", "US_Pennsylvania_Central", "US_Maryland_Baltimore", - "US_Maryland_and_DC"}, - routerComponents); -} - -UNIT_TEST(OnlineAsiaPhuketToPnompen) -{ - integration::IRouterComponents & routerComponents = - integration::GetVehicleComponents(VehicleType::Car); - TestOnlineCrosses({7.89, 98.30}, {11.56, 104.86}, {"Thailand_South", "Cambodia"}, - routerComponents); -} - -UNIT_TEST(OnlineAustraliaCanberraToPerth) -{ - integration::IRouterComponents & routerComponents = - integration::GetVehicleComponents(VehicleType::Car); - TestOnlineCrosses({-33.88, 151.13}, {-31.974, 115.88}, - {"Australia_New South Wales", "Australia_Victoria", "Australia_South Australia", - "Australia_Western Australia", "Australia_Sydney"}, - routerComponents); -} -} // namespace diff --git a/routing/routing_integration_tests/routing_test_tools.cpp b/routing/routing_integration_tests/routing_test_tools.cpp index eca84aaebd..d6cf624981 100644 --- a/routing/routing_integration_tests/routing_test_tools.cpp +++ b/routing/routing_integration_tests/routing_test_tools.cpp @@ -307,56 +307,6 @@ TestTurn GetNthTurn(routing::Route const & route, uint32_t turnNumber) return TestTurn(route.GetPoly().GetPoint(turn.m_index), turn.m_turn, turn.m_exitNum); } -void TestOnlineFetcher(ms::LatLon const & startPoint, ms::LatLon const & finalPoint, - vector const & expected, IRouterComponents & routerComponents) -{ - auto countryFileGetter = [&routerComponents](m2::PointD const & p) -> string - { - return routerComponents.GetCountryInfoGetter().GetRegionCountryId(p); - }; - auto localFileChecker = [](string const & /* countryFile */) -> bool { - // Always returns that the file is absent. - return false; - }; - routing::OnlineAbsentCountriesFetcher fetcher(countryFileGetter, localFileChecker); - fetcher.GenerateRequest(Checkpoints(mercator::FromLatLon(startPoint), mercator::FromLatLon(finalPoint))); - set absent; - fetcher.GetAbsentCountries(absent); - if (expected.size() < 2) - { - // Single MWM case. Do not use online routing. - TEST(absent.empty(), ()); - return; - } - TEST_EQUAL(absent.size(), expected.size(), ()); - for (string const & name : expected) - TEST(find(absent.begin(), absent.end(), name) != absent.end(), ("Can't find", name)); -} - -void TestOnlineCrosses(ms::LatLon const & startPoint, ms::LatLon const & finalPoint, - vector const & expected, - IRouterComponents & routerComponents) -{ - TCountryFileFn const countryFileGetter = [&](m2::PointD const & p) { - return routerComponents.GetCountryInfoGetter().GetRegionCountryId(p); - }; - routing::OnlineCrossFetcher fetcher(countryFileGetter, OSRM_ONLINE_SERVER_URL, - Checkpoints(mercator::FromLatLon(startPoint), mercator::FromLatLon(finalPoint))); - fetcher.Do(); - vector const & points = fetcher.GetMwmPoints(); - set foundMwms; - - for (m2::PointD const & point : points) - { - string const mwmName = routerComponents.GetCountryInfoGetter().GetRegionCountryId(point); - TEST(find(expected.begin(), expected.end(), mwmName) != expected.end(), - ("Can't find ", mwmName)); - foundMwms.insert(mwmName); - } - - TEST_EQUAL(expected.size(), foundMwms.size(), ()); -} - bool IsSubwayExists(Route const & route) { auto const & routeSegments = route.GetRouteSegments(); diff --git a/routing/routing_tests/CMakeLists.txt b/routing/routing_tests/CMakeLists.txt index ac324b929d..1c67edc4e1 100644 --- a/routing/routing_tests/CMakeLists.txt +++ b/routing/routing_tests/CMakeLists.txt @@ -22,7 +22,6 @@ set( index_graph_tools.hpp maxspeeds_tests.cpp nearest_edge_finder_tests.cpp - online_cross_fetcher_test.cpp opening_hours_serdes_tests.cpp position_accumulator_tests.cpp restriction_test.cpp diff --git a/routing/routing_tests/async_router_test.cpp b/routing/routing_tests/async_router_test.cpp index 0007a24804..2a2469c61a 100644 --- a/routing/routing_tests/async_router_test.cpp +++ b/routing/routing_tests/async_router_test.cpp @@ -57,20 +57,6 @@ public: } }; -class DummyFetcher : public IOnlineFetcher -{ - set m_absent; - -public: - explicit DummyFetcher(set const & absent) : m_absent(absent) {} - - // IOnlineFetcher overrides: - void GenerateRequest(Checkpoints const &) override {} - void GetAbsentCountries(set & countries) override { countries = m_absent; } -}; - -void DummyStatisticsCallback(map const &) {} - struct DummyRoutingCallbacks { vector m_codes; diff --git a/routing/routing_tests/online_cross_fetcher_test.cpp b/routing/routing_tests/online_cross_fetcher_test.cpp deleted file mode 100644 index 50a033b980..0000000000 --- a/routing/routing_tests/online_cross_fetcher_test.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "testing/testing.hpp" - -#include "routing/online_absent_fetcher.hpp" -#include "routing/online_cross_fetcher.hpp" - -#include "geometry/point2d.hpp" - -#include -#include -#include -#include - -using namespace routing; -using namespace std; - -namespace -{ -UNIT_TEST(UrlGeneratorTest) -{ - TEST_EQUAL(GenerateOnlineRequest("http://mapsme.test.ru:10012", ms::LatLon(55.690105, 37.726536), - ms::LatLon(44.527843, 39.902344)), - "http://mapsme.test.ru:10012/mapsme?loc=55.6901,37.7265&loc=44.5278,39.9023", - ("Url parsed")); -} - -UNIT_TEST(GoodResponseParse) -{ - vector outPoints; - TEST(ParseResponse(R"({"used_mwms":[[39.522671,94.009263], [37.4809, 67.7244]]})", outPoints), - ("Valid response can't be parsed")); - TEST_EQUAL(outPoints.size(), 2, ()); - TEST( - find(outPoints.begin(), outPoints.end(), m2::PointD(39.522671, 94.009263)) != outPoints.end(), - ("Can't find point in server's response.")); - TEST(find(outPoints.begin(), outPoints.end(), m2::PointD(37.4809, 67.7244)) != outPoints.end(), - ("Can't find point in server's response.")); -} - -UNIT_TEST(BadResponseParse) -{ - vector outPoints; - TEST(!ParseResponse("{\"used_mwms\":[]}", outPoints), ("Inval response should not be parsed")); - TEST_EQUAL(outPoints.size(), 0, ("Found mwm points in invalid request")); -} - -UNIT_TEST(GarbadgeInputToResponseParser) -{ - vector outPoints; - TEST(!ParseResponse("{\"usedsfblbvlshbvldshbvfvmdfknvksvbksvk", outPoints), - ("Malformed response should not be processed.")); - TEST_EQUAL(outPoints.size(), 0, ("Found mwm points in invalid request")); -} - -UNIT_TEST(OnlineAbsentFetcherSingleMwmTest) -{ - OnlineAbsentCountriesFetcher fetcher([](m2::PointD const & p){return "A";}, [](string const &){return false;}); - fetcher.GenerateRequest(Checkpoints({1, 1}, {2, 2})); - set countries; - fetcher.GetAbsentCountries(countries); - TEST(countries.empty(), ()); -} - -}