Skip to content

Commit 51c711b

Browse files
committed
test: add sync test case and upgrade elmdb-rs
1 parent 7f9223c commit 51c711b

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
]}.
116116

117117
{deps, [
118-
{elmdb, { git, "https://github.com/twilson63/elmdb-rs.git", {branch, "feat/match" }}},
118+
{elmdb, { git, "https://github.com/twilson63/elmdb-rs.git", {branch, "main" }}},
119119
{b64fast, {git, "https://github.com/ArweaveTeam/b64fast.git", {ref, "58f0502e49bf73b29d95c6d02460d1fb8d2a5273"}}},
120120
{cowboy, {git, "https://github.com/ninenines/cowboy", {tag, "2.13.0"}}},
121121
{gun, {git, "https://github.com/ninenines/gun", {tag, "2.2.0"}}},

rebar.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1},
1515
{<<"elmdb">>,
1616
{git,"https://github.com/twilson63/elmdb-rs.git",
17-
{ref,"90c8857cd4ccff341fbe415b96bc5703d17ff7f0"}},
17+
{branch, main}},
1818
0},
1919
{<<"graphql">>,{pkg,<<"graphql_erl">>,<<"0.17.1">>},0},
2020
{<<"gun">>,{pkg,<<"gun">>,<<"2.2.0">>},0},

src/hb_store.erl

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,11 +559,81 @@ hierarchical_path_resolution_test(Store) ->
559559
hb_store:read(Store, [<<"test-link">>, <<"test-file">>])
560560
).
561561

562+
%% @doc Test the hb_store:sync function by syncing from hb_store_fs to hb_store_lmdb
563+
hb_store_sync_test(_Store) ->
564+
% Generate unique names to avoid conflicts
565+
TestId = integer_to_binary(erlang:system_time(microsecond)),
566+
% Set up FromStore (hb_store_fs) with resolve=false as specified
567+
FromStore = #{
568+
<<"store-module">> => hb_store_fs,
569+
<<"name">> => <<"cache-sync-from-", TestId/binary>>,
570+
<<"resolve">> => false
571+
},
572+
% Set up ToStore (hb_store_lmdb)
573+
ToStore = #{
574+
<<"store-module">> => hb_store_lmdb,
575+
<<"name">> => <<"cache-sync-to-", TestId/binary>>
576+
},
577+
578+
% Clean up any existing data
579+
hb_store:reset(FromStore),
580+
hb_store:reset(ToStore),
581+
582+
% Start both stores
583+
hb_store:start(FromStore),
584+
hb_store:start(ToStore),
585+
586+
% Populate FromStore with directories, files, and links
587+
% Create a directory structure
588+
ok = hb_store:make_group(FromStore, <<"test-dir">>),
589+
ok = hb_store:write(FromStore, <<"test-dir/file1.txt">>, <<"Hello World">>),
590+
ok = hb_store:write(FromStore, <<"test-dir/file2.txt">>, <<"Test Data">>),
591+
592+
% Create a nested directory
593+
ok = hb_store:make_group(FromStore, <<"test-dir/nested">>),
594+
ok = hb_store:write(FromStore, <<"test-dir/nested/deep-file.txt">>, <<"Deep Content">>),
595+
596+
% Create some top-level files
597+
ok = hb_store:write(FromStore, <<"root-file.txt">>, <<"Root Content">>),
598+
599+
% Create a link
600+
ok = hb_store:make_link(FromStore, <<"root-file.txt">>, <<"link-to-root">>),
601+
602+
% Perform the sync operation
603+
Result = hb_store:sync(FromStore, ToStore),
604+
?assertEqual(ok, Result),
605+
606+
% Verify that directories exist in ToStore
607+
?assertEqual(composite, hb_store:type(ToStore, <<"test-dir">>)),
608+
?assertEqual(composite, hb_store:type(ToStore, <<"test-dir/nested">>)),
609+
610+
% Verify that files exist in ToStore
611+
{ok, File1Content} = hb_store:read(ToStore, <<"test-dir/file1.txt">>),
612+
?assertEqual(<<"Hello World">>, File1Content),
613+
614+
{ok, File2Content} = hb_store:read(ToStore, <<"test-dir/file2.txt">>),
615+
?assertEqual(<<"Test Data">>, File2Content),
616+
617+
{ok, DeepContent} = hb_store:read(ToStore, <<"test-dir/nested/deep-file.txt">>),
618+
?assertEqual(<<"Deep Content">>, DeepContent),
619+
620+
{ok, RootContent} = hb_store:read(ToStore, <<"root-file.txt">>),
621+
?assertEqual(<<"Root Content">>, RootContent),
622+
623+
% Verify that links work in ToStore
624+
{ok, LinkContent} = hb_store:read(ToStore, <<"link-to-root">>),
625+
?assertEqual(<<"Root Content">>, LinkContent),
626+
627+
% Clean up
628+
hb_store:stop(FromStore),
629+
hb_store:stop(ToStore).
630+
562631
store_suite_test_() ->
563632
generate_test_suite([
564633
{"simple path resolution", fun simple_path_resolution_test/1},
565634
{"resursive path resolution", fun resursive_path_resolution_test/1},
566-
{"hierarchical path resolution", fun hierarchical_path_resolution_test/1}
635+
{"hierarchical path resolution", fun hierarchical_path_resolution_test/1},
636+
{"hb_store sync", fun hb_store_sync_test/1}
567637
]).
568638

569639
benchmark_suite_test_() ->

0 commit comments

Comments
 (0)