[Fawkes Git] branch/fzwilling/robot-memory: 4 revs updated. (0.5.0-3098-gb8f723a)

Frederik Zwilling zwilling at kbsg.rwth-aachen.de
Thu Aug 25 22:30:50 CEST 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, fzwilling/robot-memory has been updated
        to  b8f723a3d70ad7ff4cfe3360ebbbf0d7dff3ef0c (commit)
       via  0103dae0e20e1f554ecbb8084422157c94f7976f (commit)
       via  d12243ddb9a7d991e4661c464ba4c20a82b9d32d (commit)
       via  f6f4c0569cfa901c555a4d5177bd1387092dd238 (commit)
      from  e1ca80b64149553b3e4b45393b7af50d3b3ff3e9 (commit)

http://git.fawkesrobotics.org/fawkes.git/fzwilling/robot-memory

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- *Log* ---------------------------------------------------------------
commit f6f4c0569cfa901c555a4d5177bd1387092dd238
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Thu Aug 25 02:16:47 2016 +0200
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Thu Aug 25 21:59:30 2016 +0200

    robot-memory: appropriate return values for query,insert,update,remove
    
    Added proper return values. 1/0 for successful/failed
    insert,update,remove. Cursor for query or NULL for invalid query.

http://git.fawkesrobotics.org/fawkes.git/commit/f6f4c05
http://trac.fawkesrobotics.org/changeset/f6f4c05

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit d12243ddb9a7d991e4661c464ba4c20a82b9d32d
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Thu Aug 25 02:19:47 2016 +0200
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Thu Aug 25 21:59:35 2016 +0200

    robot-memory-tests: added tests for query,insert,update,remove

http://git.fawkesrobotics.org/fawkes.git/commit/d12243d
http://trac.fawkesrobotics.org/changeset/d12243d

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit 0103dae0e20e1f554ecbb8084422157c94f7976f
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Thu Aug 25 21:57:23 2016 +0200
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Thu Aug 25 21:59:42 2016 +0200

    robot-memory: configurable debug output

http://git.fawkesrobotics.org/fawkes.git/commit/0103dae
http://trac.fawkesrobotics.org/changeset/0103dae

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
commit b8f723a3d70ad7ff4cfe3360ebbbf0d7dff3ef0c
Author:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
AuthorDate: Thu Aug 25 21:57:57 2016 +0200
Commit:     Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
CommitDate: Thu Aug 25 21:59:46 2016 +0200

    robot-memory-test: properly quit fawkes when tests finished

http://git.fawkesrobotics.org/fawkes.git/commit/b8f723a
http://trac.fawkesrobotics.org/changeset/b8f723a

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------
 cfg/conf.d/robot-memory.yaml                       |    3 +-
 src/plugins/robot-memory/Makefile                  |    1 +
 src/plugins/robot-memory/robot_memory.cpp          |  170 ++++++++++++--------
 src/plugins/robot-memory/robot_memory.h            |   13 +-
 .../robot-memory/test-plugin/robot_memory_test.cpp |  100 ++++++++++++-
 .../robot-memory/test-plugin/robot_memory_test.h   |    5 +-
 .../test-plugin/robot_memory_test_thread.cpp       |    9 +-
 7 files changed, 223 insertions(+), 78 deletions(-)


- *Diffs* -------------------------------------------------------------

- *commit* f6f4c0569cfa901c555a4d5177bd1387092dd238 - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Thu Aug 25 02:16:47 2016 +0200
Subject: robot-memory: appropriate return values for query,insert,update,remove

 src/plugins/robot-memory/robot_memory.cpp |   66 ++++++++++++++---------------
 src/plugins/robot-memory/robot_memory.h   |   12 ++++--
 2 files changed, 40 insertions(+), 38 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/robot_memory.cpp b/src/plugins/robot-memory/robot_memory.cpp
index d460f5a..d6bd428 100644
--- a/src/plugins/robot-memory/robot_memory.cpp
+++ b/src/plugins/robot-memory/robot_memory.cpp
@@ -54,7 +54,7 @@ void RobotMemory::init()
   logger_->log_info(name_, "Started RobotMemory");
   default_collection_ = "fawkes.msglog";
   try {
-    default_collection_ = config_->get_string("/plugins/mongodb/test-collection");
+    default_collection_ = config_->get_string("/plugins/robot-memory/default-collection");
   } catch (Exception &e) {}
 
   //init blackboard interface
