Commit 02c30e49 authored by knowledge4igor's avatar knowledge4igor

Improve Client and Endpoint init API and tiny changes in tests

parent bf80caf9
...@@ -306,7 +306,6 @@ public: ...@@ -306,7 +306,6 @@ public:
: threads_(Default::Threads) : threads_(Default::Threads)
, maxConnectionsPerHost_(Default::MaxConnectionsPerHost) , maxConnectionsPerHost_(Default::MaxConnectionsPerHost)
, keepAlive_(Default::KeepAlive) , keepAlive_(Default::KeepAlive)
{ } { }
Options& threads(int val); Options& threads(int val);
...@@ -323,7 +322,7 @@ public: ...@@ -323,7 +322,7 @@ public:
~Client(); ~Client();
static Options options(); static Options options();
void init(const Options& options); void init(const Options& options = Options());
RequestBuilder get(const std::string& resource); RequestBuilder get(const std::string& resource);
RequestBuilder post(const std::string& resource); RequestBuilder post(const std::string& resource);
......
...@@ -38,7 +38,7 @@ public: ...@@ -38,7 +38,7 @@ public:
listener.init(std::forward<Args>(args)...); 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 setHandler(const std::shared_ptr<Handler>& handler);
void bind(); void bind();
......
...@@ -14,7 +14,7 @@ namespace Http { ...@@ -14,7 +14,7 @@ namespace Http {
Endpoint::Options::Options() Endpoint::Options::Options()
: threads_(1) : threads_(1)
, flags_() , flags_(Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr)
, backlog_(Const::MaxBacklog) , backlog_(Const::MaxBacklog)
, maxPayload_(Const::DefaultMaxPayload) , maxPayload_(Const::DefaultMaxPayload)
{ } { }
......
...@@ -21,15 +21,12 @@ TEST(http_client_test, one_client_with_one_request) { ...@@ -21,15 +21,12 @@ TEST(http_client_test, one_client_with_one_request) {
const std::string address = "localhost:9079"; const std::string address = "localhost:9079";
Http::Endpoint server(address); Http::Endpoint server(address);
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr; server.init();
auto server_opts = Http::Endpoint::options().flags(flags).threads(1);
server.init(server_opts);
server.setHandler(Http::make_handler<HelloHandler>()); server.setHandler(Http::make_handler<HelloHandler>());
server.serveThreaded(); server.serveThreaded();
Http::Client client; Http::Client client;
auto client_opts = Http::Client::options(); client.init();
client.init(client_opts);
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
auto rb = client.get(address); auto rb = client.get(address);
...@@ -55,15 +52,12 @@ TEST(http_client_test, one_client_with_multiple_requests) { ...@@ -55,15 +52,12 @@ TEST(http_client_test, one_client_with_multiple_requests) {
const std::string address = "localhost:9080"; const std::string address = "localhost:9080";
Http::Endpoint server(address); Http::Endpoint server(address);
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr; server.init();
auto server_opts = Http::Endpoint::options().flags(flags).threads(1);
server.init(server_opts);
server.setHandler(Http::make_handler<HelloHandler>()); server.setHandler(Http::make_handler<HelloHandler>());
server.serveThreaded(); server.serveThreaded();
Http::Client client; Http::Client client;
auto client_opts = Http::Client::options().threads(1).maxConnectionsPerHost(1); client.init();
client.init(client_opts);
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
const int RESPONSE_SIZE = 3; const int RESPONSE_SIZE = 3;
...@@ -94,20 +88,17 @@ TEST(http_client_test, multiple_clients_with_one_request) { ...@@ -94,20 +88,17 @@ TEST(http_client_test, multiple_clients_with_one_request) {
const std::string address = "localhost:9081"; const std::string address = "localhost:9081";
Http::Endpoint server(address); Http::Endpoint server(address);
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr; server.init();
auto server_opts = Http::Endpoint::options().flags(flags).threads(1);
server.init(server_opts);
server.setHandler(Http::make_handler<HelloHandler>()); server.setHandler(Http::make_handler<HelloHandler>());
server.serveThreaded(); server.serveThreaded();
auto client_opts = Http::Client::options();
const int CLIENT_SIZE = 3; const int CLIENT_SIZE = 3;
Http::Client client1; Http::Client client1;
client1.init(client_opts); client1.init();
Http::Client client2; Http::Client client2;
client2.init(client_opts); client2.init();
Http::Client client3; Http::Client client3;
client3.init(client_opts); client3.init();
std::vector<Async::Promise<Http::Response>> responses; std::vector<Async::Promise<Http::Response>> responses;
int response_counter = 0; int response_counter = 0;
......
...@@ -88,11 +88,8 @@ TEST(payload, from_description) ...@@ -88,11 +88,8 @@ TEST(payload, from_description)
router.initFromDescription(desc); router.initFromDescription(desc);
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr;
auto opts = Http::Endpoint::options() auto opts = Http::Endpoint::options()
.threads(threads) .threads(threads)
.flags(flags)
.maxPayload(maxPayload); .maxPayload(maxPayload);
; ;
...@@ -142,7 +139,6 @@ TEST(payload, manual_construction) { ...@@ -142,7 +139,6 @@ TEST(payload, manual_construction) {
Port port(PORT); Port port(PORT);
Address addr(Ipv4::any(), port); Address addr(Ipv4::any(), port);
int threads = 20; int threads = 20;
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr;
size_t maxPayload = 2048; size_t maxPayload = 2048;
auto pid = fork(); auto pid = fork();
...@@ -150,7 +146,6 @@ TEST(payload, manual_construction) { ...@@ -150,7 +146,6 @@ TEST(payload, manual_construction) {
auto endpoint = std::make_shared<Http::Endpoint>(addr); auto endpoint = std::make_shared<Http::Endpoint>(addr);
auto opts = Http::Endpoint::options() auto opts = Http::Endpoint::options()
.threads(threads) .threads(threads)
.flags(flags)
.maxPayload(maxPayload); .maxPayload(maxPayload);
; ;
......
...@@ -63,11 +63,8 @@ TEST(stream, from_description) ...@@ -63,11 +63,8 @@ TEST(stream, from_description)
router.initFromDescription(desc); router.initFromDescription(desc);
auto flags = Tcp::Options::InstallSignalHandler | Tcp::Options::ReuseAddr;
auto opts = Http::Endpoint::options() auto opts = Http::Endpoint::options()
.threads(threads) .threads(threads)
.flags(flags)
.maxPayload(1024*1024) .maxPayload(1024*1024)
; ;
......
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