|
1 | 1 | /* |
2 | | - * Copyright (C) 2019-2025 HERE Europe B.V. |
| 2 | + * Copyright (C) 2019-2026 HERE Europe B.V. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -144,6 +144,10 @@ const std::string kHttpResponseLookupQuery = |
144 | 144 | const std::string kUrlQueryApi = |
145 | 145 | R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2)"; |
146 | 146 |
|
| 147 | +const std::string kUrlQueryVersionedPartition = |
| 148 | + kUrlQueryApi + |
| 149 | + R"(/layers/testlayer/partitions?partition=1111&version=100)"; |
| 150 | + |
147 | 151 | const std::string kQueryTreeIndexWithAdditionalFields = |
148 | 152 | R"(https://sab.query.data.api.platform.here.com/query/v1/catalogs/hrn:here:data::olp-here-test:hereos-internal-test-v2/layers/testlayer/versions/100/quadkeys/23064/depths/4?additionalFields=)" + |
149 | 153 | olp::utils::Url::Encode(R"(checksum,crc,dataSize,compressedDataSize)"); |
@@ -592,9 +596,6 @@ TEST_F(PartitionsRepositoryTest, GetPartitionById) { |
592 | 596 | TEST_F(PartitionsRepositoryTest, GetVersionedPartitions) { |
593 | 597 | using testing::Return; |
594 | 598 |
|
595 | | - std::shared_ptr<cache::KeyValueCache> default_cache = |
596 | | - client::OlpClientSettingsFactory::CreateDefaultCache({}); |
597 | | - |
598 | 599 | auto mock_network = std::make_shared<NetworkMock>(); |
599 | 600 | auto cache = std::make_shared<testing::StrictMock<CacheMock>>(); |
600 | 601 | const auto catalog = HRN::FromString(kCatalog); |
@@ -641,6 +642,147 @@ TEST_F(PartitionsRepositoryTest, GetVersionedPartitions) { |
641 | 642 | ASSERT_FALSE(response.IsSuccessful()); |
642 | 643 | EXPECT_TRUE(response.GetResult().GetPartitions().empty()); |
643 | 644 | } |
| 645 | + { |
| 646 | + SCOPED_TRACE( |
| 647 | + "Succeeds the cache look up when one of the partitions has no content"); |
| 648 | + OlpClientSettings settings; |
| 649 | + settings.cache = cache; |
| 650 | + settings.network_request_handler = mock_network; |
| 651 | + settings.retry_settings.timeout = 1; |
| 652 | + |
| 653 | + const std::string cache_key_1 = |
| 654 | + kCatalog + "::" + kVersionedLayerId + "::" + kPartitionId + |
| 655 | + "::" + std::to_string(kVersion) + "::partition"; |
| 656 | + |
| 657 | + const std::string cache_key_2 = |
| 658 | + kCatalog + "::" + kVersionedLayerId + "::" + kInvalidPartitionId + |
| 659 | + "::" + std::to_string(kVersion) + "::partition"; |
| 660 | + |
| 661 | + const std::string query_cache_response = |
| 662 | + R"jsonString({"version":100,"partition":"1111","layer":"testlayer","dataHandle":"qwerty"})jsonString"; |
| 663 | + |
| 664 | + const std::string no_content_cache_response = |
| 665 | + R"jsonString({"partition":"2222"})jsonString"; |
| 666 | + |
| 667 | + auto response_data = std::make_shared<cache::KeyValueCache::ValueType>( |
| 668 | + query_cache_response.begin(), query_cache_response.end()); |
| 669 | + |
| 670 | + EXPECT_CALL(*cache, Read(cache_key_1)).WillOnce(Return(response_data)); |
| 671 | + |
| 672 | + EXPECT_CALL(*cache, Read(cache_key_2)) |
| 673 | + .WillOnce(Return(std::make_shared<cache::KeyValueCache::ValueType>( |
| 674 | + no_content_cache_response.cbegin(), |
| 675 | + no_content_cache_response.cend()))); |
| 676 | + |
| 677 | + client::CancellationContext context; |
| 678 | + ApiLookupClient lookup_client(catalog, settings); |
| 679 | + repository::PartitionsRepository repository(catalog, kVersionedLayerId, |
| 680 | + settings, lookup_client); |
| 681 | + |
| 682 | + read::PartitionsRequest request; |
| 683 | + request.WithPartitionIds({kPartitionId, kInvalidPartitionId}); |
| 684 | + request.WithFetchOption(read::CacheOnly); |
| 685 | + |
| 686 | + auto response = repository.GetVersionedPartitionsExtendedResponse( |
| 687 | + request, kVersion, context); |
| 688 | + |
| 689 | + ASSERT_TRUE(response.IsSuccessful()); |
| 690 | + EXPECT_EQ(response.GetResult().GetPartitions().size(), 1); |
| 691 | + } |
| 692 | + { |
| 693 | + SCOPED_TRACE("Cache utilised for not existing partitions"); |
| 694 | + |
| 695 | + OlpClientSettings settings; |
| 696 | + settings.cache = cache; |
| 697 | + settings.network_request_handler = mock_network; |
| 698 | + settings.retry_settings.timeout = 1; |
| 699 | + |
| 700 | + const std::string cache_key_1 = |
| 701 | + kCatalog + "::" + kVersionedLayerId + "::" + kPartitionId + |
| 702 | + "::" + std::to_string(kVersion) + "::partition"; |
| 703 | + |
| 704 | + EXPECT_CALL(*cache, Read(cache_key_1)) |
| 705 | + .WillOnce(Return(client::ApiError::NotFound())); |
| 706 | + |
| 707 | + EXPECT_CALL(*cache, Write(_, _, _)).WillOnce(Return(client::ApiNoResult())); |
| 708 | + |
| 709 | + EXPECT_CALL(*cache, Get(kCacheKeyMetadata, _)) |
| 710 | + .WillOnce(Return(kUrlQueryApi)); |
| 711 | + |
| 712 | + EXPECT_CALL(*mock_network, |
| 713 | + Send(IsGetRequest(kUrlQueryVersionedPartition), _, _, _, _)) |
| 714 | + .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( |
| 715 | + olp::http::HttpStatusCode::OK), |
| 716 | + kOlpSdkHttpResponseEmptyPartitionList)); |
| 717 | + |
| 718 | + client::CancellationContext context; |
| 719 | + ApiLookupClient lookup_client(catalog, settings); |
| 720 | + repository::PartitionsRepository repository(catalog, kVersionedLayerId, |
| 721 | + settings, lookup_client); |
| 722 | + |
| 723 | + read::PartitionsRequest request; |
| 724 | + request.WithPartitionIds({kPartitionId}); |
| 725 | + request.WithFetchOption(read::OnlineIfNotFound); |
| 726 | + |
| 727 | + auto response = repository.GetVersionedPartitionsExtendedResponse( |
| 728 | + request, kVersion, context); |
| 729 | + |
| 730 | + ASSERT_TRUE(response.IsSuccessful()); |
| 731 | + EXPECT_TRUE(response.GetResult().GetPartitions().empty()); |
| 732 | + } |
| 733 | + { |
| 734 | + SCOPED_TRACE("Cache utilised for valid partition"); |
| 735 | + |
| 736 | + OlpClientSettings settings; |
| 737 | + settings.cache = cache; |
| 738 | + settings.network_request_handler = mock_network; |
| 739 | + settings.retry_settings.timeout = 1; |
| 740 | + |
| 741 | + const std::string cache_key_1 = |
| 742 | + kCatalog + "::" + kVersionedLayerId + "::" + kPartitionId + |
| 743 | + "::" + std::to_string(kVersion) + "::partition"; |
| 744 | + |
| 745 | + EXPECT_CALL(*cache, Read(cache_key_1)) |
| 746 | + .WillOnce(Return(client::ApiError::NotFound())); |
| 747 | + |
| 748 | + EXPECT_CALL(*cache, Write(_, _, _)) |
| 749 | + .Times(4) |
| 750 | + .WillRepeatedly(Return(client::ApiNoResult())); |
| 751 | + |
| 752 | + EXPECT_CALL(*cache, Get(kCacheKeyMetadata, _)) |
| 753 | + .WillOnce(Return(kUrlQueryApi)); |
| 754 | + |
| 755 | + EXPECT_CALL(*mock_network, |
| 756 | + Send(IsGetRequest(kUrlQueryVersionedPartition), _, _, _, _)) |
| 757 | + .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( |
| 758 | + olp::http::HttpStatusCode::OK), |
| 759 | + kOlpSdkHttpResponsePartitions)); |
| 760 | + |
| 761 | + client::CancellationContext context; |
| 762 | + ApiLookupClient lookup_client(catalog, settings); |
| 763 | + repository::PartitionsRepository repository(catalog, kVersionedLayerId, |
| 764 | + settings, lookup_client); |
| 765 | + |
| 766 | + read::PartitionsRequest request; |
| 767 | + request.WithPartitionIds({kPartitionId}); |
| 768 | + request.WithFetchOption(read::OnlineIfNotFound); |
| 769 | + |
| 770 | + auto response = repository.GetVersionedPartitionsExtendedResponse( |
| 771 | + request, kVersion, context); |
| 772 | + |
| 773 | + ASSERT_TRUE(response.IsSuccessful()); |
| 774 | + EXPECT_EQ(response.GetResult().GetPartitions().size(), 4); |
| 775 | + } |
| 776 | +} |
| 777 | + |
| 778 | +TEST_F(PartitionsRepositoryTest, GetVersionedPartitions_WithCache) { |
| 779 | + using testing::Return; |
| 780 | + |
| 781 | + auto mock_network = std::make_shared<NetworkMock>(); |
| 782 | + const auto catalog = HRN::FromString(kCatalog); |
| 783 | + std::shared_ptr<cache::KeyValueCache> default_cache = |
| 784 | + client::OlpClientSettingsFactory::CreateDefaultCache({}); |
| 785 | + |
644 | 786 | { |
645 | 787 | SCOPED_TRACE("Successful fetch from network with a list of partitions"); |
646 | 788 |
|
|
0 commit comments