Changing naming convention

Format for files: /<forwarding-hint>/<appname>/file/<hash>/<device_name>/<segment>
Format for actions: /<forwarding-hint>/<appname>/<shared-folder>/action/<device_name>/<action-seq>

All tests pass

Change-Id: Ie42c0f29813839ca7cc42fa52b5c3f246da2e130
diff --git a/test/test-action-log.cc b/test/test-action-log.cc
index 84c0cf9..1a1ff1f 100644
--- a/test/test-action-log.cc
+++ b/test/test-action-log.cc
@@ -47,7 +47,7 @@
   SyncLogPtr syncLog = make_shared<SyncLog> (tmpdir, localName);
   CcnxWrapperPtr ccnx = make_shared<CcnxWrapper> ();
 
-  ActionLogPtr actionLog = make_shared<ActionLog> (ccnx, tmpdir, syncLog, "top-secret",
+  ActionLogPtr actionLog = make_shared<ActionLog> (ccnx, tmpdir, syncLog, "top-secret", "test-chronoshare",
                                                    ActionLog::OnFileAddedOrChangedCallback(), ActionLog::OnFileRemovedCallback ());
 
 // const std::string &filename,
@@ -77,24 +77,27 @@
   pco = actionLog->LookupActionPco (localName, 1);
   BOOST_CHECK_EQUAL ((bool)pco, true);
 
-  BOOST_CHECK_EQUAL (pco->name (), "/alex/action/top-secret/%00%01");
+  BOOST_CHECK_EQUAL (pco->name (), "/test-chronoshare/top-secret/action/alex/%00%01");
 
-  ActionItemPtr action = actionLog->LookupAction (Name ("/alex/action/top-secret")(0));
+  ActionItemPtr action = actionLog->LookupAction (Name ("/test-chronoshare/top-secret/action/alex")(0));
   BOOST_CHECK_EQUAL ((bool)action, false);
 
-  action = actionLog->LookupAction (Name ("/alex/action/top-secret")(1));
+  action = actionLog->LookupAction (Name ("/test-chronoshare/top-secret/action/alex")(1));
   BOOST_CHECK_EQUAL ((bool)action, true);
 
-  BOOST_CHECK_EQUAL (action->version (), 0);
-  BOOST_CHECK_EQUAL (action->action (), 0);
+  if (action)
+    {
+      BOOST_CHECK_EQUAL (action->version (), 0);
+      BOOST_CHECK_EQUAL (action->action (), 0);
 
-  BOOST_CHECK_EQUAL (action->filename (), "file.txt");
-  BOOST_CHECK_EQUAL (action->seg_num (), 10);
-  BOOST_CHECK_EQUAL (action->file_hash ().size (), 32);
-  BOOST_CHECK_EQUAL (action->mode (), 0755);
+      BOOST_CHECK_EQUAL (action->filename (), "file.txt");
+      BOOST_CHECK_EQUAL (action->seg_num (), 10);
+      BOOST_CHECK_EQUAL (action->file_hash ().size (), 32);
+      BOOST_CHECK_EQUAL (action->mode (), 0755);
 
-  BOOST_CHECK_EQUAL (action->has_parent_device_name (), false);
-  BOOST_CHECK_EQUAL (action->has_parent_seq_no (), false);
+      BOOST_CHECK_EQUAL (action->has_parent_device_name (), false);
+      BOOST_CHECK_EQUAL (action->has_parent_seq_no (), false);
+    }
 
   actionLog->AddLocalActionUpdate ("file.txt", *Hash::FromString ("2ff304769cdb0125ac039e6fe7575f8576dceffc62618a431715aaf6eea2bf1c"),
                               time (NULL), 0755, 10);
@@ -105,11 +108,14 @@
   action = actionLog->LookupAction (Name ("/alex"), 2);
   BOOST_CHECK_EQUAL ((bool)action, true);
 
-  BOOST_CHECK_EQUAL (action->has_parent_device_name (), true);
-  BOOST_CHECK_EQUAL (action->has_parent_seq_no (), true);
+  if (action)
+    {
+      BOOST_CHECK_EQUAL (action->has_parent_device_name (), true);
+      BOOST_CHECK_EQUAL (action->has_parent_seq_no (), true);
 
-  BOOST_CHECK_EQUAL (action->parent_seq_no (), 1);
-  BOOST_CHECK_EQUAL (action->version (), 1);
+      BOOST_CHECK_EQUAL (action->parent_seq_no (), 1);
+      BOOST_CHECK_EQUAL (action->version (), 1);
+    }
 
   BOOST_CHECK_NO_THROW (actionLog->AddRemoteAction (pco));
   BOOST_CHECK_EQUAL (actionLog->LogSize (), 2);
@@ -122,7 +128,7 @@
   item.set_timestamp (time (NULL));
 
   BytesPtr item_msg = serializeMsg (item);
-  Name actionName = Name ("/zhenkai")("action")("top-secret")(1);
+  Name actionName = Name ("/")("test-chronoshare")("top-secret")("action")("zhenkai")(1);
   Bytes actionData = ccnx->createContentObject (actionName, head (*item_msg), item_msg->size ());
 
   pco = make_shared<ParsedContentObject> (actionData);
diff --git a/test/test-executor.cc b/test/test-executor.cc
index 9bdd43a..a13f373 100644
--- a/test/test-executor.cc
+++ b/test/test-executor.cc
@@ -43,12 +43,13 @@
 
   {
     Executor executor (3);
+    executor.start ();
     Executor::Job job = bind(timeConsumingJob);
 
     executor.execute(job);
     executor.execute(job);
 
-    usleep(1000);
+    usleep(2000);
     // both jobs should have been taken care of
     BOOST_CHECK_EQUAL(executor.jobQueueSize(), 0);
 
@@ -72,6 +73,8 @@
     // all jobs should have been fetched
     usleep(501000);
     BOOST_CHECK_EQUAL(executor.jobQueueSize(), 0);
+
+    executor.shutdown ();
   } //separate scope to ensure that destructor is called
 
 
diff --git a/test/test-fetch-manager.cc b/test/test-fetch-manager.cc
index 24ca59c..5abe47d 100644
--- a/test/test-fetch-manager.cc
+++ b/test/test-fetch-manager.cc
@@ -24,6 +24,9 @@
 #include "ccnx-wrapper.h"
 #include <boost/test/unit_test.hpp>
 #include <boost/make_shared.hpp>
+#include "logging.h"
+
+INIT_LOGGER ("Test.FetchManager");
 
 using namespace Ccnx;
 using namespace std;
@@ -51,6 +54,8 @@
   void
   onData (const Ccnx::Name &deviceName, const Ccnx::Name &basename, uint64_t seqno, Ccnx::PcoPtr pco)
   {
+    _LOG_TRACE ("onData: " << seqno);
+
     recvData.insert (seqno);
     differentNames.insert (basename);
     Name name = basename;
@@ -90,6 +95,8 @@
 
 BOOST_AUTO_TEST_CASE (TestFetcher)
 {
+  INIT_LOGGERS ();
+
   CcnxWrapperPtr ccnx = make_shared<CcnxWrapper> ();
 
   Name baseName ("/base");
@@ -111,6 +118,7 @@
 
   FetcherTestData data;
   ExecutorPtr executor = make_shared<Executor>(1);
+  executor->start ();
 
   Fetcher fetcher (ccnx,
                    executor,
@@ -176,6 +184,8 @@
     BOOST_CHECK_EQUAL (recvData.str (), "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, ");
     BOOST_CHECK_EQUAL (recvData.str (), recvContent.str ());
   }
+
+  executor->shutdown ();
 }
 
 // BOOST_AUTO_TEST_CASE (CcnxWrapperSelector)
diff --git a/test/test-object-manager.cc b/test/test-object-manager.cc
index 8f2ef2c..36c5c57 100644
--- a/test/test-object-manager.cc
+++ b/test/test-object-manager.cc
@@ -49,7 +49,7 @@
   Name deviceName ("/device");
 
   CcnxWrapperPtr ccnx = make_shared<CcnxWrapper> ();
-  ObjectManager manager (ccnx, tmpdir);
+  ObjectManager manager (ccnx, tmpdir, "test-chronoshare");
 
   tuple<HashPtr,int> hash_semgents = manager.localFileToObjects (fs::path("test") / "test-object-manager.cc", deviceName);
 
diff --git a/test/test-serve-and-fetch.cc b/test/test-serve-and-fetch.cc
index a25fa89..9d71cfb 100644
--- a/test/test-serve-and-fetch.cc
+++ b/test/test-serve-and-fetch.cc
@@ -36,6 +36,10 @@
 #include <stdio.h>
 #include <ctime>
 
+#include "logging.h"
+
+INIT_LOGGER("Test.ServerAndFetch");
+
 using namespace Ccnx;
 using namespace std;
 using namespace boost;
@@ -113,47 +117,55 @@
 
 BOOST_AUTO_TEST_CASE (TestServeAndFetch)
 {
-  cout << "Setting up test environment ..." << endl;
+  INIT_LOGGERS ();
+
+  _LOG_DEBUG ("Setting up test environment ...");
   setup();
 
   CcnxWrapperPtr ccnx_serve = make_shared<CcnxWrapper>();
   usleep(1000);
   CcnxWrapperPtr ccnx_fetch = make_shared<CcnxWrapper>();
-  ObjectManager om(ccnx_serve, root);
 
   Name deviceName("/test/device");
   Name localPrefix("/local");
   Name broadcastPrefix("/broadcast");
 
+  const string APPNAME = "test-chronoshare";
+
   time_t start = time(NULL);
-  cout << "At time " << start << ", publish local file to database, this is extremely slow ..." << endl;
+  _LOG_DEBUG ("At time " << start << ", publish local file to database, this is extremely slow ...");
   // publish file to db
+  ObjectManager om(ccnx_serve, root, APPNAME);
   tuple<HashPtr, size_t> pub = om.localFileToObjects(filePath, deviceName);
   time_t end = time(NULL);
-  cout << "At time " << end <<", publish finally finished, used " << end - start << " seconds ..."<< endl;
+  _LOG_DEBUG ("At time " << end <<", publish finally finished, used " << end - start << " seconds ...");
 
   ActionLogPtr dummyLog;
-  ContentServer server(ccnx_serve, dummyLog, root, deviceName, "pentagon's secrets", 5);
+  ContentServer server(ccnx_serve, dummyLog, root, deviceName, "pentagon's secrets", APPNAME, 5);
   server.registerPrefix(localPrefix);
   server.registerPrefix(broadcastPrefix);
 
   FetchManager fm(ccnx_fetch, bind(simpleMap, _1));
   HashPtr hash = pub.get<0> ();
-  Name baseName = Name (deviceName)("file")(hash->GetHash(), hash->GetHashBytes());
+  Name baseName = Name ("/")(APPNAME)("file")(hash->GetHash(), hash->GetHashBytes())(deviceName);
+
   fm.Enqueue(deviceName, baseName, bind(segmentCallback, _1, _2, _3, _4), bind(finishCallback, _1, _2), 0, pub.get<1>() - 1);
 
   unique_lock<mutex> lock(mut);
   system_time timeout = get_system_time() + posix_time::milliseconds(5000);
   while (!finished)
-  {
-    if (!cond.timed_wait(lock, timeout))
     {
-      BOOST_FAIL("Fetching has not finished after 5 seconds");
-      break;
+      if (!cond.timed_wait(lock, timeout))
+        {
+          BOOST_FAIL ("Fetching has not finished after 5 seconds");
+          break;
+        }
     }
-  }
+  ccnx_fetch->shutdown ();
+  ccnx_serve->shutdown ();
 
-  cout << "ack : " << ack << endl;
+  _LOG_DEBUG ("Finish");
+  usleep(100000);
 
   teardown();
 }