You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2010/05/23 20:52:43 UTC

svn commit: r947467 - in /tuscany/sca-cpp/trunk/components/log: Makefile.am adder-test.scm client-test.cpp client-test.scm log.composite logger.cpp scribe-test server-test

Author: jsdelfino
Date: Sun May 23 18:52:42 2010
New Revision: 947467

URL: http://svn.apache.org/viewvc?rev=947467&view=rev
Log:
Add a logger component that logs and relays all invocations through a reference.

Added:
    tuscany/sca-cpp/trunk/components/log/adder-test.scm
    tuscany/sca-cpp/trunk/components/log/client-test.scm
    tuscany/sca-cpp/trunk/components/log/logger.cpp
Modified:
    tuscany/sca-cpp/trunk/components/log/Makefile.am
    tuscany/sca-cpp/trunk/components/log/client-test.cpp
    tuscany/sca-cpp/trunk/components/log/log.composite
    tuscany/sca-cpp/trunk/components/log/scribe-test
    tuscany/sca-cpp/trunk/components/log/server-test

Modified: tuscany/sca-cpp/trunk/components/log/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/Makefile.am?rev=947467&r1=947466&r2=947467&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/components/log/Makefile.am Sun May 23 18:52:42 2010
@@ -35,12 +35,18 @@ gen-cpp/fb303_constants.cpp gen-cpp/fb30
 
 CLEANFILES = gen-cpp/*
 
-comp_LTLIBRARIES = liblog.la
+comp_LTLIBRARIES = liblog.la liblogger.la
+
 nodist_liblog_la_SOURCES = gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp gen-cpp/scribe_constants.cpp gen-cpp/scribe.cpp gen-cpp/scribe_types.cpp gen-cpp/FacebookService.cpp gen-cpp/scribe.h
 liblog_la_CXXFLAGS = -Wno-unused-parameter
 liblog_la_SOURCES = log.cpp
 liblog_la_LDFLAGS = -L${THRIFT_LIB} -R${THRIFT_LIB} -lthrift -L${FB303_LIB} -R${FB303_LIB} -lfb303 -L${SCRIBE_LIB} -R${SCRIBE_LIB} -lscribe
 
+nodist_liblogger_la_SOURCES = gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp gen-cpp/scribe_constants.cpp gen-cpp/scribe.cpp gen-cpp/scribe_types.cpp gen-cpp/FacebookService.cpp gen-cpp/scribe.h
+liblogger_la_CXXFLAGS = -Wno-unused-parameter
+liblogger_la_SOURCES = logger.cpp
+liblogger_la_LDFLAGS = -L${THRIFT_LIB} -R${THRIFT_LIB} -lthrift -L${FB303_LIB} -R${FB303_LIB} -lfb303 -L${SCRIBE_LIB} -R${SCRIBE_LIB} -lscribe
+
 client_test_SOURCES = client-test.cpp
 client_test_LDFLAGS = -lxml2 -lcurl -lmozjs
 

Added: tuscany/sca-cpp/trunk/components/log/adder-test.scm
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/adder-test.scm?rev=947467&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/adder-test.scm (added)
+++ tuscany/sca-cpp/trunk/components/log/adder-test.scm Sun May 23 18:52:42 2010
@@ -0,0 +1,20 @@
+;  Licensed to the Apache Software Foundation (ASF) under one
+;  or more contributor license agreements.  See the NOTICE file
+;  distributed with this work for additional information
+;  regarding copyright ownership.  The ASF licenses this file
+;  to you under the Apache License, Version 2.0 (the
+;  "License"); you may not use this file except in compliance
+;  with the License.  You may obtain a copy of the License at
+;  
+;    http://www.apache.org/licenses/LICENSE-2.0
+;    
+;  Unless required by applicable law or agreed to in writing,
+;  software distributed under the License is distributed on an
+;  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+;  KIND, either express or implied.  See the License for the
+;  specific language governing permissions and limitations
+;  under the License.
+
+; Logger test case
+
+(define (add a b) (+ a b))

Modified: tuscany/sca-cpp/trunk/components/log/client-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/client-test.cpp?rev=947467&r1=947466&r2=947467&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/log/client-test.cpp Sun May 23 18:52:42 2010
@@ -68,7 +68,7 @@ struct logLoop {
 bool testLogPerf() {
     const list<value> i = list<value>()
             + (list<value>() + "name" + string("Apple"))
-            + (list<value>() + "price" + string("$4.55"));
+            + (list<value>() + "price" + string("$2.99"));
     const value a = mklist<value>(string("item"), string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i);
 
     http::CURLSession cs;
@@ -81,6 +81,16 @@ bool testLogPerf() {
     return true;
 }
 
+bool testLogger() {
+    http::CURLSession cs;
+
+    const failable<value> res = http::evalExpr(mklist<value>(string("sum"), 33, 22), string("http://localhost:8090/client"), cs);
+    assert(hasContent(res));
+    assert((int)content(res) == 55);
+
+    return true;
+}
+
 }
 }
 
@@ -89,6 +99,7 @@ int main() {
 
     tuscany::log::testLog();
     tuscany::log::testLogPerf();
+    tuscany::log::testLogger();
 
     tuscany::cout << "OK" << tuscany::endl;
 

Added: tuscany/sca-cpp/trunk/components/log/client-test.scm
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/client-test.scm?rev=947467&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/client-test.scm (added)
+++ tuscany/sca-cpp/trunk/components/log/client-test.scm Sun May 23 18:52:42 2010
@@ -0,0 +1,20 @@
+;  Licensed to the Apache Software Foundation (ASF) under one
+;  or more contributor license agreements.  See the NOTICE file
+;  distributed with this work for additional information
+;  regarding copyright ownership.  The ASF licenses this file
+;  to you under the Apache License, Version 2.0 (the
+;  "License"); you may not use this file except in compliance
+;  with the License.  You may obtain a copy of the License at
+;  
+;    http://www.apache.org/licenses/LICENSE-2.0
+;    
+;  Unless required by applicable law or agreed to in writing,
+;  software distributed under the License is distributed on an
+;  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+;  KIND, either express or implied.  See the License for the
+;  specific language governing permissions and limitations
+;  under the License.
+
+; Logger test case
+
+(define (sum a b adder) (adder "add" a b))

Modified: tuscany/sca-cpp/trunk/components/log/log.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/log.composite?rev=947467&r1=947466&r2=947467&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/log.composite (original)
+++ tuscany/sca-cpp/trunk/components/log/log.composite Sun May 23 18:52:42 2010
@@ -30,4 +30,28 @@
         </service>
     </component>     
 
+    <component name="client">
+        <implementation.scheme script="client-test.scm"/>
+        <service name="client">
+            <t:binding.http uri="client"/>
+        </service>
+        <reference name="adder" target="logger"/>
+    </component>     
+
+    <component name="logger">
+        <implementation.cpp path=".libs" library="liblogger"/>
+        <property name="category">default</property>
+        <service name="logger">
+            <t:binding.http uri="logger"/>
+        </service>
+        <reference name="relay" target="adder"/>
+    </component>     
+
+    <component name="adder">
+        <implementation.scheme script="adder-test.scm"/>
+        <service name="adder">
+            <t:binding.http uri="adder"/>
+        </service>
+    </component>     
+
 </composite>

Added: tuscany/sca-cpp/trunk/components/log/logger.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/logger.cpp?rev=947467&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/logger.cpp (added)
+++ tuscany/sca-cpp/trunk/components/log/logger.cpp Sun May 23 18:52:42 2010
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * Scribe-based logger component implementation, used to intercept
+ * and log service invocations.
+ */
+
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+#include "scribe.hpp"
+
+namespace tuscany {
+namespace logger {
+
+/**
+ * Component implementation lambda function.
+ */
+class applyLog {
+public:
+    applyLog(const lambda<value(const list<value>&)>& relay, const value& category, scribe::Scribe& sc) : relay(relay), category(category), sc(sc) {
+    }
+
+    const value operator()(const list<value>& params) const {
+        // Log the function params
+        debug(params, "logger::apply::params");
+        scribe::log(params, category, sc);
+
+        // Relay the function
+        const failable<value> res = relay(params);
+
+        // Log the result
+        scribe::log(res, category, sc);
+        return res;
+    }
+
+private:
+    const lambda<value(const list<value>&)> relay;
+    const value category;
+    scribe::Scribe& sc;
+};
+
+/**
+ * Start the component.
+ */
+const failable<value> start(unused const list<value>& params) {
+    // Connect to Scribe
+    scribe::Scribe& sc = *(new (gc_new<scribe::Scribe>()) scribe::Scribe("localhost", 1464));
+
+    // Extract the configured relay service and category
+    const value rel = car(params);
+    const value category = ((lambda<value(list<value>)>)cadr(params))(list<value>());
+    debug(category, "logger::start::category");
+
+    // Return the component implementation lambda function
+    return value(lambda<value(const list<value>&)>(applyLog(rel, category, sc)));
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+    const tuscany::value func(car(params));
+    if (func == "start")
+        return tuscany::logger::start(cdr(params));
+    return tuscany::mkfailure<tuscany::value>();
+}
+
+}

Modified: tuscany/sca-cpp/trunk/components/log/scribe-test
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/scribe-test?rev=947467&r1=947466&r2=947467&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/scribe-test (original)
+++ tuscany/sca-cpp/trunk/components/log/scribe-test Sun May 23 18:52:42 2010
@@ -30,7 +30,7 @@ sleep 1
 # Test logging a message
 echo test | ./scribe-cat
 sleep 4
-grep test tmp/scribe/logs/central/default/* >/dev/null
+grep test tmp/scribe/logs/central/default/default_current >/dev/null
 rc=$?
 
 # Cleanup

Modified: tuscany/sca-cpp/trunk/components/log/server-test
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/server-test?rev=947467&r1=947466&r2=947467&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/server-test (original)
+++ tuscany/sca-cpp/trunk/components/log/server-test Sun May 23 18:52:42 2010
@@ -39,8 +39,17 @@ sleep 2
 ./client-test 2>/dev/null
 rc=$?
 if [ "$rc" = "0" ]; then
+    echo "Testing..."
     sleep 4
-    grep "Apple" tmp/scribe/logs/central/default/* >/dev/null
+    grep "Apple" tmp/scribe/logs/central/default/default_current >/dev/null
+    rc=$?
+fi
+if [ "$rc" = "0" ]; then
+    grep "(add 33 22)" tmp/scribe/logs/central/default/default_current >/dev/null
+    rc=$?
+fi
+if [ "$rc" = "0" ]; then
+    grep "55" tmp/scribe/logs/central/default/default_current >/dev/null
     rc=$?
 fi
 
@@ -50,4 +59,7 @@ sleep 1
 ./scribed-client-stop tmp
 ./scribed-central-stop tmp
 sleep 1
+if [ "$rc" = "0" ]; then
+    echo "OK"
+fi
 return $rc