@@ -64,7 +64,7 @@ void RobotMemory::init()
   rm_if_->write();
 }
 
-void RobotMemory::query(std::string query_string, std::string collection)
+QResCursor RobotMemory::query(std::string query_string, std::string collection)
 {
   if(collection == "")
   {
@@ -82,47 +82,39 @@ void RobotMemory::query(std::string query_string, std::string collection)
   } catch (DBException &e) {
     logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
                       query_string.c_str(), e.toString().c_str());
-    return;
+    return NULL;
   }
 
-  //introspect query
-  log(query, "executing query:");
+//  //introspect query
+//  log(query, "executing query:");
 
-  //check if virtual knowledge is queried
-  //rename field in query
-  if(query.getFilter().hasField("class")){
-    set_fields(query, std::string("{type:\"") +
-               query.getFilter()["class"].String() + "\"}");
-    remove_field(query, "class");
-  }
-  log(query, "Virtual query:");
 //  //TODO: computation on demand
+//  //check if virtual knowledge is queried
+//  //rename field in query
+//  if(query.getFilter().hasField("class")){
+//    set_fields(query, std::string("{type:\"") +
+//               query.getFilter()["class"].String() + "\"}");
+//    remove_field(query, "class");
+//  }
+//
 //  if(query.getFilter().hasField("bbinterface")){
 //    collection = config->get_string("plugins/robot-memory/blackboard-collection");
 //    gen_blackboard_data(query.getFilter()["bbinterface"].String());
 //  }
-  log(query, "Virtual query:");
 
   //actually execute query
-  std::unique_ptr<DBClientCursor> cursor;
+  QResCursor cursor;
   try{
     cursor = mongodb_client_->query(collection, query);
   } catch (DBException &e) {
     logger_->log_error(name_, "Error for query %s\n Exception: %s",
                       query_string.c_str(), e.toString().c_str());
-    return;
-  }
-
-  if(cursor->more()){
-    BSONObj res = cursor->next();
-    logger_->log_info(name_, "Query One result:\n%s", res.toString().c_str());
-  }
-  else {
-    logger_->log_info(name_, "Query result empty");
+    return NULL;
   }
+  return cursor;
 }
 
-void RobotMemory::insert(std::string insert_string, std::string collection)
+int RobotMemory::insert(std::string insert_string, std::string collection)
 {
   if(collection == "")
   {
@@ -140,7 +132,7 @@ void RobotMemory::insert(std::string insert_string, std::string collection)
   } catch (DBException &e) {
     logger_->log_error(name_, "Can't parse insert_string '%s'\n Exception: %s",
                       insert_string.c_str(), e.toString().c_str());
-    return;
+    return 0;
   }
 
   log(obj, "Inserting:");
@@ -153,11 +145,13 @@ void RobotMemory::insert(std::string insert_string, std::string collection)
   } catch (DBException &e) {
     logger_->log_error(name_, "Error for insert %s\n Exception: %s",
                       insert_string.c_str(), e.toString().c_str());
-    return;
+    return 0;
   }
+  //return success
+  return 1;
 }
 
