blob: bf5801e7dc1658a30005fb5206752cddb38c10dd [file] [log] [blame]
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Yukai Tuccdcdba2016-10-24 13:48:01 -07003 * Copyright (c) 2013-2017, Regents of the University of California.
Alexander Afanasyevee7e6132013-01-03 20:03:14 -08004 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08005 * This file is part of ChronoShare, a decentralized file sharing application over NDN.
Alexander Afanasyevee7e6132013-01-03 20:03:14 -08006 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -08007 * ChronoShare is free software: you can redistribute it and/or modify it under the terms
8 * of the GNU General Public License as published by the Free Software Foundation, either
9 * version 3 of the License, or (at your option) any later version.
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080010 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080011 * ChronoShare is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080014 *
Alexander Afanasyevfa2f6622016-12-25 12:28:00 -080015 * You should have received copies of the GNU General Public License along with
16 * ChronoShare, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * See AUTHORS.md for complete list of ChronoShare authors and contributors.
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080019 */
20
Yukai Tuccdcdba2016-10-24 13:48:01 -070021#include "sync-log.hpp"
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080022
Yukai Tuccdcdba2016-10-24 13:48:01 -070023#include "test-common.hpp"
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080024
Yukai Tuccdcdba2016-10-24 13:48:01 -070025namespace ndn {
26namespace chronoshare {
27namespace tests {
28
Alexander Afanasyev68f2a952013-01-08 14:34:16 -080029namespace fs = boost::filesystem;
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080030
Yukai Tuccdcdba2016-10-24 13:48:01 -070031INIT_LOGGER("Test.SyncLog")
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080032
Yukai Tuccdcdba2016-10-24 13:48:01 -070033BOOST_FIXTURE_TEST_SUITE(TestSyncLog, IdentityManagementTimeFixture)
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080034
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080035BOOST_AUTO_TEST_CASE(BasicDatabaseTest)
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080036{
Yukai Tuccdcdba2016-10-24 13:48:01 -070037 fs::path tmpdir = fs::unique_path(UNIT_TEST_CONFIG_PATH);
38 if (exists(tmpdir)) {
39 remove_all(tmpdir);
40 }
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080041
Yukai Tuccdcdba2016-10-24 13:48:01 -070042 SyncLog db(tmpdir, Name("/lijing"));
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080043
Yukai Tuccdcdba2016-10-24 13:48:01 -070044 ndn::ConstBufferPtr hash = db.RememberStateInStateLog();
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080045 // should be empty
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080046
Yukai Tuccdcdba2016-10-24 13:48:01 -070047 BOOST_CHECK_EQUAL(toHex(*hash),
48 "94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26");
49
50 db.UpdateDeviceSeqNo(Name("/lijing"), 1);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080051 hash = db.RememberStateInStateLog();
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080052
Yukai Tuccdcdba2016-10-24 13:48:01 -070053 BOOST_CHECK_EQUAL(toHex(*hash),
54 "91A849EEDE75ACD56AE1BCB99E92D8FB28757683BC387DBB0E59C3108FCF4F18");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080055
Yukai Tuccdcdba2016-10-24 13:48:01 -070056 db.UpdateDeviceSeqNo(Name("/lijing"), 2);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080057 hash = db.RememberStateInStateLog();
Yukai Tuccdcdba2016-10-24 13:48:01 -070058 BOOST_CHECK_EQUAL(toHex(*hash),
59 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080060
Yukai Tuccdcdba2016-10-24 13:48:01 -070061 db.UpdateDeviceSeqNo(Name("/lijing"), 2);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080062 hash = db.RememberStateInStateLog();
Yukai Tuccdcdba2016-10-24 13:48:01 -070063 BOOST_CHECK_EQUAL(toHex(*hash),
64 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080065
Yukai Tuccdcdba2016-10-24 13:48:01 -070066 db.UpdateDeviceSeqNo(Name("/lijing"), 1);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080067 hash = db.RememberStateInStateLog();
Yukai Tuccdcdba2016-10-24 13:48:01 -070068 BOOST_CHECK_EQUAL(toHex(*hash),
69 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080070
Yukai Tuccdcdba2016-10-24 13:48:01 -070071 db.UpdateLocator(Name("/lijing"), Name("/hawaii"));
Zhenkai Zhu6e7d4d22013-01-15 18:18:18 -080072
Yukai Tuccdcdba2016-10-24 13:48:01 -070073 BOOST_CHECK_EQUAL(db.LookupLocator(Name("/lijing")), Name("/hawaii"));
Zhenkai Zhu6e7d4d22013-01-15 18:18:18 -080074
Yukai Tuccdcdba2016-10-24 13:48:01 -070075 SyncStateMsgPtr msg = db.FindStateDifferences("00", "95284D3132A7A88B85C5141CA63EFA68B7A7DAF37315DEF69E296A0C24692833");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080076 BOOST_CHECK_EQUAL(msg->state_size(), 0);
Alexander Afanasyev5ec5a8f2013-01-17 17:30:33 -080077
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080078 msg = db.FindStateDifferences("00",
Yukai Tuccdcdba2016-10-24 13:48:01 -070079 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080080 BOOST_CHECK_EQUAL(msg->state_size(), 1);
81 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE);
82 BOOST_CHECK_EQUAL(msg->state(0).seq(), 2);
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080083
Yukai Tuccdcdba2016-10-24 13:48:01 -070084 msg = db.FindStateDifferences("D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282",
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080085 "00");
86 BOOST_CHECK_EQUAL(msg->state_size(), 1);
87 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::DELETE);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080088
Yukai Tuccdcdba2016-10-24 13:48:01 -070089 msg = db.FindStateDifferences("94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26",
90 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080091 BOOST_CHECK_EQUAL(msg->state_size(), 1);
92 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE);
93 BOOST_CHECK_EQUAL(msg->state(0).seq(), 2);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080094
Yukai Tuccdcdba2016-10-24 13:48:01 -070095 msg = db.FindStateDifferences("D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282",
96 "94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080097 BOOST_CHECK_EQUAL(msg->state_size(), 1);
98 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE);
99 BOOST_CHECK_EQUAL(msg->state(0).seq(), 0);
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -0800100
Yukai Tuccdcdba2016-10-24 13:48:01 -0700101 db.UpdateDeviceSeqNo(Name("/shuai"), 1);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800102 hash = db.RememberStateInStateLog();
Yukai Tuccdcdba2016-10-24 13:48:01 -0700103 BOOST_CHECK_EQUAL(toHex(*hash),
104 "602FF1878FC394B90E4A0E90C7409EA4B8EE8AA40169801D62F838470551DB7C");
Alexander Afanasyev5ec5a8f2013-01-17 17:30:33 -0800105
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800106 msg = db.FindStateDifferences("00",
Yukai Tuccdcdba2016-10-24 13:48:01 -0700107 "602FF1878FC394B90E4A0E90C7409EA4B8EE8AA40169801D62F838470551DB7C");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800108 BOOST_CHECK_EQUAL(msg->state_size(), 2);
109 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE);
110 BOOST_CHECK_EQUAL(msg->state(0).seq(), 2);
Alexander Afanasyev5ec5a8f2013-01-17 17:30:33 -0800111
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800112 BOOST_CHECK_EQUAL(msg->state(1).type(), SyncState::UPDATE);
113 BOOST_CHECK_EQUAL(msg->state(1).seq(), 1);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800114}
115
116BOOST_AUTO_TEST_SUITE_END()
Yukai Tuccdcdba2016-10-24 13:48:01 -0700117
118} // namespace tests
119} // namespace chronoshare
120} // namespace ndn