diff options
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/server/client-test.cpp | 79 |
1 files changed, 48 insertions, 31 deletions
diff --git a/sca-cpp/trunk/modules/server/client-test.cpp b/sca-cpp/trunk/modules/server/client-test.cpp index b43cb92c52..5888c481e3 100644 --- a/sca-cpp/trunk/modules/server/client-test.cpp +++ b/sca-cpp/trunk/modules/server/client-test.cpp @@ -50,7 +50,7 @@ std::ostringstream* curlWriter(const std::string& s, std::ostringstream* os) { } const bool testGet() { - http::CURLHandle ch; + http::CURLSession ch; { std::ostringstream os; const failable<list<std::ostringstream*>, std::string> r = http::get<std::ostringstream*>(curlWriter, &os, "http://localhost:8090", ch); @@ -66,7 +66,7 @@ const bool testGet() { return true; } -const bool testGetLoop(const int count, http::CURLHandle& ch) { +const bool testGetLoop(const int count, http::CURLSession& ch) { if (count == 0) return true; const failable<value, std::string> r = get("http://localhost:8090", ch); @@ -77,16 +77,13 @@ const bool testGetLoop(const int count, http::CURLHandle& ch) { const bool testGetPerf() { const int count = 50; - http::CURLHandle ch; + http::CURLSession ch; struct timeval start; struct timeval end; { testGetLoop(5, ch); - gettimeofday(&start, NULL); - testGetLoop(count, ch); - gettimeofday(&end, NULL); std::cout << "Static GET test " << duration(start, end, count) << " ms" << std::endl; } @@ -94,13 +91,13 @@ const bool testGetPerf() { } const bool testEval() { - http::CURLHandle ch; + http::CURLSession ch; const value val = content(http::evalExpr(mklist<value>(std::string("echo"), std::string("Hello")), "http://localhost:8090/test", ch)); assert(val == std::string("Hello")); return true; } -const bool testEvalLoop(const int count, http::CURLHandle& ch) { +const bool testEvalLoop(const int count, http::CURLSession& ch) { if (count == 0) return true; const value val = content(http::evalExpr(mklist<value>(std::string("echo"), std::string("Hello")), "http://localhost:8090/test", ch)); @@ -111,7 +108,7 @@ const bool testEvalLoop(const int count, http::CURLHandle& ch) { const value blob(std::string(3000, 'A')); const list<value> blobs = mklist(blob, blob, blob, blob, blob); -const bool testBlobEvalLoop(const int count, http::CURLHandle& ch) { +const bool testBlobEvalLoop(const int count, http::CURLSession& ch) { if (count == 0) return true; const value val = content(http::evalExpr(mklist<value>(std::string("echo"), blobs), "http://localhost:8090/test", ch)); @@ -121,26 +118,20 @@ const bool testBlobEvalLoop(const int count, http::CURLHandle& ch) { const bool testEvalPerf() { const int count = 50; - http::CURLHandle ch; + http::CURLSession ch; struct timeval start; struct timeval end; { testEvalLoop(5, ch); - gettimeofday(&start, NULL); - testEvalLoop(count, ch); - gettimeofday(&end, NULL); std::cout << "JSON-RPC eval echo test " << duration(start, end, count) << " ms" << std::endl; } { testBlobEvalLoop(5, ch); - gettimeofday(&start, NULL); - testBlobEvalLoop(count, ch); - gettimeofday(&end, NULL); std::cout << "JSON-RPC eval blob test " << duration(start, end, count) << " ms" << std::endl; } @@ -156,23 +147,23 @@ bool testPost() { << (list<value>() << "name" << std::string("Apple")) << (list<value>() << "price" << std::string("$2.99")); const list<value> a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); - http::CURLHandle ch; - value rc = content(http::post(a, "http://localhost:8090/test", ch)); - assert(rc == value(true)); + http::CURLSession ch; + const failable<value, std::string> id = http::post(a, "http://localhost:8090/test", ch); + assert(hasContent(id)); return true; } -const bool testPostLoop(const int count, const value& val, http::CURLHandle& ch) { +const bool testPostLoop(const int count, const value& val, http::CURLSession& ch) { if (count == 0) return true; - const value rc = content(http::post(val, "http://localhost:8090/test", ch)); - assert(rc == value(true)); + const failable<value, std::string> id = http::post(val, "http://localhost:8090/test", ch); + assert(hasContent(id)); return testPostLoop(count - 1, val, ch); } const bool testPostPerf() { const int count = 50; - http::CURLHandle ch; + http::CURLSession ch; struct timeval start; struct timeval end; { @@ -181,11 +172,8 @@ const bool testPostPerf() { << (list<value>() << "price" << std::string("$2.99")); const list<value> val = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); testPostLoop(5, val, ch); - gettimeofday(&start, NULL); - testPostLoop(count, val, ch); - gettimeofday(&end, NULL); std::cout << "ATOMPub POST small test " << duration(start, end, count) << " ms" << std::endl; } @@ -200,11 +188,8 @@ const bool testPostPerf() { << (list<value>() << "price" << std::string("$2.99")); const list<value> val = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); testPostLoop(5, val, ch); - gettimeofday(&start, NULL); - testPostLoop(count, val, ch); - gettimeofday(&end, NULL); std::cout << "ATOMPub POST blob test " << duration(start, end, count) << " ms" << std::endl; } @@ -216,19 +201,49 @@ const bool testPut() { << (list<value>() << "name" << std::string("Apple")) << (list<value>() << "price" << std::string("$2.99")); const list<value> a = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); - http::CURLHandle ch; + http::CURLSession ch; value rc = content(http::put(a, "http://localhost:8090/test/111", ch)); assert(rc == value(true)); return true; } const bool testDel() { - http::CURLHandle ch; + http::CURLSession ch; value rc = content(http::del("http://localhost:8090/test/123456789", ch)); assert(rc == value(true)); return true; } +const bool testEvalCpp() { + http::CURLSession ch; + const value val = content(http::evalExpr(mklist<value>(std::string("hello"), std::string("world")), "http://localhost:8090/cpp", ch)); + assert(val == std::string("hello world")); + return true; +} + +const bool testEvalCppLoop(const int count, http::CURLSession& ch) { + if (count == 0) + return true; + const value val = content(http::evalExpr(mklist<value>(std::string("hello"), std::string("world")), "http://localhost:8090/cpp", ch)); + assert(val == std::string("hello world")); + return testEvalCppLoop(count - 1, ch); +} + +const bool testEvalCppPerf() { + const int count = 50; + http::CURLSession ch; + struct timeval start; + struct timeval end; + { + testEvalCppLoop(5, ch); + gettimeofday(&start, NULL); + testEvalCppLoop(count, ch); + gettimeofday(&end, NULL); + std::cout << "JSON-RPC C++ eval test " << duration(start, end, count) << " ms" << std::endl; + } + return true; +} + } } @@ -244,6 +259,8 @@ int main() { tuscany::server::testFeed(); tuscany::server::testPut(); tuscany::server::testDel(); + tuscany::server::testEvalCpp(); + tuscany::server::testEvalCppPerf(); std::cout << "OK" << std::endl; |