071-fs_actor.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. // SPDX-FileCopyrightText: 2019-2024 Ivan Baidakou
  3. #include "test-utils.h"
  4. #include "fs/file_actor.h"
  5. #include "fs/utils.h"
  6. #include "diff-builder.h"
  7. #include "net/messages.h"
  8. #include "test_supervisor.h"
  9. #include "access.h"
  10. #include "model/cluster.h"
  11. #include "access.h"
  12. #include <boost/filesystem.hpp>
  13. using namespace syncspirit;
  14. using namespace syncspirit::db;
  15. using namespace syncspirit::test;
  16. using namespace syncspirit::model;
  17. using namespace syncspirit::net;
  18. namespace bfs = boost::filesystem;
  19. namespace {
  20. struct fixture_t {
  21. using msg_t = net::message::load_cluster_response_t;
  22. using msg_ptr_t = r::intrusive_ptr_t<msg_t>;
  23. using blk_res_t = fs::message::block_response_t;
  24. using blk_res_ptr_t = r::intrusive_ptr_t<blk_res_t>;
  25. fixture_t() noexcept : root_path{bfs::unique_path()}, path_guard{root_path} {
  26. utils::set_default("trace");
  27. bfs::create_directory(root_path);
  28. sequencer = make_sequencer(67);
  29. }
  30. virtual supervisor_t::configure_callback_t configure() noexcept {
  31. return [&](r::plugin::plugin_base_t &plugin) {
  32. plugin.template with_casted<r::plugin::starter_plugin_t>([&](auto &p) {
  33. p.subscribe_actor(r::lambda<msg_t>([&](msg_t &msg) { reply = &msg; }));
  34. p.subscribe_actor(r::lambda<blk_res_t>([&](blk_res_t &msg) { block_reply = &msg; }));
  35. });
  36. };
  37. }
  38. virtual void run() noexcept {
  39. auto my_id =
  40. device_id_t::from_string("KHQNO2S-5QSILRK-YX4JZZ4-7L77APM-QNVGZJT-EKU7IFI-PNEPBMY-4MXFMQD").value();
  41. my_device = device_t::create(my_id, "my-device").value();
  42. cluster = new cluster_t(my_device, 1);
  43. auto peer_id =
  44. device_id_t::from_string("VUV42CZ-IQD5A37-RPEBPM4-VVQK6E4-6WSKC7B-PVJQHHD-4PZD44V-ENC6WAZ").value();
  45. peer_device = device_t::create(peer_id, "peer-device").value();
  46. cluster->get_devices().put(my_device);
  47. cluster->get_devices().put(peer_device);
  48. r::system_context_t ctx;
  49. sup = ctx.create_supervisor<supervisor_t>().auto_finish(false).timeout(timeout).create_registry().finish();
  50. sup->cluster = cluster;
  51. sup->configure_callback = configure();
  52. sup->start();
  53. sup->do_process();
  54. CHECK(static_cast<r::actor_base_t *>(sup.get())->access<to::state>() == r::state_t::OPERATIONAL);
  55. auto sha256 = peer_device->device_id().get_sha256();
  56. file_actor = sup->create_actor<fs::file_actor_t>().mru_size(2).cluster(cluster).timeout(timeout).finish();
  57. sup->do_process();
  58. CHECK(static_cast<r::actor_base_t *>(file_actor.get())->access<to::state>() == r::state_t::OPERATIONAL);
  59. file_addr = file_actor->get_address();
  60. auto builder = diff_builder_t(*cluster);
  61. builder.upsert_folder(folder_id, root_path.string(), "my-label")
  62. .apply(*sup)
  63. .update_peer(peer_device->device_id(), "some_name", "some-cn", true)
  64. .apply(*sup)
  65. .share_folder(sha256, folder_id)
  66. .apply(*sup);
  67. folder = cluster->get_folders().by_id(folder_id);
  68. folder_my = folder->get_folder_infos().by_device(*my_device);
  69. folder_peer = folder->get_folder_infos().by_device(*peer_device);
  70. main();
  71. reply.reset();
  72. sup->shutdown();
  73. sup->do_process();
  74. CHECK(static_cast<r::actor_base_t *>(sup.get())->access<to::state>() == r::state_t::SHUT_DOWN);
  75. }
  76. virtual void main() noexcept {}
  77. r::address_ptr_t file_addr;
  78. r::pt::time_duration timeout = r::pt::millisec{10};
  79. cluster_ptr_t cluster;
  80. model::sequencer_ptr_t sequencer;
  81. model::device_ptr_t peer_device;
  82. model::device_ptr_t my_device;
  83. model::folder_ptr_t folder;
  84. model::folder_info_ptr_t folder_my;
  85. model::folder_info_ptr_t folder_peer;
  86. r::intrusive_ptr_t<supervisor_t> sup;
  87. r::intrusive_ptr_t<fs::file_actor_t> file_actor;
  88. bfs::path root_path;
  89. path_guard_t path_guard;
  90. r::system_context_t ctx;
  91. msg_ptr_t reply;
  92. blk_res_ptr_t block_reply;
  93. std::string_view folder_id = "1234-5678";
  94. };
  95. } // namespace
  96. void test_clone_file() {
  97. struct F : fixture_t {
  98. void main() noexcept override {
  99. proto::FileInfo pr_fi;
  100. std::int64_t modified = 1641828421;
  101. pr_fi.set_name("q.txt");
  102. pr_fi.set_modified_s(modified);
  103. auto version = pr_fi.mutable_version();
  104. auto counter = version->add_counters();
  105. counter->set_id(1);
  106. counter->set_value(peer_device->as_uint());
  107. auto make_file = [&]() {
  108. auto file = file_info_t::create(sequencer->next_uuid(), pr_fi, folder_peer).value();
  109. folder_peer->add(file, false);
  110. return file;
  111. };
  112. SECTION("empty regular file") {
  113. auto peer_file = make_file();
  114. diff_builder_t(*cluster).clone_file(*peer_file).apply(*sup);
  115. auto my_file = folder_my->get_file_infos().by_name(peer_file->get_name());
  116. auto &path = my_file->get_path();
  117. REQUIRE(bfs::exists(path));
  118. REQUIRE(bfs::file_size(path) == 0);
  119. REQUIRE(bfs::last_write_time(path) == 1641828421);
  120. }
  121. SECTION("empty regular file a subdir") {
  122. pr_fi.set_name("a/b/c/d/e.txt");
  123. auto peer_file = make_file();
  124. diff_builder_t(*cluster).clone_file(*peer_file).apply(*sup);
  125. auto file = folder_my->get_file_infos().by_name(pr_fi.name());
  126. auto &path = file->get_path();
  127. REQUIRE(bfs::exists(path));
  128. REQUIRE(bfs::file_size(path) == 0);
  129. }
  130. SECTION("non-empty regular file") {
  131. pr_fi.set_size(5);
  132. pr_fi.set_block_size(5);
  133. auto b = proto::BlockInfo();
  134. b.set_hash(utils::sha256_digest("12345").value());
  135. b.set_weak_hash(555);
  136. b.set_size(5ul);
  137. auto bi = block_info_t::create(b).value();
  138. auto &blocks_map = cluster->get_blocks();
  139. blocks_map.put(bi);
  140. auto peer_file = make_file();
  141. peer_file->assign_block(bi, 0);
  142. diff_builder_t(*cluster).clone_file(*peer_file).apply(*sup);
  143. auto file = folder_my->get_file_infos().by_name(pr_fi.name());
  144. auto filename = std::string(file->get_name()) + ".syncspirit-tmp";
  145. auto path = root_path / filename;
  146. REQUIRE(bfs::exists(path));
  147. REQUIRE(bfs::file_size(path) == 5);
  148. }
  149. SECTION("directory") {
  150. pr_fi.set_type(proto::FileInfoType::DIRECTORY);
  151. auto peer_file = make_file();
  152. diff_builder_t(*cluster).clone_file(*peer_file).apply(*sup);
  153. auto file = folder_my->get_file_infos().by_name(pr_fi.name());
  154. auto &path = file->get_path();
  155. REQUIRE(bfs::exists(path));
  156. REQUIRE(bfs::is_directory(path));
  157. }
  158. #ifndef SYNCSPIRIT_WIN
  159. SECTION("symlink") {
  160. bfs::path target = root_path / "some-existing-file";
  161. write_file(target, "zzz");
  162. pr_fi.set_type(proto::FileInfoType::SYMLINK);
  163. pr_fi.set_symlink_target(target.string());
  164. auto peer_file = make_file();
  165. diff_builder_t(*cluster).clone_file(*peer_file).apply(*sup);
  166. auto file = folder_my->get_file_infos().by_name(pr_fi.name());
  167. auto &path = file->get_path();
  168. CHECK(!bfs::exists(path));
  169. CHECK(bfs::is_symlink(path));
  170. CHECK(bfs::read_symlink(path) == target);
  171. }
  172. #endif
  173. SECTION("deleted file") {
  174. pr_fi.set_deleted(true);
  175. bfs::path target = root_path / pr_fi.name();
  176. write_file(target, "zzz");
  177. REQUIRE(bfs::exists(target));
  178. auto peer_file = make_file();
  179. diff_builder_t(*cluster).clone_file(*peer_file).apply(*sup);
  180. auto file = folder_my->get_file_infos().by_name(pr_fi.name());
  181. CHECK(file->is_deleted());
  182. REQUIRE(!bfs::exists(target));
  183. }
  184. }
  185. };
  186. F().run();
  187. }
  188. void test_append_block() {
  189. struct F : fixture_t {
  190. void main() noexcept override {
  191. std::int64_t modified = 1641828421;
  192. proto::FileInfo pr_source;
  193. pr_source.set_name("q.txt");
  194. pr_source.set_block_size(5ul);
  195. pr_source.set_modified_s(modified);
  196. auto version = pr_source.mutable_version();
  197. auto counter = version->add_counters();
  198. counter->set_id(1);
  199. counter->set_value(peer_device->as_uint());
  200. auto bi = proto::BlockInfo();
  201. bi.set_size(5);
  202. bi.set_weak_hash(12);
  203. bi.set_hash(utils::sha256_digest("12345").value());
  204. bi.set_offset(0);
  205. auto b = block_info_t::create(bi).value();
  206. auto bi2 = proto::BlockInfo();
  207. bi2.set_size(5);
  208. bi2.set_weak_hash(12);
  209. bi2.set_hash(utils::sha256_digest("67890").value());
  210. bi2.set_offset(0);
  211. auto b2 = block_info_t::create(bi2).value();
  212. cluster->get_blocks().put(b);
  213. cluster->get_blocks().put(b2);
  214. auto blocks = std::vector<block_info_ptr_t>{b, b2};
  215. auto make_file = [&](size_t count) {
  216. auto file = file_info_t::create(sequencer->next_uuid(), pr_source, folder_peer).value();
  217. for (size_t i = 0; i < count; ++i) {
  218. file->assign_block(blocks[i], i);
  219. }
  220. folder_peer->add(file, false);
  221. return file;
  222. };
  223. auto builder = diff_builder_t(*cluster);
  224. auto callback = [&](diff::modify::block_transaction_t &diff) {
  225. REQUIRE(diff.errors.load() == 0);
  226. builder.ack_block(diff);
  227. };
  228. SECTION("file with 1 block") {
  229. pr_source.set_size(5ul);
  230. auto peer_file = make_file(1);
  231. builder.clone_file(*peer_file).apply(*sup);
  232. auto file = folder_my->get_file_infos().by_name(pr_source.name());
  233. builder.append_block(*peer_file, 0, "12345", callback)
  234. .apply(*sup)
  235. .finish_file(*peer_file->local_file())
  236. .apply(*sup);
  237. auto path = root_path / std::string(file->get_name());
  238. REQUIRE(bfs::exists(path));
  239. REQUIRE(bfs::file_size(path) == 5);
  240. auto data = read_file(path);
  241. CHECK(data == "12345");
  242. CHECK(bfs::last_write_time(path) == 1641828421);
  243. }
  244. SECTION("file with 2 different blocks") {
  245. pr_source.set_size(10ul);
  246. auto peer_file = make_file(2);
  247. builder.clone_file(*peer_file).apply(*sup);
  248. auto file = folder_my->get_file_infos().by_name(pr_source.name());
  249. builder.append_block(*peer_file, 0, "12345", callback).apply(*sup);
  250. auto filename = std::string(file->get_name()) + ".syncspirit-tmp";
  251. auto path = root_path / filename;
  252. #ifndef SYNCSPIRIT_WIN
  253. REQUIRE(bfs::exists(path));
  254. REQUIRE(bfs::file_size(path) == 10);
  255. auto data = read_file(path);
  256. CHECK(data.substr(0, 5) == "12345");
  257. #endif
  258. builder.append_block(*peer_file, 1, "67890", callback).apply(*sup);
  259. SECTION("add 2nd block") {
  260. builder.finish_file(*peer_file->local_file()).apply(*sup);
  261. filename = std::string(file->get_name());
  262. path = root_path / filename;
  263. REQUIRE(bfs::exists(path));
  264. REQUIRE(bfs::file_size(path) == 10);
  265. auto data = read_file(path);
  266. CHECK(data == "1234567890");
  267. CHECK(bfs::last_write_time(path) == 1641828421);
  268. }
  269. #ifndef SYNCSPIRIT_WIN
  270. SECTION("remove folder (simulate err)") {
  271. bfs::remove_all(root_path);
  272. diff_builder_t(*cluster).finish_file(*peer_file->local_file()).apply(*sup);
  273. CHECK(static_cast<r::actor_base_t *>(file_actor.get())->access<to::state>() ==
  274. r::state_t::SHUT_DOWN);
  275. }
  276. #endif
  277. }
  278. }
  279. };
  280. F().run();
  281. }
  282. void test_clone_block() {
  283. struct F : fixture_t {
  284. void main() noexcept override {
  285. auto bi = proto::BlockInfo();
  286. bi.set_size(5);
  287. bi.set_weak_hash(12);
  288. bi.set_hash(utils::sha256_digest("12345").value());
  289. bi.set_offset(0);
  290. auto b = block_info_t::create(bi).value();
  291. auto bi2 = proto::BlockInfo();
  292. bi2.set_size(5);
  293. bi2.set_weak_hash(12);
  294. bi2.set_hash(utils::sha256_digest("67890").value());
  295. bi2.set_offset(0);
  296. auto b2 = block_info_t::create(bi2).value();
  297. cluster->get_blocks().put(b);
  298. cluster->get_blocks().put(b2);
  299. auto blocks = std::vector<block_info_ptr_t>{b, b2};
  300. std::int64_t modified = 1641828421;
  301. proto::FileInfo pr_source;
  302. pr_source.set_name("a.txt");
  303. pr_source.set_block_size(5ul);
  304. pr_source.set_modified_s(modified);
  305. auto version = pr_source.mutable_version();
  306. auto counter = version->add_counters();
  307. counter->set_id(1);
  308. counter->set_value(peer_device->as_uint());
  309. auto make_file = [&](const proto::FileInfo &fi, size_t count) {
  310. auto file = file_info_t::create(sequencer->next_uuid(), fi, folder_peer).value();
  311. for (size_t i = 0; i < count; ++i) {
  312. file->assign_block(blocks[i], i);
  313. }
  314. folder_peer->add(file, false);
  315. return file;
  316. };
  317. auto builder = diff_builder_t(*cluster);
  318. auto callback = [&](diff::modify::block_transaction_t &diff) {
  319. REQUIRE(diff.errors.load() == 0);
  320. builder.ack_block(diff);
  321. };
  322. SECTION("source & target are different files") {
  323. proto::FileInfo pr_target;
  324. pr_target.set_name("b.txt");
  325. pr_target.set_block_size(5ul);
  326. (*pr_target.mutable_version()) = *version;
  327. SECTION("single block target file") {
  328. pr_source.set_size(5ul);
  329. pr_target.set_size(5ul);
  330. pr_target.set_modified_s(modified);
  331. auto source = make_file(pr_source, 1);
  332. auto target = make_file(pr_target, 1);
  333. builder.clone_file(*source).clone_file(*target).apply(*sup);
  334. auto source_file = folder_peer->get_file_infos().by_name(pr_source.name());
  335. auto target_file = folder_peer->get_file_infos().by_name(pr_target.name());
  336. builder.append_block(*source_file, 0, "12345", callback)
  337. .apply(*sup)
  338. .finish_file(*source_file->local_file())
  339. .apply(*sup);
  340. auto block = source_file->get_blocks()[0];
  341. auto file_block = model::file_block_t(block.get(), target_file.get(), 0);
  342. builder.clone_block(file_block, callback)
  343. .apply(*sup)
  344. .finish_file(*target->local_file())
  345. .apply(*sup);
  346. auto path = root_path / std::string(target_file->get_name());
  347. REQUIRE(bfs::exists(path));
  348. REQUIRE(bfs::file_size(path) == 5);
  349. auto data = read_file(path);
  350. CHECK(data == "12345");
  351. CHECK(bfs::last_write_time(path) == 1641828421);
  352. }
  353. SECTION("multi block target file") {
  354. pr_source.set_size(10ul);
  355. pr_target.set_size(10ul);
  356. auto source = make_file(pr_source, 2);
  357. auto target = make_file(pr_target, 2);
  358. builder.clone_file(*source).clone_file(*target).apply(*sup);
  359. auto source_file = folder_peer->get_file_infos().by_name(pr_source.name());
  360. auto target_file = folder_peer->get_file_infos().by_name(pr_target.name());
  361. builder.append_block(*source_file, 0, "12345", callback)
  362. .append_block(*source_file, 1, "67890", callback)
  363. .apply(*sup);
  364. auto blocks = source_file->get_blocks();
  365. auto fb_1 = model::file_block_t(blocks[0].get(), target_file.get(), 0);
  366. auto fb_2 = model::file_block_t(blocks[1].get(), target_file.get(), 1);
  367. builder.clone_block(fb_1, callback)
  368. .clone_block(fb_2, callback)
  369. .apply(*sup)
  370. .finish_file(*target->local_file())
  371. .apply(*sup);
  372. auto filename = std::string(target_file->get_name());
  373. auto path = root_path / filename;
  374. REQUIRE(bfs::exists(path));
  375. REQUIRE(bfs::file_size(path) == 10);
  376. auto data = read_file(path);
  377. CHECK(data == "1234567890");
  378. }
  379. SECTION("source/target different sizes") {
  380. pr_source.set_size(5ul);
  381. pr_target.set_size(10ul);
  382. auto target = make_file(pr_target, 2);
  383. auto source = file_info_t::create(sequencer->next_uuid(), pr_source, folder_peer).value();
  384. source->assign_block(blocks[1], 0);
  385. folder_peer->add(source, false);
  386. builder.clone_file(*source).clone_file(*target).apply(*sup);
  387. auto source_file = folder_peer->get_file_infos().by_name(pr_source.name());
  388. auto target_file = folder_peer->get_file_infos().by_name(pr_target.name());
  389. builder.append_block(*source_file, 0, "67890", callback)
  390. .append_block(*target_file, 0, "12345", callback)
  391. .apply(*sup);
  392. auto blocks = source_file->get_blocks();
  393. auto fb = model::file_block_t(blocks[0].get(), target_file.get(), 1);
  394. builder.clone_block(fb, callback).apply(*sup).finish_file(*target->local_file()).apply(*sup);
  395. auto filename = std::string(target_file->get_name());
  396. auto path = root_path / filename;
  397. REQUIRE(bfs::exists(path));
  398. REQUIRE(bfs::file_size(path) == 10);
  399. auto data = read_file(path);
  400. CHECK(data == "1234567890");
  401. }
  402. }
  403. SECTION("source & target are is the same file") {
  404. pr_source.set_size(10ul);
  405. auto source = file_info_t::create(sequencer->next_uuid(), pr_source, folder_peer).value();
  406. source->assign_block(blocks[0], 0);
  407. source->assign_block(blocks[0], 1);
  408. folder_peer->add(source, false);
  409. builder.clone_file(*source).apply(*sup);
  410. auto source_file = folder_peer->get_file_infos().by_name(pr_source.name());
  411. auto target_file = source_file;
  412. builder.append_block(*source_file, 0, "12345", callback).apply(*sup);
  413. auto block = source_file->get_blocks()[0];
  414. auto file_block = model::file_block_t(block.get(), target_file.get(), 1);
  415. builder.clone_block(file_block, callback).apply(*sup).finish_file(*source->local_file()).apply(*sup);
  416. auto path = root_path / std::string(target_file->get_name());
  417. REQUIRE(bfs::exists(path));
  418. REQUIRE(bfs::file_size(path) == 10);
  419. auto data = read_file(path);
  420. CHECK(data == "1234512345");
  421. CHECK(bfs::last_write_time(path) == 1641828421);
  422. }
  423. }
  424. };
  425. F().run();
  426. }
  427. void test_requesting_block() {
  428. struct F : fixture_t {
  429. void main() noexcept override {
  430. auto bi = proto::BlockInfo();
  431. bi.set_size(5);
  432. bi.set_weak_hash(12);
  433. bi.set_hash(utils::sha256_digest("12345").value());
  434. bi.set_offset(0);
  435. auto b = block_info_t::create(bi).value();
  436. auto bi2 = proto::BlockInfo();
  437. bi2.set_size(5);
  438. bi2.set_weak_hash(12);
  439. bi2.set_hash(utils::sha256_digest("67890").value());
  440. bi2.set_offset(0);
  441. auto b2 = block_info_t::create(bi2).value();
  442. cluster->get_blocks().put(b);
  443. cluster->get_blocks().put(b2);
  444. bfs::path target = root_path / "a.txt";
  445. std::int64_t modified = 1641828421;
  446. proto::FileInfo pr_source;
  447. pr_source.set_name("a.txt");
  448. pr_source.set_block_size(5ul);
  449. pr_source.set_modified_s(modified);
  450. pr_source.set_size(10);
  451. auto version = pr_source.mutable_version();
  452. auto counter = version->add_counters();
  453. counter->set_id(1);
  454. counter->set_value(my_device->as_uint());
  455. *pr_source.add_blocks() = bi;
  456. *pr_source.add_blocks() = bi2;
  457. auto file = file_info_t::create(sequencer->next_uuid(), pr_source, folder_my).value();
  458. file->assign_block(b, 0);
  459. file->assign_block(b2, 1);
  460. folder_my->add(file, false);
  461. auto req = proto::Request();
  462. req.set_folder(std::string(folder->get_id()));
  463. req.set_name("a.txt");
  464. req.set_offset(0);
  465. req.set_size(5);
  466. auto req_ptr = proto::message::Request(new proto::Request(req));
  467. auto msg = r::make_message<fs::payload::block_request_t>(file_actor->get_address(), std::move(req_ptr),
  468. sup->get_address());
  469. SECTION("error, no file") {
  470. sup->put(msg);
  471. sup->do_process();
  472. REQUIRE(block_reply);
  473. REQUIRE(block_reply->payload.remote_request);
  474. REQUIRE(block_reply->payload.ec);
  475. REQUIRE(block_reply->payload.data.empty());
  476. }
  477. SECTION("error, oversized request") {
  478. write_file(target, "1234");
  479. sup->put(msg);
  480. sup->do_process();
  481. REQUIRE(block_reply);
  482. REQUIRE(block_reply->payload.remote_request);
  483. REQUIRE(block_reply->payload.ec);
  484. REQUIRE(block_reply->payload.data.empty());
  485. }
  486. SECTION("successful file reading") {
  487. write_file(target, "1234567890");
  488. sup->put(msg);
  489. sup->do_process();
  490. REQUIRE(block_reply);
  491. REQUIRE(block_reply->payload.remote_request);
  492. REQUIRE(!block_reply->payload.ec);
  493. REQUIRE(block_reply->payload.data == "12345");
  494. req.set_offset(5);
  495. auto req_ptr = proto::message::Request(new proto::Request(req));
  496. auto msg = r::make_message<fs::payload::block_request_t>(file_actor->get_address(), std::move(req_ptr),
  497. sup->get_address());
  498. sup->put(msg);
  499. sup->do_process();
  500. REQUIRE(block_reply);
  501. REQUIRE(block_reply->payload.remote_request);
  502. REQUIRE(!block_reply->payload.ec);
  503. REQUIRE(block_reply->payload.data == "67890");
  504. }
  505. }
  506. };
  507. F().run();
  508. }
  509. int _init() {
  510. REGISTER_TEST_CASE(test_clone_file, "test_clone_file", "[fs]");
  511. REGISTER_TEST_CASE(test_append_block, "test_append_block", "[fs]");
  512. REGISTER_TEST_CASE(test_clone_block, "test_clone_block", "[fs]");
  513. REGISTER_TEST_CASE(test_requesting_block, "test_requesting_block", "[fs]");
  514. return 1;
  515. }
  516. static int v = _init();