memgraph/tests/distributed/raft/example_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

49 lines
1.3 KiB
C++

#include <ctime>
#include <random>
#include <thread>
#include <fmt/format.h>
#include <gflags/gflags.h>
#include <glog/logging.h>
#include "communication/rpc/client.hpp"
#include "io/network/endpoint.hpp"
#include "io/network/utils.hpp"
#include "messages.hpp"
using namespace communication::rpc;
using namespace std::literals::chrono_literals;
DEFINE_string(server_interface, "127.0.0.1",
"Server interface on which to communicate.");
DEFINE_int32(server_port, 8010, "Server port on which to communicate.");
int main(int argc, char **argv) {
google::SetUsageMessage("Raft RPC Client");
gflags::ParseCommandLineFlags(&argc, &argv, true);
google::InitGoogleLogging(argv[0]);
// Initialize client.
Client client(io::network::Endpoint(
io::network::ResolveHostname(FLAGS_server_interface), FLAGS_server_port));
// Try to send 100 values to server.
// If requests timeout, try to resend it.
// Log output on server should contain all values once
// in correct order.
for (int i = 1; i <= 100; ++i) {
LOG(INFO) << fmt::format("Apennding value: {}", i);
auto result_tuple = client.Call<AppendEntry>(i);
if (!result_tuple) {
LOG(INFO) << "Request unsuccessful";
// Try to resend value
--i;
} else {
LOG(INFO) << fmt::format("Appended value: {}", i);
}
}
return 0;
}