fix test for file serve and fetch
diff --git a/src/content-server.cc b/src/content-server.cc
index 91b6561..542f453 100644
--- a/src/content-server.cc
+++ b/src/content-server.cc
@@ -24,10 +24,11 @@
using namespace Ccnx;
using namespace std;
-ContentServer::ContentServer(CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir)
+ContentServer::ContentServer(CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir, int freshness)
: m_ccnx(ccnx)
, m_actionLog(actionLog)
, m_dbFolder(rootDir / ".chronoshare")
+ , m_freshness(freshness)
{
}
@@ -64,11 +65,6 @@
void
ContentServer::serve(const Name &interest)
{
- int size = interest.size();
- cout << ">>> Serving: " << interest.getPartialName(0, size - 2) << ", seq = " << interest.getCompAsInt(size -1) << endl;
-
-
-
ReadLock lock(m_mutex);
for (PrefixIt it = m_prefixes.begin(); it != m_prefixes.end(); ++it)
{
@@ -110,7 +106,14 @@
if (co)
{
- m_ccnx->publishData(interest, *co);
+ if (m_freshness > 0)
+ {
+ m_ccnx->publishData(interest, *co, m_freshness);
+ }
+ else
+ {
+ m_ccnx->publishData(interest, *co);
+ }
}
}
}
diff --git a/src/content-server.h b/src/content-server.h
index 3eb2325..994f8b9 100644
--- a/src/content-server.h
+++ b/src/content-server.h
@@ -31,7 +31,7 @@
class ContentServer
{
public:
- ContentServer(Ccnx::CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir);
+ ContentServer(Ccnx::CcnxWrapperPtr ccnx, ActionLogPtr actionLog, const boost::filesystem::path &rootDir, int freshness = -1);
~ContentServer();
// the assumption is, when the interest comes in, interest is informs of
@@ -54,5 +54,6 @@
std::set<Ccnx::Name> m_prefixes;
Mutex m_mutex;
boost::filesystem::path m_dbFolder;
+ int m_freshness;
};
#endif // CONTENT_SERVER_H
diff --git a/src/fetcher.cc b/src/fetcher.cc
index e311461..5f731bb 100644
--- a/src/fetcher.cc
+++ b/src/fetcher.cc
@@ -96,7 +96,7 @@
Name x = Name(m_forwardingHint)(m_name)(m_minSendSeqNo+1);
int xsize = x.size();
- _LOG_DEBUG (" >>> i " << x.getPartialName(0, xsize - 2) << ", seq = " << (m_minSendSeqNo + 1 ));
+ //_LOG_DEBUG (" >>> i " << x.getPartialName(0, xsize - 2) << ", seq = " << (m_minSendSeqNo + 1 ));
// cout << ">>> " << m_minSendSeqNo+1 << endl;
m_ccnx->sendInterest (Name (m_forwardingHint)(m_name)(m_minSendSeqNo+1),
diff --git a/test/test-serve-and-fetch.cc b/test/test-serve-and-fetch.cc
index 4db2094..05782c2 100644
--- a/test/test-serve-and-fetch.cc
+++ b/test/test-serve-and-fetch.cc
@@ -34,6 +34,7 @@
#include <boost/thread/thread_time.hpp>
#include <boost/thread/condition_variable.hpp>
#include <stdio.h>
+#include <ctime>
using namespace Ccnx;
using namespace std;
@@ -112,6 +113,7 @@
BOOST_AUTO_TEST_CASE (TestServeAndFetch)
{
+ cout << "Setting up test environment ..." << endl;
setup();
CcnxWrapperPtr ccnx_serve = make_shared<CcnxWrapper>();
@@ -119,21 +121,26 @@
CcnxWrapperPtr ccnx_fetch = make_shared<CcnxWrapper>();
ObjectManager om(ccnx_serve, root);
- Name deviceName("/device");
+ Name deviceName("/test/device");
Name localPrefix("/local");
Name broadcastPrefix("/broadcast");
+
+ time_t start = time(NULL);
+ cout << "At time " << start << ", publish local file to database, this is extremely slow ..." << endl;
// publish file to db
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;
ActionLogPtr dummyLog;
- ContentServer server(ccnx_serve, dummyLog, root);
+ ContentServer server(ccnx_serve, dummyLog, root, 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());
- fm.Enqueue(deviceName, baseName, bind(segmentCallback, _1, _2, _3, _4), bind(finishCallback, _1, _2), 0, get<1>(pub));
+ 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);
@@ -146,6 +153,8 @@
}
}
+ cout << "ack : " << ack << endl;
+
teardown();
}