blob: 7d4eeebfa670c2af75f1f0ade93d6b7e443c3ac7 [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 -070031BOOST_FIXTURE_TEST_SUITE(TestSyncLog, IdentityManagementTimeFixture)
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080032
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080033BOOST_AUTO_TEST_CASE(BasicDatabaseTest)
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080034{
Yukai Tuccdcdba2016-10-24 13:48:01 -070035 fs::path tmpdir = fs::unique_path(UNIT_TEST_CONFIG_PATH);
36 if (exists(tmpdir)) {
37 remove_all(tmpdir);
38 }
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080039
Yukai Tuccdcdba2016-10-24 13:48:01 -070040 SyncLog db(tmpdir, Name("/lijing"));
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080041
Yukai Tuccdcdba2016-10-24 13:48:01 -070042 ndn::ConstBufferPtr hash = db.RememberStateInStateLog();
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080043 // should be empty
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080044
Yukai Tuccdcdba2016-10-24 13:48:01 -070045 BOOST_CHECK_EQUAL(toHex(*hash),
46 "94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26");
47
48 db.UpdateDeviceSeqNo(Name("/lijing"), 1);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080049 hash = db.RememberStateInStateLog();
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080050
Yukai Tuccdcdba2016-10-24 13:48:01 -070051 BOOST_CHECK_EQUAL(toHex(*hash),
52 "91A849EEDE75ACD56AE1BCB99E92D8FB28757683BC387DBB0E59C3108FCF4F18");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080053
Yukai Tuccdcdba2016-10-24 13:48:01 -070054 db.UpdateDeviceSeqNo(Name("/lijing"), 2);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080055 hash = db.RememberStateInStateLog();
Yukai Tuccdcdba2016-10-24 13:48:01 -070056 BOOST_CHECK_EQUAL(toHex(*hash),
57 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080058
Yukai Tuccdcdba2016-10-24 13:48:01 -070059 db.UpdateDeviceSeqNo(Name("/lijing"), 2);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080060 hash = db.RememberStateInStateLog();
Yukai Tuccdcdba2016-10-24 13:48:01 -070061 BOOST_CHECK_EQUAL(toHex(*hash),
62 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080063
Yukai Tuccdcdba2016-10-24 13:48:01 -070064 db.UpdateDeviceSeqNo(Name("/lijing"), 1);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080065 hash = db.RememberStateInStateLog();
Yukai Tuccdcdba2016-10-24 13:48:01 -070066 BOOST_CHECK_EQUAL(toHex(*hash),
67 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080068
Yukai Tuccdcdba2016-10-24 13:48:01 -070069 db.UpdateLocator(Name("/lijing"), Name("/hawaii"));
Zhenkai Zhu6e7d4d22013-01-15 18:18:18 -080070
Yukai Tuccdcdba2016-10-24 13:48:01 -070071 BOOST_CHECK_EQUAL(db.LookupLocator(Name("/lijing")), Name("/hawaii"));
Zhenkai Zhu6e7d4d22013-01-15 18:18:18 -080072
Yukai Tuccdcdba2016-10-24 13:48:01 -070073 SyncStateMsgPtr msg = db.FindStateDifferences("00", "95284D3132A7A88B85C5141CA63EFA68B7A7DAF37315DEF69E296A0C24692833");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080074 BOOST_CHECK_EQUAL(msg->state_size(), 0);
Alexander Afanasyev5ec5a8f2013-01-17 17:30:33 -080075
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080076 msg = db.FindStateDifferences("00",
Yukai Tuccdcdba2016-10-24 13:48:01 -070077 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080078 BOOST_CHECK_EQUAL(msg->state_size(), 1);
79 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE);
80 BOOST_CHECK_EQUAL(msg->state(0).seq(), 2);
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080081
Yukai Tuccdcdba2016-10-24 13:48:01 -070082 msg = db.FindStateDifferences("D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282",
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080083 "00");
84 BOOST_CHECK_EQUAL(msg->state_size(), 1);
85 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::DELETE);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080086
Yukai Tuccdcdba2016-10-24 13:48:01 -070087 msg = db.FindStateDifferences("94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26",
88 "D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080089 BOOST_CHECK_EQUAL(msg->state_size(), 1);
90 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE);
91 BOOST_CHECK_EQUAL(msg->state(0).seq(), 2);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -080092
Yukai Tuccdcdba2016-10-24 13:48:01 -070093 msg = db.FindStateDifferences("D2DFEDA56ED98C0E17D455A859BC8C3B9E31C85C138C280A8BADAB4FC551F282",
94 "94D988A90C6A3D0F74624368BE65E5369DDDDB3444841FAD4EF41F674B937F26");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080095 BOOST_CHECK_EQUAL(msg->state_size(), 1);
96 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE);
97 BOOST_CHECK_EQUAL(msg->state(0).seq(), 0);
Alexander Afanasyev8e2104a2013-01-22 10:56:18 -080098
Yukai Tuccdcdba2016-10-24 13:48:01 -070099 db.UpdateDeviceSeqNo(Name("/shuai"), 1);
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800100 hash = db.RememberStateInStateLog();
Yukai Tuccdcdba2016-10-24 13:48:01 -0700101 BOOST_CHECK_EQUAL(toHex(*hash),
102 "602FF1878FC394B90E4A0E90C7409EA4B8EE8AA40169801D62F838470551DB7C");
Alexander Afanasyev5ec5a8f2013-01-17 17:30:33 -0800103
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800104 msg = db.FindStateDifferences("00",
Yukai Tuccdcdba2016-10-24 13:48:01 -0700105 "602FF1878FC394B90E4A0E90C7409EA4B8EE8AA40169801D62F838470551DB7C");
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800106 BOOST_CHECK_EQUAL(msg->state_size(), 2);
107 BOOST_CHECK_EQUAL(msg->state(0).type(), SyncState::UPDATE);
108 BOOST_CHECK_EQUAL(msg->state(0).seq(), 2);
Alexander Afanasyev5ec5a8f2013-01-17 17:30:33 -0800109
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800110 BOOST_CHECK_EQUAL(msg->state(1).type(), SyncState::UPDATE);
111 BOOST_CHECK_EQUAL(msg->state(1).seq(), 1);
Alexander Afanasyevee7e6132013-01-03 20:03:14 -0800112}
113
114BOOST_AUTO_TEST_SUITE_END()
Yukai Tuccdcdba2016-10-24 13:48:01 -0700115
116} // namespace tests
117} // namespace chronoshare
118} // namespace ndn