From 0ffea496ac021df01723fcde7d9c615af89254c7 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Mon, 11 May 2015 15:06:06 +0300 Subject: [PATCH] Adding the http server to the messaging_service test To test the messaging service API it needs to be included in the messaging service test. To test it, start the server with --stay-alive true then you can use the API to get the messges information: http://localhost:10001/messaging_service/messages/exception will return the number of exception per connection http://localhost:10001/messaging_service/command/completed will return the number of completed command per connection. Note that because the two servers are running on the same machine, to prevent port conflict, the server port will be increment by one (i.e 10001) Signed-off-by: Amnon Heiman --- configure.py | 2 +- tests/urchin/message.cc | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/configure.py b/configure.py index 3d0ca41e28..52d92e5b3a 100755 --- a/configure.py +++ b/configure.py @@ -467,7 +467,7 @@ urchin_core = (['database.cc', + [Thrift('interface/cassandra.thrift', 'Cassandra')] + core + libnet) -urchin_tests_dependencies = urchin_core + [ +urchin_tests_dependencies = urchin_core + http + api + [ 'tests/urchin/cql_test_env.cc', 'tests/urchin/cql_assertions.cc', ] diff --git a/tests/urchin/message.cc b/tests/urchin/message.cc index 315d869d4a..210108c3e6 100644 --- a/tests/urchin/message.cc +++ b/tests/urchin/message.cc @@ -7,6 +7,8 @@ #include "gms/gossip_digest_ack2.hh" #include "gms/gossip_digest.hh" #include "core/sleep.hh" +#include "http/httpd.hh" +#include "api/api.hh" using namespace std::chrono_literals; using namespace net; @@ -169,18 +171,37 @@ int main(int ac, char ** av) { app.add_options() ("server", bpo::value(), "Server ip") ("listen-address", bpo::value()->default_value("0.0.0.0"), "IP address to listen") + ("api-port", bpo::value()->default_value(10000), "Http Rest API port") + ("stay-alive", bpo::value()->default_value(false), "Do not kill the test server after the test") ("cpuid", bpo::value()->default_value(0), "Server cpuid"); - return app.run(ac, av, [&app] { + + distributed db; + api::http_context ctx(db); + + return app.run(ac, av, [&app, &ctx] { auto config = app.configuration(); + uint16_t api_port = config["api-port"].as(); + bool stay_alive = config["stay-alive"].as(); + if (config.count("server")) { + api_port++; + } const gms::inet_address listen = gms::inet_address(config["listen-address"].as()); - net::get_messaging_service().start(listen).then([config] () { + net::get_messaging_service().start(listen).then([config, api_port, &ctx, stay_alive] () { auto testers = new distributed; testers->start().then([testers]{ auto& server = net::get_local_messaging_service(); auto port = server.port(); std::cout << "Messaging server listening on port " << port << " ...\n"; return testers->invoke_on_all(&tester::init_handler); - }).then([testers, config] { + }).then([api_port, &ctx] { + return ctx.http_server.start(); + }).then([api_port, &ctx] { + return set_server(ctx); + }).then([&ctx, api_port] { + return ctx.http_server.listen(api_port); + }).then([api_port] { + std::cout << "Seastar HTTP server listening on port " << api_port << " ...\n"; + }).then([testers, config, stay_alive] { auto t = &testers->local(); if (!config.count("server")) { return; @@ -197,7 +218,10 @@ int main(int ac, char ** av) { return t->test_echo(); }).then([testers, t] { return t->test_exception(); - }).then([testers, t] { + }).then([testers, t, stay_alive] { + if (stay_alive) { + return; + } print("=============TEST DONE===========\n"); testers->stop().then([testers] { delete testers;