-void RobotMemory::update(std::string query_string, std::string update_string,
+int RobotMemory::update(std::string query_string, std::string update_string,
                                     std::string collection)
 {
   if(collection == "")
@@ -177,7 +171,7 @@ void RobotMemory::update(std::string query_string, std::string update_string,
   } catch (DBException &e) {
     logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
                       query_string.c_str(), e.toString().c_str());
-    return;
+    return 0;
   }
   BSONObj update;
   try{
@@ -185,7 +179,7 @@ void RobotMemory::update(std::string query_string, std::string update_string,
   } catch (DBException &e) {
     logger_->log_error(name_, "Can't parse update_string '%s'\n Exception: %s",
                       update_string.c_str(), e.toString().c_str());
-    return;
+    return 0;
   }
 
   log(query, "Updating documents for query:");
@@ -197,11 +191,13 @@ void RobotMemory::update(std::string query_string, std::string update_string,
   } catch (DBException &e) {
     logger_->log_error(name_, "Error for update %s for query %s\n Exception: %s",
                       update_string.c_str(), query_string.c_str(), e.toString().c_str());
-    return;
+    return 0;
   }
+  //return success
+  return 1;
 }
 
-void RobotMemory::remove(std::string query_string, std::string collection)
+int RobotMemory::remove(std::string query_string, std::string collection)
 {
   if(collection == "")
   {
@@ -220,7 +216,7 @@ void RobotMemory::remove(std::string query_string, std::string collection)
   } catch (DBException &e) {
     logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
                       query_string.c_str(), e.toString().c_str());
-    return;
+    return 0;
   }
 
   //introspect
@@ -232,8 +228,10 @@ void RobotMemory::remove(std::string query_string, std::string collection)
   } catch (DBException &e) {
     logger_->log_error(name_, "Error for query %s\n Exception: %s",
                       query_string.c_str(), e.toString().c_str());
-    return;
+    return 0;
   }
+  //return success
+  return 1;
 }
 
 void
diff --git a/src/plugins/robot-memory/robot_memory.h b/src/plugins/robot-memory/robot_memory.h
index 8584de1..c216df7 100644
--- a/src/plugins/robot-memory/robot_memory.h
+++ b/src/plugins/robot-memory/robot_memory.h
@@ -25,6 +25,7 @@
 #include <aspect/configurable.h>
 #include <aspect/logging.h>
 #include <aspect/blackboard.h>
+#include <memory>
 
 #include <mongo/client/dbclient.h>
 #include "interfaces/RobotMemoryInterface.h"
@@ -34,6 +35,9 @@ namespace fawkes {
   class RobotMemoryInterface;
 }
 
+///typedef for shorter type description
+typedef std::unique_ptr<mongo::DBClientCursor> QResCursor;
+
 /*
  *
  */
@@ -48,10 +52,10 @@ class RobotMemory
     virtual ~RobotMemory();
 
     //robot memory functions
-    void query(std::string query, std::string collection = "");
-    void insert(std::string insert, std::string collection = "");
-    void update(std::string query, std::string update, std::string collection = "");
-    void remove(std::string query, std::string collection = "");
+    QResCursor query(std::string query, std::string collection = "");
+    int insert(std::string insert, std::string collection = "");
+    int update(std::string query, std::string update, std::string collection = "");
+    int remove(std::string query, std::string collection = "");
 
   private:
     mongo::DBClientBase* mongodb_client_;

- *commit* d12243ddb9a7d991e4661c464ba4c20a82b9d32d - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Thu Aug 25 02:19:47 2016 +0200
Subject: robot-memory-tests: added tests for query,insert,update,remove

 src/plugins/robot-memory/Makefile                  |    1 +
 .../robot-memory/test-plugin/robot_memory_test.cpp |   99 +++++++++++++++++++-
 .../robot-memory/test-plugin/robot_memory_test.h   |    3 +
 3 files changed, 102 insertions(+), 1 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/Makefile b/src/plugins/robot-memory/Makefile
index 6deb5cb..84453a7 100644
--- a/src/plugins/robot-memory/Makefile
+++ b/src/plugins/robot-memory/Makefile
@@ -20,6 +20,7 @@ include $(BUILDCONFDIR)/tf/tf.mk
 include $(BASEDIR)/src/plugins/mongodb/mongodb.mk
 
 PRESUBDIRS = interfaces aspect
+SUBDIRS = test-plugin
 
 LIBS_robot_memory = fawkescore fawkesaspects fawkesblackboard fawkesinterface \
 		fawkesutils fawkeslogging fawkesmongodbaspect fvutils \
diff --git a/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp b/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
index 06888ea..e326900 100644
--- a/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
+++ b/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
@@ -24,7 +24,8 @@
 //init static variable
 RobotMemory* RobotMemoryTestEnvironment::robot_memory = NULL;
 
