Skip to content

Commit a3b2b28

Browse files
Add CancelPendingRequests in VolatileLayerClient
Add Add CancelPendingRequests in VolatileLayerClient and provide it implementation. Add test DataserviceReadVolatileLayerClientTest.CancelPendingRequestsPartitions. Resolves: OLPEDGE-1094 Signed-off-by: Diachenko Mykahilo <[email protected]>
1 parent 55978d8 commit a3b2b28

File tree

6 files changed

+94
-13
lines changed

6 files changed

+94
-13
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ class DATASERVICE_READ_API VolatileLayerClient final {
9090

9191
~VolatileLayerClient();
9292

93+
/**
94+
* @brief Cancels all active and pending requests.
95+
* @return True on success.
96+
*/
97+
bool CancelPendingRequests();
98+
9399
/**
94100
* @brief Fetches a list partitions for given volatile layer asynchronously.
95101
* @param request contains the complete set of request parameters.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ VolatileLayerClient& VolatileLayerClient::operator=(
4040

4141
VolatileLayerClient::~VolatileLayerClient() = default;
4242

43+
bool VolatileLayerClient::CancelPendingRequests() {
44+
return impl_->CancelPendingRequests();
45+
}
46+
4347
client::CancellationToken VolatileLayerClient::GetPartitions(
4448
PartitionsRequest request, PartitionsResponseCallback callback) {
4549
return impl_->GetPartitions(std::move(request), std::move(callback));

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ VolatileLayerClientImpl::~VolatileLayerClientImpl() {
7171
pending_requests_->CancelAllAndWait();
7272
}
7373

74+
bool VolatileLayerClientImpl::CancelPendingRequests() {
75+
OLP_SDK_LOG_TRACE(kLogTag, "CancelPendingRequests");
76+
return pending_requests_->CancelAll();
77+
}
78+
7479
client::CancellationToken VolatileLayerClientImpl::GetPartitions(
7580
PartitionsRequest request, PartitionsResponseCallback callback) {
7681
auto schedule_get_partitions = [&](PartitionsRequest request,

olp-cpp-sdk-dataservice-read/src/VolatileLayerClientImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class VolatileLayerClientImpl {
4646

4747
virtual ~VolatileLayerClientImpl();
4848

49+
virtual bool CancelPendingRequests();
50+
4951
virtual client::CancellationToken GetPartitions(
5052
PartitionsRequest request, PartitionsResponseCallback callback);
5153

tests/integration/olp-cpp-sdk-dataservice-read/HttpResponses.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@
179179
#define URL_QUERY_PARTITION_1476147 \
180180
R"(https://query.data.api.platform.here.com/query/v1/catalogs/)"+GetTestCatalog()+R"(/layers/hype-test-prefetch/partitions?partition=1476147&version=4)"
181181

182+
#define URL_QUERY_VOLATILE_PARTITION_269 \
183+
R"(https://query.data.api.platform.here.com/query/v1/catalogs/hereos-internal-test-v2/layers/testlayer_volatile/partitions?partition=269)"
184+
182185
#define URL_BLOB_DATA_PREFETCH_1 \
183186
R"(https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/hype-test-prefetch/data/a7a1afdf-db7e-4833-9627-d38bee6e2f81)"
184187

@@ -200,6 +203,9 @@
200203
#define URL_BLOB_DATA_PREFETCH_7 \
201204
R"(https://blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/hype-test-prefetch/data/95c5c703-e00e-4c38-841e-e419367474f1)"
202205

206+
#define URL_VOLATILE_BLOB_DATA \
207+
R"(https://volatile-blob-ireland.data.api.platform.here.com/blobstore/v1/catalogs/hereos-internal-test-v2/layers/testlayer_volatile/data/4eed6ed1-0d32-43b9-ae79-043cb4256410)"
208+
203209
#define HTTP_RESPONSE_CONFIG_V2 \
204210
R"jsonString({"id":"hereos-internal-test-v2","hrn":"hrn:here:data::olp-here-test:hereos-internal-test-v2","name":"hereos-internal-test-v2","summary":"hereos-internal-test-v2","description":"Used for internal testing","contacts":{},"owner":{"creator":{"id":"9PBigz3zyXks0OlAQv13"},"organisation":{"id":"olp-here-test"}},"tags":[],"billingTags":[],"created":"2019-01-10T22:30:12.917Z","replication":{"regions":[{"id":"eu-ireland","role":"primary"}]},"layers":[{"id":"hype-test-prefetch","hrn":"hrn:here:data::olp-here-test:hereos-internal-test-v2:hype-test-prefetch","name":"Hype Test Prefetch","summary":"hype prefetch testing","description":"Layer for hype prefetch testing","owner":{"creator":{"id":"9PBigz3zyXks0OlAQv13"},"organisation":{"id":"olp-here-test"}},"partitioningScheme":"heretile","partitioning":{"tileLevels":[],"scheme":"heretile"},"contentType":"application/x-protobuf","volume":{"volumeType":"durable"},"tags":["TEST"],"billingTags":[],"created":"2019-01-10T22:30:12.917Z","layerType":"versioned"},{"id":"hype-test-prefetch-2","hrn":"hrn:here:data::olp-here-test:hereos-internal-test-v2:hype-test-prefetch-2","name":"Hype Test Prefetch2","summary":"Layer for testing hype2 prefetching","description":"Layer for testing hype2 prefetching","owner":{"creator":{"id":"9PBigz3zyXks0OlAQv13"},"organisation":{"id":"olp-here-test"}},"partitioningScheme":"heretile","partitioning":{"tileLevels":[],"scheme":"heretile"},"contentType":"application/x-protobuf","volume":{"volumeType":"durable"},"tags":["TEST"],"billingTags":[],"created":"2019-01-10T22:30:12.917Z","layerType":"versioned"},{"id":"testlayer_res","hrn":"hrn:here:data::olp-here-test:hereos-internal-test-v2:testlayer_res","name":"Resource Test Layer","summary":"testlayer_res","description":"testlayer_res","owner":{"creator":{"id":"9PBigz3zyXks0OlAQv13"},"organisation":{"id":"olp-here-test"}},"partitioningScheme":"generic","partitioning":{"scheme":"generic"},"contentType":"application/x-protobuf","volume":{"volumeType":"durable"},"tags":["TEST"],"billingTags":[],"created":"2019-01-10T22:30:12.917Z","layerType":"versioned"},{"id":"testlayer","hrn":"hrn:here:data::olp-here-test:hereos-internal-test-v2:testlayer","name":"Test Layer","summary":"Test Layer","description":"A simple test layer","owner":{"creator":{"id":"9PBigz3zyXks0OlAQv13"},"organisation":{"id":"olp-here-test"}},"partitioningScheme":"generic","partitioning":{"scheme":"generic"},"contentType":"application/x-protobuf","volume":{"volumeType":"durable"},"tags":["TEST"],"billingTags":[],"created":"2019-01-10T22:30:12.917Z","layerType":"versioned"},{"id":"testlayer_gzip","hrn":"hrn:here:data::olp-here-test:hereos-internal-test-v2:testlayer_gzip","name":"Test Layer","summary":"Test Layer","description":"A simple compressed test layer","owner":{"creator":{"id":"9PBigz3zyXks0OlAQv13"},"organisation":{"id":"olp-here-test"}},"partitioningScheme":"generic","partitioning":{"scheme":"generic"},"contentType":"application/x-protobuf","contentEncoding":"gzip","volume":{"volumeType":"durable"},"tags":["TEST"],"billingTags":[],"created":"2019-01-10T22:30:12.917Z","layerType":"versioned"},{"id":"multilevel_testlayer","hrn":"hrn:here:data::olp-here-test:hereos-internal-test-v2:multilevel_testlayer","name":"Multi Level Test Layer","summary":"Multi Level Test Layer","description":"A multi level test layer just for testing","owner":{"creator":{"id":"9PBigz3zyXks0OlAQv13"},"organisation":{"id":"olp-here-test"}},"partitioningScheme":"generic","partitioning":{"scheme":"generic"},"contentType":"application/x-protobuf","volume":{"volumeType":"durable"},"tags":["TEST"],"billingTags":[],"created":"2019-01-10T22:30:12.917Z","layerType":"versioned"}],"marketplaceReady":false,"version":1})jsonString"
205211

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

Lines changed: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -730,23 +730,14 @@ TEST_F(DataserviceReadVolatileLayerClientTest, GetVolatileDataByPartitionId) {
730730
Send(IsGetRequest(URL_LATEST_CATALOG_VERSION), _, _, _, _))
731731
.Times(0);
732732

733-
EXPECT_CALL(
734-
*network_mock_,
735-
Send(IsGetRequest("https://query.data.api.platform.here.com/query/v1/"
736-
"catalogs/hereos-internal-test-v2/layers/"
737-
"testlayer_volatile/partitions?partition=269"),
738-
_, _, _, _))
733+
EXPECT_CALL(*network_mock_,
734+
Send(IsGetRequest(URL_QUERY_VOLATILE_PARTITION_269), _, _, _, _))
739735
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
740736
olp::http::HttpStatusCode::OK),
741737
HTTP_RESPONSE_PARTITIONS_V2));
742738

743-
EXPECT_CALL(
744-
*network_mock_,
745-
Send(IsGetRequest(
746-
"https://volatile-blob-ireland.data.api.platform.here.com/"
747-
"blobstore/v1/catalogs/hereos-internal-test-v2/layers/"
748-
"testlayer_volatile/data/4eed6ed1-0d32-43b9-ae79-043cb4256410"),
749-
_, _, _, _))
739+
EXPECT_CALL(*network_mock_,
740+
Send(IsGetRequest(URL_VOLATILE_BLOB_DATA), _, _, _, _))
750741
.WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
751742
olp::http::HttpStatusCode::OK),
752743
"someData"));
@@ -769,4 +760,71 @@ TEST_F(DataserviceReadVolatileLayerClientTest, GetVolatileDataByPartitionId) {
769760
ASSERT_EQ("someData", data_string);
770761
}
771762

763+
TEST_F(DataserviceReadVolatileLayerClientTest,
764+
CancelPendingRequestsPartitions) {
765+
olp::client::HRN hrn(GetTestCatalog());
766+
767+
auto client = std::make_unique<VolatileLayerClient>(hrn, "testlayer_volatile",
768+
settings_);
769+
auto partitions_request = PartitionsRequest().WithFetchOption(OnlineOnly);
770+
auto data_request =
771+
DataRequest().WithPartitionId("269").WithFetchOption(OnlineOnly);
772+
773+
auto request_started = std::make_shared<std::promise<void>>();
774+
auto continue_request = std::make_shared<std::promise<void>>();
775+
776+
{
777+
olp::http::RequestId request_id;
778+
NetworkCallback send_mock;
779+
CancelCallback cancel_mock;
780+
781+
std::tie(request_id, send_mock, cancel_mock) = GenerateNetworkMockActions(
782+
request_started, continue_request,
783+
{olp::http::HttpStatusCode::OK, HTTP_RESPONSE_PARTITIONS_V2});
784+
785+
EXPECT_CALL(
786+
*network_mock_,
787+
Send(IsGetRequest(URL_QUERY_VOLATILE_PARTITION_269), _, _, _, _))
788+
.Times(1)
789+
.WillOnce(testing::Invoke(std::move(send_mock)));
790+
791+
EXPECT_CALL(*network_mock_, Cancel(request_id))
792+
.WillOnce(testing::Invoke(std::move(cancel_mock)));
793+
794+
ON_CALL(*network_mock_,
795+
Send(IsGetRequest(URL_VOLATILE_BLOB_DATA), _, _, _, _))
796+
.WillByDefault(
797+
ReturnHttpResponse(olp::http::NetworkResponse().WithStatus(
798+
olp::http::HttpStatusCode::OK),
799+
"someData"));
800+
}
801+
802+
auto data_future = client->GetData(data_request);
803+
auto partitions_future = client->GetPartitions(partitions_request);
804+
805+
request_started->get_future().get();
806+
client->CancelPendingRequests();
807+
continue_request->set_value();
808+
809+
PartitionsResponse partitions_response = partitions_future.GetFuture().get();
810+
811+
ASSERT_FALSE(partitions_response.IsSuccessful())
812+
<< ApiErrorToString(partitions_response.GetError());
813+
814+
ASSERT_EQ(static_cast<int>(olp::http::ErrorCode::CANCELLED_ERROR),
815+
partitions_response.GetError().GetHttpStatusCode());
816+
ASSERT_EQ(olp::client::ErrorCode::Cancelled,
817+
partitions_response.GetError().GetErrorCode());
818+
819+
DataResponse data_response = data_future.GetFuture().get();
820+
821+
ASSERT_FALSE(data_response.IsSuccessful())
822+
<< ApiErrorToString(data_response.GetError());
823+
824+
ASSERT_EQ(static_cast<int>(olp::http::ErrorCode::CANCELLED_ERROR),
825+
data_response.GetError().GetHttpStatusCode());
826+
ASSERT_EQ(olp::client::ErrorCode::Cancelled,
827+
data_response.GetError().GetErrorCode());
828+
}
829+
772830
} // namespace

0 commit comments

Comments
 (0)