| 68 | } |
| 69 | |
| 70 | int main(int argc, char ** argv) |
| 71 | { |
| 72 | gflags::ParseCommandLineFlags(&argc, &argv, true); |
| 73 | |
| 74 | if (FLAGS_h) |
| 75 | { |
| 76 | log_message("Main options:\n" |
| 77 | << std::setiosflags(std::ios::left) |
| 78 | << std::setw(ALIGN_WIDTH) << " --h" << "produce help message\n" |
| 79 | << std::setw(ALIGN_WIDTH) << " --host arg (=127.0.0.1:8080)" << "tso server host address\n" |
| 80 | << std::setw(ALIGN_WIDTH) << " --client arg (=10)" << "number of clients\n" |
| 81 | << std::setw(ALIGN_WIDTH) << " --task arg (=10)" << "number of tasks for each client\n" |
| 82 | << std::setw(ALIGN_WIDTH) << " --interval arg (=10)" << "interval of each task (milliseconds)\n") |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | std::string server_addr = FLAGS_host; |
| 87 | log_message("Connect to server : " << server_addr) |
| 88 | |
| 89 | /// single test |
| 90 | log_message(std::endl << "TSO service Single Test:") |
| 91 | |
| 92 | DB::TSO::TSOClient client(server_addr); |
| 93 | |
| 94 | DB::UInt64 first_timestamp = client.getTimestamp().timestamp(); |
| 95 | log_message("Next TSO value: 0x" << std::setiosflags(std::ios::uppercase) << std::hex << first_timestamp) |
| 96 | log_message("Physical time: " << getPhysicalTime(first_timestamp)) |
| 97 | log_message("Logical time: " << getLogicalTime(first_timestamp)) |
| 98 | |
| 99 | /// concurrency test |
| 100 | log_message(std::endl << "TSO service Concurrency Test:") |
| 101 | |
| 102 | size_t num_clients = FLAGS_client; |
| 103 | size_t num_tasks = FLAGS_task; |
| 104 | size_t interval = FLAGS_interval; |
| 105 | log_message("Number of TSO clients: " << num_clients) |
| 106 | log_message("Number of tasks for each client: " << num_tasks) |
| 107 | log_message("Interval of each task: " << interval << " ms") |
| 108 | |
| 109 | std::vector<DB::TSO::TSOClientPtr> client_pool; |
| 110 | for (size_t i = 0; i < num_clients; i++) |
| 111 | { |
| 112 | client_pool.push_back(std::make_shared<DB::TSO::TSOClient>(server_addr)); |
| 113 | } |
| 114 | |
| 115 | ThreadPool thread_pool(num_clients); |
| 116 | |
| 117 | for (size_t i = 0; i < num_clients; i++) |
| 118 | { |
| 119 | auto task = [&, i] |
| 120 | { |
| 121 | for (size_t j = 0; j < num_tasks; j++) |
| 122 | { |
| 123 | DB::UInt64 timestamp = client_pool[i]->getTimestamp().timestamp(); |
| 124 | log_message("Client[" << i << "] Task[" << j << "] get physical time: " << getPhysicalTime(timestamp) |
| 125 | << ", logical time: " << getLogicalTime(timestamp)) |
| 126 | std::this_thread::sleep_for(std::chrono::milliseconds(interval)); |
| 127 | } |
nothing calls this directly
no test coverage detected