-
+using namespace fawkes;
+using namespace mongo;
 
 /**
  * Setup for each test
@@ -44,6 +45,102 @@ TEST_F(RobotMemoryTest, AspectAvailable)
   ASSERT_FALSE(robot_memory==NULL);
 }
 
+TEST_F(RobotMemoryTest, QueryResultEmpty)
+{
+  QResCursor qres = robot_memory->query("{somekey:'should_not_exist'}");
+  ASSERT_FALSE(qres->more());
+}
+
+TEST_F(RobotMemoryTest, StoreAndQuery)
+{
+  ASSERT_TRUE(robot_memory->insert("{'testkey':'value'}"));
+  QResCursor qres = robot_memory->query("{'testkey':'value'}");
+  ASSERT_TRUE(qres->more());
+  ASSERT_TRUE(contains_pairs(qres->next(), fromjson("{'testkey':'value'}")));
+}
 
+TEST_F(RobotMemoryTest, StoreAndQueryOtherCollection)
+{
+  ASSERT_TRUE(robot_memory->insert("{'testkey':'value'}", "robmem.othercollection"));
+  QResCursor qres = robot_memory->query("{'testkey':'value'}", "robmem.othercollection");
+  ASSERT_TRUE(qres->more());
+  ASSERT_TRUE(contains_pairs(qres->next(), fromjson("{'testkey':'value'}")));
+}
 
+TEST_F(RobotMemoryTest, StoreUpdateQuery)
+{
+  ASSERT_TRUE(robot_memory->insert("{'inserting':'something',as:0.5}"));
+  ASSERT_TRUE(robot_memory->update("{'inserting':'something',as:0.5}",
+      "{'updated':'something',as:3.0,extra:true}"));
+  QResCursor qres = robot_memory->query("{'updated':'something'}");
+  ASSERT_TRUE(qres->more());
+  ASSERT_TRUE(contains_pairs(qres->next(), fromjson(
+      "{'updated':'something',as:3.0,extra:true}")));
+}
+
+TEST_F(RobotMemoryTest, StoreRemoveQuery)
+{
+  ASSERT_TRUE(robot_memory->insert("{to_be:'removed'}"));
+  ASSERT_TRUE(robot_memory->remove("{to_be:'removed'}"));
+  QResCursor qres = robot_memory->query("{to_be:'removed'}");
+  ASSERT_FALSE(qres->more());
+}
+
+TEST_F(RobotMemoryTest, QueryInvalidCaught)
+{
+  ASSERT_EQ(robot_memory->query("{key:'not existing'}"), NULL);
+}
+
+TEST_F(RobotMemoryTest, InsertInvalidCaught)
+{
+  ASSERT_NO_THROW(robot_memory->insert("{'testkey'::'value'}"));
+  ASSERT_FALSE(robot_memory->insert("warbagarbl"));
+}
 
+TEST_F(RobotMemoryTest, UpdateInvalidCaught)
+{
+  ASSERT_NO_THROW(robot_memory->update("{'testkey'::'value'}",
+      "{'key':'update'}"));
+  ASSERT_NO_THROW(robot_memory->update("{'testkey':'good'}",
+      "{'bad':1.2.3}"));
+  ASSERT_FALSE(robot_memory->update("{([})]", "{'key':4}"));
+  ASSERT_FALSE(robot_memory->update("{'key':'valid'}", "invalid!"));
+}
+
+TEST_F(RobotMemoryTest, RemoveInvalidCaught)
+{
+  ASSERT_NO_THROW(robot_memory->remove("{____:4.56}"));
+  ASSERT_FALSE(robot_memory->remove("{([})]"));
+}
+
+TEST_F(RobotMemoryTest, AggregationQuery)
+{
+  //TODO: implement
+}
+
+TEST_F(RobotMemoryTest, MapReduceQuery)
+{
+  //TODO: implement
+}
+
+TEST_F(RobotMemoryTest, JavaScriptQuery)
+{
+  //TODO: implement
+}
+
+
+::testing::AssertionResult RobotMemoryTest::contains_pairs(BSONObj obj, BSONObj exp)
+{
+  for(BSONObjIterator it = exp.begin(); it.more();)
+  {
+    BSONElement kvpair = it.next();
+    printf("checking %s\n", kvpair.toString().c_str());
+    if(!obj.hasElement(kvpair.fieldName())
+        || obj.getField(kvpair.fieldName()) != kvpair)
+    {
+      return ::testing::AssertionFailure() << obj.toString()
+          << " does not include {" << kvpair.toString() << "}";
+    }
+  }
+  return ::testing::AssertionSuccess();
+}
diff --git a/src/plugins/robot-memory/test-plugin/robot_memory_test.h b/src/plugins/robot-memory/test-plugin/robot_memory_test.h
index 3b0a902..d28dcca 100644
--- a/src/plugins/robot-memory/test-plugin/robot_memory_test.h
+++ b/src/plugins/robot-memory/test-plugin/robot_memory_test.h
@@ -50,6 +50,9 @@ class RobotMemoryTest : public ::testing::Test
  protected:
   virtual void SetUp();
   RobotMemory* robot_memory;
+
+ protected:
+  ::testing::AssertionResult contains_pairs(mongo::BSONObj obj, mongo::BSONObj exp);
 };
 
 

- *commit* 0103dae0e20e1f554ecbb8084422157c94f7976f - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Thu Aug 25 21:57:23 2016 +0200
Subject: robot-memory: configurable debug output

 cfg/conf.d/robot-memory.yaml                       |    3 +-
 src/plugins/robot-memory/robot_memory.cpp          |  104 ++++++++++++++------
 src/plugins/robot-memory/robot_memory.h            |    1 +
 .../robot-memory/test-plugin/robot_memory_test.cpp |    3 +-
 .../robot-memory/test-plugin/robot_memory_test.h   |    2 +-
 5 files changed, 78 insertions(+), 35 deletions(-)

_Diff for modified files_:
diff --git a/cfg/conf.d/robot-memory.yaml b/cfg/conf.d/robot-memory.yaml
index 03e1f8e..51c959b 100644
--- a/cfg/conf.d/robot-memory.yaml
+++ b/cfg/conf.d/robot-memory.yaml
@@ -6,7 +6,8 @@ doc-url: !url http://trac.fawkesrobotics.org/wiki/Plugins/robot-memory
 plugins/robot-memory:
 
   database: fawkes
-  test-collection: "robmem.test"
+  default-collection: "robmem.test"
   interface-name: "memory"
+  more-debug-output: true
 
   blackboard-collection: "robmem.bb"
\ No newline at end of file
diff --git a/src/plugins/robot-memory/robot_memory.cpp b/src/plugins/robot-memory/robot_memory.cpp
index d6bd428..e3024c9 100644
--- a/src/plugins/robot-memory/robot_memory.cpp
+++ b/src/plugins/robot-memory/robot_memory.cpp
@@ -40,6 +40,7 @@ RobotMemory::RobotMemory(fawkes::Configuration* config, fawkes::Logger* logger,
   clock_ = clock;
   mongodb_client_ = mongodb_client;
   blackboard_ = blackboard;
+  debug_ = false;
 }
 
 RobotMemory::~RobotMemory()
@@ -56,12 +57,20 @@ void RobotMemory::init()
   try {
     default_collection_ = config_->get_string("/plugins/robot-memory/default-collection");
   } catch (Exception &e) {}
+  try {
+    debug_ = config_->get_bool("/plugins/robot-memory/more-debug-output");
+  } catch (Exception &e) {}
 
   //init blackboard interface
   rm_if_ = blackboard_->open_for_writing<RobotMemoryInterface>(config_->get_string("/plugins/robot-memory/interface-name").c_str());
   rm_if_->set_error("");
   rm_if_->set_result("");
   rm_if_->write();
+
+  if(debug_)
+  {
+    logger_->log_info(name_, "Initialized RobotMemory");
+  }
 }
 
 QResCursor RobotMemory::query(std::string query_string, std::string collection)
@@ -70,7 +79,10 @@ QResCursor RobotMemory::query(std::string query_string, std::string collection)
   {
     collection = default_collection_;
   }
-  logger_->log_info(name_, "Executing Query %s on collection %s", query_string.c_str(), collection);
+  if(debug_)
+  {
+    logger_->log_info(name_, "Executing Query %s on collection %s", query_string.c_str(), collection);
+  }
 
   //only one query at a time
   MutexLocker lock(mutex_);
@@ -80,8 +92,11 @@ QResCursor RobotMemory::query(std::string query_string, std::string collection)
   try{
     query = Query(query_string);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
-                      query_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
+          query_string.c_str(), e.toString().c_str());
+    }
     return NULL;
   }
 
@@ -107,8 +122,11 @@ QResCursor RobotMemory::query(std::string query_string, std::string collection)
   try{
     cursor = mongodb_client_->query(collection, query);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Error for query %s\n Exception: %s",
-                      query_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Error for query %s\n Exception: %s",
+          query_string.c_str(), e.toString().c_str());
+    }
     return NULL;
   }
   return cursor;
@@ -120,7 +138,10 @@ int RobotMemory::insert(std::string insert_string, std::string collection)
   {
     collection = default_collection_;
   }
-  logger_->log_info(name_, "Executing Query %s on collection %s", insert_string.c_str(), collection);
+  if(debug_)
+  {
+    logger_->log_info(name_, "Executing Query %s on collection %s", insert_string.c_str(), collection);
+  }
 
   //only one query at a time
   MutexLocker lock(mutex_);
@@ -130,21 +151,25 @@ int RobotMemory::insert(std::string insert_string, std::string collection)
   try{
     obj = fromjson(insert_string);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Can't parse insert_string '%s'\n Exception: %s",
-                      insert_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Can't parse insert_string '%s'\n Exception: %s",
+          insert_string.c_str(), e.toString().c_str());
+    }
     return 0;
   }
 
-  log(obj, "Inserting:");
   set_fields(obj, "{type: \"test\"}");
-  log(obj, "Updated Inserting:");
 
   //actually execute insert
   try{
     mongodb_client_->insert(collection, obj);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Error for insert %s\n Exception: %s",
-                      insert_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Error for insert %s\n Exception: %s",
+          insert_string.c_str(), e.toString().c_str());
+    }
     return 0;
   }
   //return success
@@ -158,8 +183,11 @@ int RobotMemory::update(std::string query_string, std::string update_string,
   {
     collection = default_collection_;
   }
-  logger_->log_info(name_, "Executing Update %s for query %s on collection %s",
-                   update_string.c_str(), query_string.c_str(), collection);
+  if(debug_)
+  {
+    logger_->log_info(name_, "Executing Update %s for query %s on collection %s",
+        update_string.c_str(), query_string.c_str(), collection);
+  }
 
   //only one query at a time
   MutexLocker lock(mutex_);
@@ -169,28 +197,34 @@ int RobotMemory::update(std::string query_string, std::string update_string,
   try{
     query = Query(query_string);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
-                      query_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
+          query_string.c_str(), e.toString().c_str());
+    }
     return 0;
   }
   BSONObj update;
   try{
     update = fromjson(update_string);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Can't parse update_string '%s'\n Exception: %s",
-                      update_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Can't parse update_string '%s'\n Exception: %s",
+          update_string.c_str(), e.toString().c_str());
+    }
     return 0;
   }
 
-  log(query, "Updating documents for query:");
-  log(update, "Updating with:");
-
   //actually execute update
   try{
     mongodb_client_->update(collection, query, update);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Error for update %s for query %s\n Exception: %s",
-                      update_string.c_str(), query_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Error for update %s for query %s\n Exception: %s",
+          update_string.c_str(), query_string.c_str(), e.toString().c_str());
+    }
     return 0;
   }
   //return success
@@ -203,8 +237,11 @@ int RobotMemory::remove(std::string query_string, std::string collection)
   {
     collection = default_collection_;
   }
-  logger_->log_info(name_, "Executing Remove %s on collection %s",
-                    query_string.c_str(), collection);
+  if(debug_)
+  {
+    logger_->log_info(name_, "Executing Remove %s on collection %s",
+        query_string.c_str(), collection);
+  }
 
   //only one query at a time
   MutexLocker lock(mutex_);
@@ -214,20 +251,23 @@ int RobotMemory::remove(std::string query_string, std::string collection)
   try{
     query = Query(query_string);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
-                      query_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Can't parse query_string '%s'\n Exception: %s",
+          query_string.c_str(), e.toString().c_str());
+    }
     return 0;
   }
 
-  //introspect
-  log(query, "Removing documents for query:");
-
   //actually execute remove
   try{
     mongodb_client_->remove(collection, query);
   } catch (DBException &e) {
-    logger_->log_error(name_, "Error for query %s\n Exception: %s",
-                      query_string.c_str(), e.toString().c_str());
+    if(debug_)
+    {
+      logger_->log_error(name_, "Error for query %s\n Exception: %s",
+          query_string.c_str(), e.toString().c_str());
+    }
     return 0;
   }
   //return success
diff --git a/src/plugins/robot-memory/robot_memory.h b/src/plugins/robot-memory/robot_memory.h
index c216df7..7a095f4 100644
--- a/src/plugins/robot-memory/robot_memory.h
+++ b/src/plugins/robot-memory/robot_memory.h
@@ -66,6 +66,7 @@ class RobotMemory
 
     const char* name_ = "RobotMemory";
     std::string default_collection_;
+    bool debug_;
     fawkes::Mutex *mutex_;
     fawkes::RobotMemoryInterface* rm_if_;
 
diff --git a/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp b/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
index e326900..6f8f68e 100644
--- a/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
+++ b/src/plugins/robot-memory/test-plugin/robot_memory_test.cpp
@@ -47,6 +47,7 @@ TEST_F(RobotMemoryTest, AspectAvailable)
 
 TEST_F(RobotMemoryTest, QueryResultEmpty)
 {
+  ASSERT_TRUE(robot_memory->insert("{'insert':'something to have the namespace'}"));
   QResCursor qres = robot_memory->query("{somekey:'should_not_exist'}");
   ASSERT_FALSE(qres->more());
 }
@@ -88,7 +89,7 @@ TEST_F(RobotMemoryTest, StoreRemoveQuery)
 
 TEST_F(RobotMemoryTest, QueryInvalidCaught)
 {
-  ASSERT_EQ(robot_memory->query("{key:'not existing'}"), NULL);
+  ASSERT_FALSE(robot_memory->query("{key-:+'not existing'}"));
 }
 
 TEST_F(RobotMemoryTest, InsertInvalidCaught)
diff --git a/src/plugins/robot-memory/test-plugin/robot_memory_test.h b/src/plugins/robot-memory/test-plugin/robot_memory_test.h
index d28dcca..a9cdb07 100644
--- a/src/plugins/robot-memory/test-plugin/robot_memory_test.h
+++ b/src/plugins/robot-memory/test-plugin/robot_memory_test.h
@@ -38,7 +38,7 @@ class RobotMemoryTestEnvironment : public ::testing::Environment
   }
   virtual ~RobotMemoryTestEnvironment() {}
   void SetUp() {}
-  virtual void TearDown() {}
+  virtual void TearDown(){}
  public:
   static RobotMemory* robot_memory;
 };

- *commit* b8f723a3d70ad7ff4cfe3360ebbbf0d7dff3ef0c - - - - - - - - - -
Author:  Frederik Zwilling <zwilling at kbsg.rwth-aachen.de>
Date:    Thu Aug 25 21:57:57 2016 +0200
Subject: robot-memory-test: properly quit fawkes when tests finished

 .../test-plugin/robot_memory_test_thread.cpp       |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

_Diff for modified files_:
diff --git a/src/plugins/robot-memory/test-plugin/robot_memory_test_thread.cpp b/src/plugins/robot-memory/test-plugin/robot_memory_test_thread.cpp
index 2a3d7c3..5bedac1 100644
--- a/src/plugins/robot-memory/test-plugin/robot_memory_test_thread.cpp
+++ b/src/plugins/robot-memory/test-plugin/robot_memory_test_thread.cpp
@@ -23,7 +23,7 @@
 
 #include "robot_memory_test_thread.h"
 #include <core/exception.h>
-
+#include <baseapp/run.h>
 #include <gtest/gtest.h>
 
 using namespace fawkes;
@@ -54,10 +54,9 @@ RobotMemoryTestThread::init()
 void
 RobotMemoryTestThread::loop()
 {
-  logger->log_warn(name(), "Finished tests with result %d, shutting down...", test_result_);
-
-  //stop fawkes by throwing an exception
-  throw fawkes::Exception("Stopping Fawkes after running tests in %s", name());
+  logger->log_warn(name(), "Finished tests with, quitting as intended...");
+  //stop fawkes to finish the testing run
+  fawkes::runtime::quit();
 }
 
 void




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list