Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion olp-cpp-sdk-core/include/olp/core/client/ErrorCode.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2025 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -101,6 +101,11 @@ enum class ErrorCode {
* Absence of network connectivity.
*/
Offline,

/**
* The requested content does not exist in the requested resource.
*/
NoContent,
};

} // namespace client
Expand Down
8 changes: 4 additions & 4 deletions olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2025 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -341,8 +341,8 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchPartitions(
auto download = [=](std::string data_handle,
client::CancellationContext inner_context) mutable {
if (data_handle.empty()) {
return BlobApi::DataResponse(
client::ApiError(client::ErrorCode::NotFound, "Not found"));
return BlobApi::DataResponse(client::ApiError(
client::ErrorCode::NoContent, "Partition is empty"));
}
repository::DataCacheRepository data_cache_repository(catalog_,
settings_.cache);
Expand Down Expand Up @@ -533,7 +533,7 @@ client::CancellationToken VersionedLayerClientImpl::PrefetchTiles(
client::CancellationContext inner_context) mutable {
if (data_handle.empty()) {
return BlobApi::DataResponse(
ApiError(ErrorCode::NotFound, "Not found"));
ApiError(ErrorCode::NoContent, "Partition is empty"));
}

repository::DataCacheRepository cache(catalog_,
Expand Down
6 changes: 3 additions & 3 deletions olp-cpp-sdk-dataservice-read/src/VolatileLayerClientImpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -251,8 +251,8 @@ client::CancellationToken VolatileLayerClientImpl::PrefetchTiles(
auto download = [=](std::string data_handle,
client::CancellationContext inner_context) mutable {
if (data_handle.empty()) {
return BlobApi::DataResponse(
client::ApiError(client::ErrorCode::NotFound, "Not found"));
return BlobApi::DataResponse(client::ApiError(
client::ErrorCode::NoContent, "Partition is empty"));
}
repository::DataCacheRepository data_cache_repository(
catalog_, settings_.cache);
Expand Down
10 changes: 6 additions & 4 deletions olp-cpp-sdk-dataservice-read/src/repositories/DataRepository.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -123,8 +123,9 @@ BlobApi::DataResponse DataRepository::GetVersionedData(
catalog_.ToCatalogHRNString().c_str(),
request.CreateKey(layer_id, version).c_str());

return DataResponse(client::ApiError::NotFound("Partition not found"),
network_statistics);
return DataResponse(
client::ApiError(client::ErrorCode::NoContent, "Partition is empty"),
network_statistics);
}

partition = std::move(partitions.front());
Expand Down Expand Up @@ -281,7 +282,8 @@ BlobApi::DataResponse DataRepository::GetVolatileData(
catalog_.ToCatalogHRNString().c_str(),
request.CreateKey(layer_id, olp::porting::none).c_str());

return client::ApiError::NotFound("Partition not found");
return client::ApiError(client::ErrorCode::NoContent,
"Partition is empty");
}

partition = std::move(partitions.front());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
#include "PartitionsRepository.h"

#include <algorithm>
#include <memory>
#include <utility>

#include <olp/core/cache/KeyGenerator.h>
Expand Down Expand Up @@ -169,6 +170,32 @@ bool CheckAdditionalFields(

return true;
}

model::Partitions CreateNoContentPartitions(
const std::vector<std::string>& partition_ids) {
model::Partitions result;
auto& partitions = result.GetMutablePartitions();
partitions.reserve(partition_ids.size());

std::transform(partition_ids.cbegin(), partition_ids.cend(),
std::back_inserter(partitions),
[&](const std::string& partition_id) {
// Partition can't be empty, see `Partition::GetPartition`.
// Data handle is the only not optional field and actual data
// is requested by the data handle so not setting it is a
// sign that `Partition` object has no corresponding data.
model::Partition partition;
partition.SetPartition(partition_id);
return partition;
});

return result;
}

bool HasNoContent(const model::Partition& partition) {
return partition.GetDataHandle().empty();
}

} // namespace

namespace olp {
Expand Down Expand Up @@ -252,6 +279,16 @@ PartitionsRepository::GetPartitionsExtendedResponse(
OLP_SDK_LOG_TRACE_F(kLogTag,
"GetPartitions found in cache, hrn='%s', key='%s'",
catalog_str.c_str(), key.c_str());

// Clear from cached NoContent partitions
auto& mutable_partitions = cached_partitions->GetMutablePartitions();
mutable_partitions.erase(
std::remove_if(mutable_partitions.begin(), mutable_partitions.end(),
[](const model::Partition& partition) {
return HasNoContent(partition);
}),
mutable_partitions.end());

return *cached_partitions;
} else if (fetch_option == CacheOnly) {
OLP_SDK_LOG_TRACE_F(
Expand Down Expand Up @@ -356,6 +393,16 @@ PartitionsResponse PartitionsRepository::GetPartitionById(
OLP_SDK_LOG_TRACE_F(kLogTag,
"GetPartitionById found in cache, hrn='%s', key='%s'",
catalog_.ToCatalogHRNString().c_str(), key.c_str());

// Clear from cached NoContent partitions
auto& mutable_partitions = cached_partitions.GetMutablePartitions();
mutable_partitions.erase(
std::remove_if(mutable_partitions.begin(), mutable_partitions.end(),
[](const model::Partition& partition) {
return HasNoContent(partition);
}),
mutable_partitions.end());

return cached_partitions;
} else if (fetch_option == CacheOnly) {
OLP_SDK_LOG_TRACE_F(
Expand Down Expand Up @@ -383,8 +430,13 @@ PartitionsResponse PartitionsRepository::GetPartitionById(
OLP_SDK_LOG_TRACE_F(kLogTag,
"GetPartitionById put to cache, hrn='%s', key='%s'",
catalog_.ToCatalogHRNString().c_str(), key.c_str());

const auto put_result =
cache_.Put(query_response.GetResult(), version, olp::porting::none);
cache_.Put(!query_response.GetResult().GetPartitions().empty()
? query_response.GetResult()
: CreateNoContentPartitions(partitions),
version, olp::porting::none);

if (!put_result.IsSuccessful()) {
OLP_SDK_LOG_ERROR_F(kLogTag,
"GetPartitionById failed to write data to cache, "
Expand Down
60 changes: 51 additions & 9 deletions olp-cpp-sdk-dataservice-read/tests/VolatileLayerClientImplTest.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -42,6 +42,7 @@ namespace read = olp::dataservice::read;
namespace model = olp::dataservice::read::model;
using ::testing::_;
using ::testing::Mock;
using ::testing::Return;

constexpr auto kUrlVolatileBlobData =
R"(https://volatile-blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/testlayer/data/4eed6ed1-0d32-43b9-ae79-043cb4256432)";
Expand Down Expand Up @@ -79,6 +80,12 @@ constexpr auto kUrlPrefetchBlobData1 =
constexpr auto kUrlPrefetchBlobData2 =
R"(https://volatile-blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/testlayer/data/e83b397a-2be5-45a8-b7fb-ad4cb3ea13b1)";

constexpr auto kCacheKeyPartition269 =
R"(hrn:here:data::olp-here-test:hereos-internal-test-v2::testlayer::269::partition)";

const std::string kNoContentPartition269Str =
R"({"dataHandle":"","partition":"269"})";

const std::string kCatalog =
"hrn:here:data::olp-here-test:hereos-internal-test-v2";
const std::string kLayerId = "testlayer";
Expand Down Expand Up @@ -109,13 +116,14 @@ TEST(VolatileLayerClientImplTest, GetData) {
settings.cache = cache_mock;
read::VolatileLayerClientImpl client(kHrn, kLayerId, settings);

EXPECT_CALL(*network_mock, Send(IsGetRequest(kUrlLookup), _, _, _, _))
.WillRepeatedly(
ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
olp::http::HttpStatusCode::OK),
kHttpResponseLookup));

{
SCOPED_TRACE("Get Data with DataHandle");
EXPECT_CALL(*network_mock, Send(IsGetRequest(kUrlLookup), _, _, _, _))
.WillRepeatedly(
ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
olp::http::HttpStatusCode::OK),
kHttpResponseLookup));

SetupNetworkExpectation(*network_mock, kUrlVolatileBlobData, "someData",
olp::http::HttpStatusCode::OK);
Expand Down Expand Up @@ -191,6 +199,40 @@ TEST(VolatileLayerClientImplTest, GetData) {
kHttpResponseNoPartition,
olp::http::HttpStatusCode::OK);

EXPECT_CALL(*cache_mock, Read(kCacheKeyPartition269))
.WillOnce(Return(olp::client::ApiError::NotFound()));

EXPECT_CALL(*cache_mock, Write(kCacheKeyPartition269, _, _))
.WillOnce(Return(olp::client::ApiNoResult()));

std::promise<read::DataResponse> promise;
std::future<read::DataResponse> future = promise.get_future();

auto token = client.GetData(
read::DataRequest().WithPartitionId(kPartitionId),
[&](read::DataResponse response) { promise.set_value(response); });

EXPECT_EQ(future.wait_for(kTimeout), std::future_status::ready);

const auto& response = future.get();
ASSERT_FALSE(response.IsSuccessful());
EXPECT_EQ(response.GetError().GetErrorCode(),
olp::client::ErrorCode::NoContent);

Mock::VerifyAndClearExpectations(network_mock.get());
}

{
SCOPED_TRACE("Get Data from non existent partition utilizes cache");

auto expected_cached_value =
std::make_shared<olp::cache::KeyValueCache::ValueType>(
kNoContentPartition269Str.cbegin(),
kNoContentPartition269Str.cend());

EXPECT_CALL(*cache_mock, Read(kCacheKeyPartition269))
.WillOnce(Return(expected_cached_value));

std::promise<read::DataResponse> promise;
std::future<read::DataResponse> future = promise.get_future();

Expand All @@ -203,7 +245,7 @@ TEST(VolatileLayerClientImplTest, GetData) {
const auto& response = future.get();
ASSERT_FALSE(response.IsSuccessful());
EXPECT_EQ(response.GetError().GetErrorCode(),
olp::client::ErrorCode::NotFound);
olp::client::ErrorCode::NoContent);

Mock::VerifyAndClearExpectations(network_mock.get());
}
Expand Down Expand Up @@ -292,7 +334,7 @@ TEST(VolatileLayerClientImplTest, GetDataCancellableFuture) {
const auto& response = future.get();
ASSERT_FALSE(response.IsSuccessful());
EXPECT_EQ(response.GetError().GetErrorCode(),
olp::client::ErrorCode::NotFound);
olp::client::ErrorCode::NoContent);

Mock::VerifyAndClearExpectations(network_mock.get());
}
Expand Down Expand Up @@ -677,7 +719,7 @@ TEST(VolatileLayerClientImplTest, PrefetchTiles) {
for (auto& tile_result : result) {
std::string str = tile_result->tile_key_.ToHereTile();
ASSERT_FALSE(tile_result->IsSuccessful());
ASSERT_EQ(olp::client::ErrorCode::NotFound,
ASSERT_EQ(olp::client::ErrorCode::NoContent,
tile_result->GetError().GetErrorCode());
ASSERT_TRUE(tile_result->tile_key_.IsValid());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2019-2024 HERE Europe B.V.
* Copyright (C) 2019-2026 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -2057,7 +2057,7 @@ TEST_F(DataserviceReadVersionedLayerClientTest,
for (auto tile_result : response.GetResult()) {
std::string str = tile_result->tile_key_.ToHereTile();
ASSERT_FALSE(tile_result->IsSuccessful());
ASSERT_EQ(olp::client::ErrorCode::NotFound,
ASSERT_EQ(olp::client::ErrorCode::NoContent,
tile_result->GetError().GetErrorCode());
ASSERT_TRUE(tile_result->tile_key_.IsValid());
}
Expand Down
Loading