test for sync (failing)
diff --git a/src/ccnx-wrapper.cpp b/src/ccnx-wrapper.cpp
index 3f82889..c818cd2 100644
--- a/src/ccnx-wrapper.cpp
+++ b/src/ccnx-wrapper.cpp
@@ -60,7 +60,7 @@
m_thread.join ();
ccn_disconnect (m_handle);
- ccn_destroy (&m_handle);
+ //ccn_destroy (&m_handle);
}
void
diff --git a/src/sync-core.cc b/src/sync-core.cc
index 32a1243..e37a367 100644
--- a/src/sync-core.cc
+++ b/src/sync-core.cc
@@ -38,13 +38,13 @@
m_recoverClosure = new Closure(0, boost::bind(&SyncCore::handleRecoverData, this, _1, _2), boost::bind(&SyncCore::handleRecoverInterestTimeout, this, _1));
m_handle->setInterestFilter(m_syncPrefix, boost::bind(&SyncCore::handleInterest, this, _1));
m_log.initYP(m_yp);
- m_scheduler->start();
+ //m_scheduler->start();
sendSyncInterest();
}
SyncCore::~SyncCore()
{
- m_scheduler->shutdown();
+ //m_scheduler->shutdown();
if (m_syncClosure != 0)
{
delete m_syncClosure;
@@ -153,6 +153,9 @@
else if (m_log.LookupSyncLog(*hash) > 0)
{
// we know something more
+ cout << "SyncInterest: " << name << endl;
+ cout << "hash: " << *hash << endl;
+ cout << "root hash: " << *m_rootHash << endl;
SyncStateMsgPtr msg = m_log.FindStateDifferences(*hash, *m_rootHash);
Bytes syncData;
diff --git a/test/test-sync-core.cc b/test/test-sync-core.cc
new file mode 100644
index 0000000..cdec04d
--- /dev/null
+++ b/test/test-sync-core.cc
@@ -0,0 +1,86 @@
+#include "sync-core.h"
+
+#include <boost/test/unit_test.hpp>
+#include <boost/filesystem.hpp>
+
+using namespace std;
+using namespace Ccnx;
+using namespace boost::filesystem;
+
+BOOST_AUTO_TEST_SUITE(SyncCoreTests)
+
+SyncStateMsgPtr msg1;
+SyncStateMsgPtr msg2;
+
+void callback1(const SyncStateMsgPtr &ptr)
+{
+ msg1 = ptr;
+}
+
+void callback2(const SyncStateMsgPtr &ptr)
+{
+ msg2 = ptr;
+}
+
+BOOST_AUTO_TEST_CASE(SyncCoreTest)
+{
+ string dir = "./SyncCoreTest";
+ Name user1("/joker");
+ Name loc1("/gotham1");
+ Name user2("/darkknight");
+ Name loc2("/gotham2");
+ Name syncPrefix("/broadcast/darkknight");
+ CcnxWrapperPtr c1(new CcnxWrapper());
+ CcnxWrapperPtr c2(new CcnxWrapper());
+ SchedulerPtr scheduler(new Scheduler());
+ scheduler->start();
+
+ // clean the test dir
+ path d(dir);
+ if (exists(d))
+ {
+ remove_all(d);
+ }
+
+ SyncCore *core1 = new SyncCore(dir, user1, loc1, syncPrefix, bind(callback1, _1), c1, scheduler);
+ usleep(10000);
+ SyncCore *core2 = new SyncCore(dir, user2, loc2, syncPrefix, bind(callback2, _1), c2, scheduler);
+ usleep(10000);
+
+ SyncState state;
+
+ core1->updateLocalState(1);
+ usleep(100000);
+ BOOST_CHECK_EQUAL(msg2->state_size(), 1);
+ state = msg2->state(0);
+ BOOST_CHECK_EQUAL(state.seq(), 1);
+ BOOST_CHECK_EQUAL(user1, state.name());
+ BOOST_CHECK_EQUAL(loc1, state.locator());
+
+ core1->updateLocalState(5);
+ usleep(100000);
+ state = msg2->state(0);
+ BOOST_CHECK_EQUAL(state.seq(), 5);
+
+ core2->updateLocalState(10);
+ usleep(100000);
+ state = msg1->state(0);
+ BOOST_CHECK_EQUAL(state.seq(), 10);
+
+ // simple simultaneous data generation
+ core1->updateLocalState(11);
+ core2->updateLocalState(12);
+ usleep(100000);
+ state = msg1->state(0);
+ BOOST_CHECK_EQUAL(state.seq(), 12);
+ state = msg2->state(0);
+ BOOST_CHECK_EQUAL(state.seq(), 11);
+
+ // clean the test dir
+ if (exists(d))
+ {
+ remove_all(d);
+ }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/wscript b/wscript
index 69e49b9..92949b7 100644
--- a/wscript
+++ b/wscript
@@ -111,7 +111,7 @@
target="unit-tests",
source = bld.path.ant_glob(['test/**/*.cc']),
features=['cxx', 'cxxprogram'],
- use = 'BOOST_TEST ccnxx database',
+ use = 'BOOST_TEST BOOST_FILESYSTEM ccnxx database',
includes = ['include', 'src'],
)