Unverified Commit 8cbb750f authored by Dennis Jenkins's avatar Dennis Jenkins Committed by GitHub

Merge pull request #315 from knowledge4igor/improve_client_and_endpoint_api

Improve Client and Endpoint init API and tiny changes in tests
parents 18976dc0 809f6221
......@@ -306,7 +306,6 @@ public:
: threads_(Default::Threads)
, maxConnectionsPerHost_(Default::MaxConnectionsPerHost)
, keepAlive_(Default::KeepAlive)
{ }
Options& threads(int val);
......@@ -323,7 +322,7 @@ public:
~Client();
static Options options();
void init(const Options& options);
void init(const Options& options = Options());
RequestBuilder get(const std::string& resource);
RequestBuilder post(const std::string& resource);
......
......@@ -38,7 +38,7 @@ public:
listener.init(std::forward<Args>(args)...);
}
void init(const Options& options);
void init(const Options& options = Options());
void setHandler(const std::shared_ptr<Handler>& handler);
void bind();
......@@ -78,14 +78,7 @@ private:
};
template<typename Handler>
void listenAndServe(Address addr)
{
auto options = Endpoint::options().threads(1);
listenAndServe<Handler>(addr, options);
}
template<typename Handler>
void listenAndServe(Address addr, const Endpoint::Options& options)
void listenAndServe(Address addr, const Endpoint::Options& options = Endpoint::options())
{
Endpoint endpoint(addr);
endpoint.init(options);
......
......@@ -22,14 +22,13 @@ TEST(http_client_test, one_client_with_one_request) {
Http::Endpoint server(address);
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags).threads(1);
auto server_opts = Http::Endpoint::options().flags(flags);
server.init(server_opts);
server.setHandler(Http::make_handler<HelloHandler>());
server.serveThreaded();
Http::Client client;
auto client_opts = Http::Client::options();
client.init(client_opts);
client.init();
std::vector<Async::Promise<Http::Response>> responses;
auto rb = client.get(address);
......@@ -56,14 +55,13 @@ TEST(http_client_test, one_client_with_multiple_requests) {
Http::Endpoint server(address);
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags).threads(1);
auto server_opts = Http::Endpoint::options().flags(flags);
server.init(server_opts);
server.setHandler(Http::make_handler<HelloHandler>());
server.serveThreaded();
Http::Client client;
auto client_opts = Http::Client::options().threads(1).maxConnectionsPerHost(1);
client.init(client_opts);
client.init();
std::vector<Async::Promise<Http::Response>> responses;
const int RESPONSE_SIZE = 3;
......@@ -95,19 +93,18 @@ TEST(http_client_test, multiple_clients_with_one_request) {
Http::Endpoint server(address);
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr;
auto server_opts = Http::Endpoint::options().flags(flags).threads(1);
auto server_opts = Http::Endpoint::options().flags(flags);
server.init(server_opts);
server.setHandler(Http::make_handler<HelloHandler>());
server.serveThreaded();
auto client_opts = Http::Client::options();
const int CLIENT_SIZE = 3;
Http::Client client1;
client1.init(client_opts);
client1.init();
Http::Client client2;
client2.init(client_opts);
client2.init();
Http::Client client3;
client3.init(client_opts);
client3.init();
std::vector<Async::Promise<Http::Response>> responses;
int response_counter = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment