diff options
Diffstat (limited to 'fbench/src/test/httpclient.cpp')
-rw-r--r-- | fbench/src/test/httpclient.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/fbench/src/test/httpclient.cpp b/fbench/src/test/httpclient.cpp new file mode 100644 index 00000000000..9c1800d0003 --- /dev/null +++ b/fbench/src/test/httpclient.cpp @@ -0,0 +1,54 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include <util/httpclient.h> +#include <iostream> +#include <thread> + +int +main(int argc, char **argv) +{ + if (argc < 4) { + printf("usage: httpclient <host> <port> <url> [keep-alive]\n"); + return 1; + } + + HTTPClient *client; + ssize_t len; + + if(argc == 4) { + client = new HTTPClient(argv[1], atoi(argv[2]), false, true); + } else { + client = new HTTPClient(argv[1], atoi(argv[2]), true, true); + } + + std::ostream * output = & std::cout; + + if ((len = client->Fetch(argv[3], output).ResultSize()) >= 0) { + printf("SUCCESS!\n"); + printf("LENGTH: %ld\n", len); + } else { + printf("ERROR: could not fetch URL content.\n"); + } + if ((len = client->Fetch(argv[3], output).ResultSize()) >= 0) { + printf("SUCCESS!\n"); + printf("LENGTH: %ld\n", len); + } else { + printf("ERROR: could not fetch URL content.\n"); + } + + std::this_thread::sleep_for(std::chrono::seconds(20)); + + if ((len = client->Fetch(argv[3], output).ResultSize()) >= 0) { + printf("SUCCESS!\n"); + printf("LENGTH: %ld\n", len); + } else { + printf("ERROR: could not fetch URL content.\n"); + } + if ((len = client->Fetch(argv[3], output).ResultSize()) >= 0) { + printf("SUCCESS!\n"); + printf("LENGTH: %ld\n", len); + } else { + printf("ERROR: could not fetch URL content.\n"); + } + printf("REUSE COUNT: %" PRIu64 "\n", client->GetReuseCount()); + return 0; +} |