From 8015f0d53da53876b65fdcdc712f1dc92835a9b1 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 11 Jan 2010 08:29:17 +0000 Subject: Minor fixes to server and python evaluator to get python store working. Some changes to python and scheme store test cases to simplify them a bit and make them consistent. Enabled a few more server test combinations. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@897785 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/json/json.hpp | 12 +++++++++++ sca-cpp/trunk/modules/python/eval.hpp | 2 +- sca-cpp/trunk/modules/server/client-test.cpp | 30 ++++++++++++++-------------- sca-cpp/trunk/modules/server/mod-eval.cpp | 4 ++-- sca-cpp/trunk/modules/server/server-test.py | 10 ++++++++++ 5 files changed, 40 insertions(+), 18 deletions(-) (limited to 'sca-cpp/trunk/modules') diff --git a/sca-cpp/trunk/modules/json/json.hpp b/sca-cpp/trunk/modules/json/json.hpp index e2f036541a..fc5e512d5e 100644 --- a/sca-cpp/trunk/modules/json/json.hpp +++ b/sca-cpp/trunk/modules/json/json.hpp @@ -381,6 +381,18 @@ const failable > jsonResult(const value& id, const value& val, JSON return writeJSON(valuesToElements(mklist(mklist("id", id), mklist("result", val))), cx); } +/** + * Return a portable function name from a JSON-RPC function name. + * Strip the "system." and "Service." prefixes added by some JSON-RPC clients. + */ +const string funcName(const string& f) { + if (length(f) > 7 && find(f, "system.", 0) == 0) + return c_str(f) + 7; + if (length(f) > 8 && find(f, "Service.", 0) == 0) + return c_str(f) + 8; + return f; +} + } } diff --git a/sca-cpp/trunk/modules/python/eval.hpp b/sca-cpp/trunk/modules/python/eval.hpp index b0d793418a..cb6cdea3e2 100644 --- a/sca-cpp/trunk/modules/python/eval.hpp +++ b/sca-cpp/trunk/modules/python/eval.hpp @@ -152,7 +152,7 @@ PyObject* valueToPyObject(const value& v) { case value::Bool: return (bool)v? Py_True : Py_False; default: - return NULL; + return Py_None; } } diff --git a/sca-cpp/trunk/modules/server/client-test.cpp b/sca-cpp/trunk/modules/server/client-test.cpp index d037aabbf9..f46cba5068 100644 --- a/sca-cpp/trunk/modules/server/client-test.cpp +++ b/sca-cpp/trunk/modules/server/client-test.cpp @@ -86,7 +86,7 @@ const bool testEval(const string& uri) { const bool testEval() { testEval("http://localhost:8090/test"); - //testEval("http://localhost:8090/cpp"); + testEval("http://localhost:8090/cpp"); testEval("http://localhost:8090/python"); return true; } @@ -129,7 +129,7 @@ const bool testEvalPerf(const string& type, const string& uri) { const bool testEvalPerf() { testEvalPerf("Scheme", "http://localhost:8090/test"); - //testEvalPerf("C++", "http://localhost:8090/cpp"); + testEvalPerf("C++", "http://localhost:8090/cpp"); testEvalPerf("Python", "http://localhost:8090/python"); return true; } @@ -147,7 +147,7 @@ bool testPost(const string& uri) { const bool testPost() { testPost("http://localhost:8090/test"); - //testPost("http://localhost:8090/cpp"); + testPost("http://localhost:8090/cpp"); testPost("http://localhost:8090/python"); return true; } @@ -193,7 +193,7 @@ const bool testPostPerf(const string& type, const string& uri) { const bool testPostPerf() { testPostPerf("Scheme", "http://localhost:8090/test"); - //testPostPerf("C++", "http://localhost:8090/cpp"); + testPostPerf("C++", "http://localhost:8090/cpp"); testPostPerf("Python", "http://localhost:8090/python"); return true; } @@ -252,16 +252,16 @@ const bool testPostThreadPerf(const string& type, const string& uri) { const bool testPostThreadPerf() { testPostThreadPerf("Scheme", "http://localhost:8090/test"); - //testPostThreadPerf("C++", "http://localhost:8090/cpp"); - //testPostThreadPerf("Python", "http://localhost:8090/python"); + testPostThreadPerf("C++", "http://localhost:8090/cpp"); + testPostThreadPerf("Python", "http://localhost:8090/python"); return true; } #else -const bool postProc(const int count, const value& val) { +const bool postProc(const string& uri, const int count, const value& val) { http::CURLSession ch; - const lambda pl = postLoop(val, ch); + const lambda pl = postLoop(uri, val, ch); time(pl, 0, count); return true; } @@ -316,9 +316,9 @@ const bool testPostForkPerf(const string& type, const string& uri) { } const bool testPostForkPerf() { - testPostThreadPerf("Scheme", "http://localhost:8090/test"); - //testPostThreadPerf("C++", "http://localhost:8090/cpp"); - testPostThreadPerf("Python", "http://localhost:8090/python"); + testPostForkPerf("Scheme", "http://localhost:8090/test"); + //testPostForkPerf("C++", "http://localhost:8090/cpp"); + testPostForkPerf("Python", "http://localhost:8090/python"); return true; } @@ -363,18 +363,18 @@ int main() { tuscany::cout << "Testing..." << tuscany::endl; tuscany::server::testGet(); - tuscany::server::testGetPerf(); tuscany::server::testPost(); + tuscany::server::testPut(); + tuscany::server::testDel(); + tuscany::server::testEval(); + tuscany::server::testGetPerf(); tuscany::server::testPostPerf(); #ifdef _REENTRANT tuscany::server::testPostThreadPerf(); #else tuscany::server::testPostForkPerf(); #endif - tuscany::server::testEval(); tuscany::server::testEvalPerf(); - tuscany::server::testPut(); - tuscany::server::testDel(); tuscany::cout << "OK" << tuscany::endl; diff --git a/sca-cpp/trunk/modules/server/mod-eval.cpp b/sca-cpp/trunk/modules/server/mod-eval.cpp index 34c1f00cba..23454e3ceb 100644 --- a/sca-cpp/trunk/modules/server/mod-eval.cpp +++ b/sca-cpp/trunk/modules/server/mod-eval.cpp @@ -100,7 +100,7 @@ const failable get(request_rec* r, const lambda&)>& // Extract the request id, method and params const value id = cadr(ia); - const value func = c_str(string(cadr(ma))); + const value func = c_str(json::funcName(string(cadr(ma)))); // Apply the requested function const failable val = failableResult(impl(cons(func, httpd::queryParams(args)))); @@ -145,7 +145,7 @@ const failable post(request_rec* r, const lambda&)> // Extract the request id, method and params const value id = cadr(assoc(value("id"), args)); - const value func = c_str(cadr(assoc(value("method"), args))); + const value func = c_str(json::funcName(cadr(assoc(value("method"), args)))); const list params = (list)cadr(assoc(value("params"), args)); // Evaluate the request expression diff --git a/sca-cpp/trunk/modules/server/server-test.py b/sca-cpp/trunk/modules/server/server-test.py index c80d800eff..cdef94e116 100644 --- a/sca-cpp/trunk/modules/server/server-test.py +++ b/sca-cpp/trunk/modules/server/server-test.py @@ -5,6 +5,16 @@ def echo(x): # ATOMPub test case +def getall(): + return ("Sample Feed", "123456789", + ("Item", "111", (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99))), + ("Item", "222", (("'javaClass", "services.Item"), ("'name", "Orange"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 3.55))), + ("Item", "333", (("'javaClass", "services.Item"), ("name", "Pear"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 1.55)))) + +def get(id): + entry = (("'javaClass", "services.Item"), ("'name", "Apple"), ("'currencyCode", "USD"), ("'currencySymbol", "$"), ("'price", 2.99)) + return ("Item", id, entry) + def post(entry): return "123456789" -- cgit v1.2.3