594
594
EXPECT_EQ(url, root["url"].asString());
597
TEST(StreamingHttpClient, pause_and_resume)
599
using namespace ::testing;
600
// We obtain a default client instance, dispatching to the default implementation.
601
auto client = http::make_streaming_client();
603
// Execute the client
604
std::thread worker{[client]() { client->run(); }};
606
auto url = "https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tar.xz";
608
// The client mostly acts as a factory for http requests.
609
auto request = client->streaming_get(http::Request::Configuration::from_uri_as_string(url));
611
// Our mocked data handler.
612
auto dh = MockDataHandler::create(); EXPECT_CALL(*dh, on_new_data(_)).Times(AtLeast(1));
614
std::promise<core::net::http::Response> promise;
615
auto future = promise.get_future();
617
// We finally execute the query asynchronously.
618
request->async_execute(
619
http::Request::Handler()
620
.on_progress(default_progress_reporter)
621
.on_response([&](const core::net::http::Response& response)
623
promise.set_value(response);
625
.on_error([&](const core::net::Error& e)
627
promise.set_exception(std::make_exception_ptr(e));
629
dh->to_data_handler());
631
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
632
std::cout << "we pause" << std::endl;
635
//Please check if we can resume if we didn't set speed_limit/time option for this request
636
std::this_thread::sleep_for(std::chrono::microseconds(5000));
638
std::cout << "we resume." << std::endl;
641
auto response = future.get();
643
// We expect the query to complete successfully
644
EXPECT_EQ(core::net::http::Status::ok, response.status);
648
// We shut down our worker thread
649
if (worker.joinable())