MCPcopy Create free account
hub / github.com/DeNA/HandlerSocket-Plugin-for-MySQL / test_1

Method test_1

client/hstest.cpp:193–257  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

191};
192
193void
194hstest_thread::test_1()
195{
196 char buf[1024];
197 unsigned int seed = arg.id;
198 seed ^= arg.sh.conf.get_int("seed_xor", 0);
199 std::string err;
200 if (socket_connect(fd, arg.sh.arg, err) != 0) {
201 fprintf(stderr, "connect: %d %s\n", errno, strerror(errno));
202 return;
203 }
204 const char op = arg.sh.op;
205 const int tablesize = arg.sh.conf.get_int("tablesize", 0);
206 for (size_t i = 0; i < arg.sh.loop; ++i) {
207 for (size_t j = 0; j < arg.sh.pipe; ++j) {
208 int k = 0, v = 0, len = 0;
209 if (op == 'G') {
210 k = rand_r(&seed);
211 v = rand_r(&seed); /* unused */
212 if (tablesize != 0) {
213 k &= tablesize;
214 }
215 len = snprintf(buf, sizeof(buf), "%c\tk%d\n", op, k);
216 } else {
217 k = rand_r(&seed);
218 v = rand_r(&seed);
219 if (tablesize != 0) {
220 k &= tablesize;
221 }
222 len = snprintf(buf, sizeof(buf), "%c\tk%d\tv%d\n", op, k, v);
223 }
224 const int wlen = write(fd.get(), buf, len);
225 if (wlen != len) {
226 return;
227 }
228 }
229 size_t read_cnt = 0;
230 size_t read_pos = 0;
231 while (read_cnt < arg.sh.pipe) {
232 const int rlen = read(fd.get(), buf + read_pos, sizeof(buf) - read_pos);
233 if (rlen <= 0) {
234 return;
235 }
236 read_pos += rlen;
237 while (true) {
238 const char *const p = static_cast<const char *>(memchr(buf, '\n',
239 read_pos));
240 if (p == 0) {
241 break;
242 }
243 ++read_cnt;
244 ++io_success_count;
245 arg.sh.increment_count();
246 if (p != buf && buf[0] == '=') {
247 ++op_success_count;
248 }
249 const size_t rest_size = buf + read_pos - (p + 1);
250 if (rest_size != 0) {

Callers

nothing calls this directly

Calls 4

socket_connectFunction · 0.85
get_intMethod · 0.80
increment_countMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected