Skip to content

Commit fcd693c

Browse files
author
Liubov Didkivska
authored
Make CacheWithUpdate option unsuported for VersionedLayerClient. (#699)
* Make CacheWithUpdate option unsupported for VersionedLayerClient. CacheWithUpdate fetch option are not supported for versioned layer. Version is locked in constructor for VersionуdLayerClient, so if data are already in the cache, it makes no sense to update online. Update tests. Relates-To: OLPEDGE-1658 Signed-off-by: Liubov Didkivska <[email protected]>
1 parent e743509 commit fcd693c

File tree

4 files changed

+71
-62
lines changed

4 files changed

+71
-62
lines changed

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/FetchOptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ enum FetchOptions {
4343
/**
4444
* Returns the requested cached resource if it is found and updates the cache
4545
* in the background.
46+
* @note Do not Use for versioned layer client requests.
4647
*/
4748
CacheWithUpdate
4849
};

olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/VersionedLayerClient.h

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
164164
*
165165
* @param data_request The `DataRequest` instance that contains a complete set
166166
* of request parameters.
167-
* @note The `GetLayerId` value of the \c DataRequest object is ignored, and
168-
* the parameter from the constructor is used instead.
167+
* @note CacheWithUpdate fetch option is not suported.
169168
* @param callback The `DataResponseCallback` object that is invoked if
170169
* the `DataResult` object is available or an error is encountered.
171170
*
@@ -185,8 +184,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
185184
*
186185
* @param data_request The `DataRequest` instance that contains a complete set
187186
* of request parameters.
188-
* @note The `GetLayerId` value of the \c DataRequest object is ignored, and
189-
* the parameter from the constructor is used instead.
187+
* @note CacheWithUpdate fetch option is not suported.
190188
*
191189
* @return `CancellableFuture` that contains the `DataResponse` instance
192190
* or an error. You can also use `CancellableFuture` to cancel this request.
@@ -209,6 +207,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
209207
*
210208
* @param request The `TileRequest` instance that contains a complete set
211209
* of request parameters.
210+
* @note CacheWithUpdate fetch option is not suported.
212211
* @param callback The `DataResponseCallback` object that is invoked if
213212
* the `DataResult` object is available or an error is encountered.
214213
*
@@ -232,6 +231,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
232231
*
233232
* @param request The `TileRequest` instance that contains a complete set
234233
* of request parameters.
234+
* @note CacheWithUpdate fetch option is not suported.
235235
*
236236
* @return `CancellableFuture` that contains the `DataResponse` instance
237237
* or an error. You can also use `CancellableFuture` to cancel this request.
@@ -247,8 +247,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
247247
*
248248
* @param partitions_request The `PartitionsRequest` instance that contains
249249
* a complete set of request parameters.
250-
* @note The `GetLayerId` value of the \c PartitionsRequest object is ignored,
251-
* and the parameter from the constructor is used instead.
250+
* @note CacheWithUpdate fetch option is not suported.
252251
* @param callback The `PartitionsResponseCallback` object that is invoked if
253252
* the list of partitions is available or an error is encountered.
254253
*
@@ -267,8 +266,7 @@ class DATASERVICE_READ_API VersionedLayerClient final {
267266
*
268267
* @param partitions_request The `PartitionsRequest` instance that contains
269268
* a complete set of request parameters.
270-
* @note The `GetLayerId` value of the \c PartitionsRequest object is ignored,
271-
* and the parameter from the constructor is used instead.
269+
* @note CacheWithUpdate fetch option is not suported.
272270
*
273271
* @return `CancellableFuture` that contains the `PartitionsResponse` instance
274272
* with data or an error. You can also use `CancellableFuture` to cancel this
@@ -290,8 +288,6 @@ class DATASERVICE_READ_API VersionedLayerClient final {
290288
*
291289
* @param request The `PrefetchTilesRequest` instance that contains
292290
* a complete set of request parameters.
293-
* @note The `GetLayerId` value of the \c PrefetchTilesRequest object is
294-
* ignored, and the parameter from the constructor is used instead.
295291
* @param callback The `PrefetchTilesResponseCallback` object that is invoked
296292
* if the `PrefetchTilesResult` instance is available or an error is
297293
* encountered.
@@ -314,8 +310,6 @@ class DATASERVICE_READ_API VersionedLayerClient final {
314310
*
315311
* @param request The `PrefetchTilesRequest` instance that contains
316312
* a complete set of request parameters.
317-
* @note The `GetLayerId` value of the \c PrefetchTilesRequest object is
318-
* ignored, and the parameter from the constructor is used instead.
319313
*
320314
* @return `CancellableFuture` that contains the `PrefetchTilesResponse`
321315
* instance with data or an error. You can also use `CancellableFuture` to

olp-cpp-sdk-dataservice-read/src/VersionedLayerClientImpl.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ client::CancellationToken VersionedLayerClientImpl::GetPartitions(
7474
"VersionedLayerClient constructor to specify version");
7575
}
7676

77+
if (request.GetFetchOption() == CacheWithUpdate) {
78+
auto task = [](client::CancellationContext) -> PartitionsResponse {
79+
return {{client::ErrorCode::InvalidArgument,
80+
"CacheWithUpdate option can not be used for versioned "
81+
"layer"}};
82+
};
83+
return AddTask(settings_.task_scheduler, pending_requests_, std::move(task),
84+
std::move(callback));
85+
}
86+
7787
auto schedule_get_partitions = [&](PartitionsRequest request,
7888
PartitionsResponseCallback callback) {
7989
auto catalog = catalog_;
@@ -120,6 +130,16 @@ client::CancellationToken VersionedLayerClientImpl::GetData(
120130
"VersionedLayerClient constructor to specify version");
121131
}
122132

133+
if (request.GetFetchOption() == CacheWithUpdate) {
134+
auto task = [](client::CancellationContext) -> DataResponse {
135+
return {{client::ErrorCode::InvalidArgument,
136+
"CacheWithUpdate option can not be used for versioned "
137+
"layer"}};
138+
};
139+
return AddTask(settings_.task_scheduler, pending_requests_, std::move(task),
140+
std::move(callback));
141+
}
142+
123143
auto schedule_get_data = [&](DataRequest request,
124144
DataResponseCallback callback) {
125145
auto catalog = catalog_;
@@ -145,6 +165,7 @@ client::CancellationToken VersionedLayerClientImpl::GetData(
145165
return AddTask(settings.task_scheduler, pending_requests_,
146166
std::move(data_task), std::move(callback));
147167
};
168+
148169
return ScheduleFetch(std::move(schedule_get_data), std::move(request),
149170
std::move(callback));
150171
}
@@ -378,6 +399,16 @@ CatalogVersionResponse VersionedLayerClientImpl::GetVersion(
378399

379400
client::CancellationToken VersionedLayerClientImpl::GetData(
380401
TileRequest request, DataResponseCallback callback) {
402+
if (request.GetFetchOption() == CacheWithUpdate) {
403+
auto task = [](client::CancellationContext) -> DataResponse {
404+
return {{client::ErrorCode::InvalidArgument,
405+
"CacheWithUpdate option can not be used for versioned "
406+
"layer"}};
407+
};
408+
return AddTask(settings_.task_scheduler, pending_requests_, std::move(task),
409+
std::move(callback));
410+
}
411+
381412
auto schedule_get_data = [&](TileRequest request,
382413
DataResponseCallback callback) {
383414
auto catalog = catalog_;

tests/integration/olp-cpp-sdk-dataservice-read/VersionedLayerClientTest.cpp

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ TEST_F(DataserviceReadVersionedLayerClientTest,
550550
}
551551

552552
TEST_F(DataserviceReadVersionedLayerClientTest,
553-
GetDataFromPartitionCacheAndUpdateSync) {
553+
GetDataFromPartitionOnlineIfNotFoundCacheUpdate) {
554554
EXPECT_CALL(*network_mock_, Send(_, _, _, _, _))
555555
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
556556
olp::http::HttpStatusCode::OK),
@@ -582,10 +582,9 @@ TEST_F(DataserviceReadVersionedLayerClientTest,
582582
auto token = client->GetData(
583583
olp::dataservice::read::DataRequest()
584584
.WithPartitionId(partition)
585-
.WithFetchOption(FetchOptions::CacheWithUpdate),
585+
.WithFetchOption(FetchOptions::OnlineIfNotFound),
586586
[&response](DataResponse resp) { response = std::move(resp); });
587-
ASSERT_FALSE(response.IsSuccessful());
588-
ASSERT_FALSE(response.GetResult() != nullptr);
587+
ASSERT_TRUE(response.IsSuccessful());
589588

590589
token = client->GetData(
591590
olp::dataservice::read::DataRequest()
@@ -868,7 +867,7 @@ TEST_F(DataserviceReadVersionedLayerClientTest,
868867
olp::dataservice::read::DataRequest()
869868
.WithVersion(version)
870869
.WithPartitionId(partition)
871-
.WithFetchOption(FetchOptions::CacheWithUpdate),
870+
.WithFetchOption(FetchOptions::OnlineIfNotFound),
872871
[&promise](DataResponse response) { promise.set_value(response); });
873872

874873
wait_for_cancel->get_future().get();
@@ -1084,25 +1083,6 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetPartitionsCacheWithUpdate) {
10841083
auto catalog = olp::client::HRN::FromString(
10851084
GetArgument("dataservice_read_test_catalog"));
10861085
auto layer = GetArgument("dataservice_read_test_layer");
1087-
1088-
auto wait_to_start_signal = std::make_shared<std::promise<void>>();
1089-
auto pre_callback_wait = std::make_shared<std::promise<void>>();
1090-
pre_callback_wait->set_value();
1091-
auto wait_for_end_signal = std::make_shared<std::promise<void>>();
1092-
1093-
olp::http::RequestId request_id;
1094-
NetworkCallback send_mock;
1095-
CancelCallback cancel_mock;
1096-
1097-
std::tie(request_id, send_mock, cancel_mock) = GenerateNetworkMockActions(
1098-
wait_to_start_signal, pre_callback_wait,
1099-
{olp::http::HttpStatusCode::OK, HTTP_RESPONSE_PARTITIONS},
1100-
wait_for_end_signal);
1101-
1102-
EXPECT_CALL(*network_mock_, Send(IsGetRequest(URL_PARTITIONS), _, _, _, _))
1103-
.Times(1)
1104-
.WillOnce(testing::Invoke(std::move(send_mock)));
1105-
11061086
auto client = std::make_unique<olp::dataservice::read::VersionedLayerClient>(
11071087
catalog, layer, *settings_);
11081088

@@ -1121,8 +1101,6 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetPartitionsCacheWithUpdate) {
11211101
ASSERT_FALSE(response.IsSuccessful()) << response.GetError().GetMessage();
11221102
}
11231103

1124-
wait_for_end_signal->get_future().get();
1125-
11261104
// Request 2
11271105
{
11281106
auto promise = std::make_shared<std::promise<PartitionsResponse>>();
@@ -1134,8 +1112,8 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetPartitionsCacheWithUpdate) {
11341112
});
11351113
ASSERT_NE(future.wait_for(kWaitTimeout), std::future_status::timeout);
11361114
PartitionsResponse response = future.get();
1137-
// Cache should be available here.
1138-
ASSERT_TRUE(response.IsSuccessful()) << response.GetError().GetMessage();
1115+
// Cache should not be available for versioned layer.
1116+
ASSERT_FALSE(response.IsSuccessful()) << response.GetError().GetMessage();
11391117
}
11401118
}
11411119

@@ -1949,24 +1927,6 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetData403CacheClear) {
19491927

19501928
TEST_F(DataserviceReadVersionedLayerClientTest, GetDataCacheWithUpdate) {
19511929
olp::client::HRN hrn(GetTestCatalog());
1952-
// Setup the expected calls :
1953-
auto wait_to_start_signal = std::make_shared<std::promise<void>>();
1954-
auto pre_callback_wait = std::make_shared<std::promise<void>>();
1955-
pre_callback_wait->set_value();
1956-
auto wait_for_end_signal = std::make_shared<std::promise<void>>();
1957-
1958-
olp::http::RequestId request_id;
1959-
NetworkCallback send_mock;
1960-
CancelCallback cancel_mock;
1961-
1962-
std::tie(request_id, send_mock, cancel_mock) = GenerateNetworkMockActions(
1963-
wait_to_start_signal, pre_callback_wait,
1964-
{olp::http::HttpStatusCode::OK, HTTP_RESPONSE_BLOB_DATA_269},
1965-
wait_for_end_signal);
1966-
1967-
EXPECT_CALL(*network_mock_, Send(IsGetRequest(URL_BLOB_DATA_269), _, _, _, _))
1968-
.Times(1)
1969-
.WillOnce(testing::Invoke(std::move(send_mock)));
19701930

19711931
auto client =
19721932
std::make_unique<VersionedLayerClient>(hrn, "testlayer", *settings_);
@@ -1979,13 +1939,11 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetDataCacheWithUpdate) {
19791939
ASSERT_FALSE(data_response.IsSuccessful())
19801940
<< ApiErrorToString(data_response.GetError());
19811941
// Request 2 to check there is a cached value.
1982-
// waiting for cache to fill-in
1983-
wait_for_end_signal->get_future().get();
19841942
request.WithFetchOption(CacheOnly);
19851943
future = client->GetData(request);
19861944
data_response = future.GetFuture().get();
1987-
// Cache should be available here.
1988-
ASSERT_TRUE(data_response.IsSuccessful())
1945+
// Cache should not be available for versioned layer.
1946+
ASSERT_FALSE(data_response.IsSuccessful())
19891947
<< ApiErrorToString(data_response.GetError());
19901948
}
19911949

@@ -2685,6 +2643,31 @@ TEST_F(DataserviceReadVersionedLayerClientTest, GetTileOnlineOnly) {
26852643
}
26862644
}
26872645

2646+
TEST_F(DataserviceReadVersionedLayerClientTest, GetTileCacheWithUpdate) {
2647+
olp::client::HRN hrn(GetTestCatalog());
2648+
auto client = std::make_unique<olp::dataservice::read::VersionedLayerClient>(
2649+
hrn, "testlayer", 4, *settings_);
2650+
2651+
auto request = olp::dataservice::read::TileRequest()
2652+
.WithTileKey(olp::geo::TileKey::FromHereTile("5904591"))
2653+
.WithFetchOption(CacheWithUpdate);
2654+
{
2655+
std::cout << "request<=" << request.GetFetchOption() << std::endl;
2656+
SCOPED_TRACE("Request data using TileKey.");
2657+
auto data_response = client->GetData(request).GetFuture().get();
2658+
2659+
ASSERT_FALSE(data_response.IsSuccessful())
2660+
<< ApiErrorToString(data_response.GetError());
2661+
}
2662+
2663+
{
2664+
SCOPED_TRACE("Check cache, should not be avialible.");
2665+
auto future = client->GetData(request.WithFetchOption(CacheOnly));
2666+
auto data_response = future.GetFuture().get();
2667+
ASSERT_FALSE(data_response.IsSuccessful());
2668+
}
2669+
}
2670+
26882671
TEST_F(DataserviceReadVersionedLayerClientTest, GetTileTwoSequentialCalls) {
26892672
olp::client::HRN hrn(GetTestCatalog());
26902673
auto client = std::make_unique<olp::dataservice::read::VersionedLayerClient>(

0 commit comments

Comments
 (0)