memgraph/tests/manual/bolt_client.cpp
Teon Banek ce29517998 Extract utils into mg-utils static library and explicitly list tests
Summary:
Utils source files are now moved to a standalone mg-utils library.

Unit and manual tests are no longer collected using glob recursion in
cmake, but are explicitly listed. This allows us to set only required
dependencies of those tests.

Both of these changes should improve compilation and link times, as well
as lower the disk usage.

Additional improvement would be to cleanup utils header files to be
split in .hpp and .cpp as well as merging threading into utils. Other
potential library extractions that shouldn't be difficult are:

  * data_structures
  * io/network
  * communication

Reviewers: buda, mferencevic, dgleich, ipaljak, mculinovic, mtomic, msantl

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1408
2018-05-30 09:41:56 +02:00

63 lines
1.9 KiB
C++

#include <gflags/gflags.h>
#include <glog/logging.h>
#include "communication/bolt/client.hpp"
#include "io/network/endpoint.hpp"
#include "io/network/utils.hpp"
#include "utils/timer.hpp"
DEFINE_string(address, "127.0.0.1", "Server address");
DEFINE_int32(port, 7687, "Server port");
DEFINE_string(username, "", "Username for the database");
DEFINE_string(password, "", "Password for the database");
int main(int argc, char **argv) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
// TODO: handle endpoint exception
io::network::Endpoint endpoint(io::network::ResolveHostname(FLAGS_address),
FLAGS_port);
communication::bolt::Client client;
if (!client.Connect(endpoint, FLAGS_username, FLAGS_password)) return 1;
std::cout << "Memgraph bolt client is connected and running." << std::endl;
while (true) {
std::string s;
std::getline(std::cin, s);
if (s == "") {
break;
}
try {
utils::Timer t;
auto ret = client.Execute(s, {});
auto elapsed = t.Elapsed().count();
std::cout << "Wall time:\n " << elapsed << std::endl;
std::cout << "Fields:" << std::endl;
for (auto &field : ret.fields) {
std::cout << " " << field << std::endl;
}
std::cout << "Records:" << std::endl;
for (int i = 0; i < static_cast<int>(ret.records.size()); ++i) {
std::cout << " " << i << std::endl;
for (auto &value : ret.records[i]) {
std::cout << " " << value << std::endl;
}
}
std::cout << "Metadata:" << std::endl;
for (auto &data : ret.metadata) {
std::cout << " " << data.first << " : " << data.second << std::endl;
}
} catch (const communication::bolt::ClientQueryException &e) {
std::cout << "Client received exception: " << e.what() << std::endl;
}
}
return 0;
}