Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 136 lines (124 sloc) 7.465 kB
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
1 -module(luwak_tree_tests).
2
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
3 -ifdef(TEST).
4
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
5 -include_lib("eunit/include/eunit.hrl").
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
6 -include("luwak.hrl").
7
8 tree_test_() ->
9 {spawn,
10 [{setup,
11 fun test_helper:setup/0,
12 fun test_helper:cleanup/1,
13 [
14 {timeout, 60000,
15 [fun create_simple_tree/0,
16 fun create_and_overwrite_middle_tree/0,
17 fun create_multilevel_tree/0,
18 fun create_and_overwrite_multilevel_tree/0,
19 fun create_and_append/0,
20 fun append_beyond_pointer/0,
21 fun block_at/0]}
22 ]
23 }
24 ]
25 }.
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
26
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
27 create_simple_tree() ->
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
28 test_helper:riak_test(fun(Riak) ->
29 {ok, File} = luwak_file:create(Riak, <<"file1">>, [{tree_order,4},{block_size,5}], dict:new()),
58654cc @beerriot sanitize test data
beerriot authored
30 {ok, _Written, File2} = luwak_io:put_range(Riak, File, 0, <<"abcdefghijklm">>),
31 BHash1 = <<"751fa004096ddee0b639b37d02fdb2dc68bd4eb7749bb2c17e5edc624d8a9eef4815e4cc1132cc14dfc493d1f46fc1b072653c0bcb3533e1da9676e96a4aeb30">>,
32 BHash2 = <<"86a17f1a92887662099480d4bdd222d7e3372b347a1df276a183e3df5407d68ab44225967c0047f8e1a7c8d854198ac949a3d8f960385c7df4655a9143ad7fa7">>,
33 BHash3 = <<"a472d1328b53ad058a383902e0a4170ad6b202f78fb1b25a5a41c8bb9f4a552f20ffebed176620f84990d2d60c9ecd85513af915e8f25bcb35e77c1b46efed67">>,
34 RootHash = <<"5676ff048bedcf789df26fec4d118241089f71929579f023cbe7a26c620ad242106f91ee7b9f4d5f3c2c305bcbc5ba9c95b2e5d24706c8ab76305a32866e7de8">>,
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
35 Root = luwak_file:get_property(File2, root),
36 ?assertEqual(RootHash, Root),
37 {ok, RootNode} = luwak_tree:get(Riak, Root),
38 Children = RootNode#n.children,
39 ?assertEqual([{BHash1,5},{BHash2,5},{BHash3,3}], Children)
40 end).
41
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
42 create_and_overwrite_middle_tree() ->
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
43 test_helper:riak_test(fun(Riak) ->
44 {ok, File} = luwak_file:create(Riak, <<"file1">>, [{tree_order,4},{block_size,5}], dict:new()),
58654cc @beerriot sanitize test data
beerriot authored
45 {ok, _Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"abcdefghijklm">>),
46 BHash3 = <<"9b0b42ba73433d128142716ec92c0b6193fb5646eb4094aacd0246ac25c109ace790d6c97d08df257407f42a7c1ba8163fc209117a229c0236bc0994fae353a6">>,
47 {ok, _Written2, File3} = luwak_io:put_range(Riak, File2, 1, <<"zyxwvutsrq">>),
48 BHash1_2 = <<"dc9cb02788c70dda88e58b35c301d9824c07466dbc86298145327536524f3baa5e3d9cdbb40642e06c8ed9ce7f097923f39a0d3f38bb24729a0cbe9a4c8f2a01">>,
49 BHash2_2 = <<"6f92ce05db424b6ea3b9bb9ad51d40b311490d5b3a15b8dbe2621e38796885369df197177bea421556dd2ef556301c240fcde02e41352ac9807a530af5a0ea46">>,
50 RootHash2 = <<"14ec341979962a61404a79552754b12fc9faf9e747e1f13d2792ef5d9609b0a406d5fc25952da64eb61a6d99435c27cce4cf85a3d8bbea348bc7215bd8071eee">>,
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
51 Root = luwak_file:get_property(File3, root),
52 ?assertEqual(RootHash2, Root),
53 {ok, RootNode} = luwak_tree:get(Riak, Root),
54 Children = RootNode#n.children,
55 ?assertEqual([{BHash1_2,5},{BHash2_2,5},{BHash3,3}], Children)
56 end).
57
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
58 create_multilevel_tree() ->
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
59 test_helper:riak_test(fun(Riak) ->
60 {ok, File} = luwak_file:create(Riak, <<"file1">>, [{tree_order,5},{block_size,1}], dict:new()),
58654cc @beerriot sanitize test data
beerriot authored
61 {ok, _Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"abcdefghijklm">>),
62 Blocks = [ {skerl:hexhash(512, list_to_binary([C])), 1} || C <- binary_to_list(<<"abcdefghijklm">>) ],
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
63 {FirstNodeChildren, Tail1} = lists:split(5, Blocks),
64 {SecondNodeChildren, ThirdNodeChildren} = lists:split(5, Tail1),
65 Node1 = skerl:hexhash(512, term_to_binary(FirstNodeChildren)),
66 Node2 = skerl:hexhash(512, term_to_binary(SecondNodeChildren)),
67 Node3 = skerl:hexhash(512, term_to_binary(ThirdNodeChildren)),
68 RootChildren = [{Node1,5}, {Node2,5}, {Node3,3}],
69 Root1 = skerl:hexhash(512, term_to_binary(RootChildren)),
70 ?assertEqual(Root1, luwak_file:get_property(File2, root)),
71 {ok, RootNode} = luwak_tree:get(Riak, Root1),
72 ?assertEqual(RootChildren, RootNode#n.children),
73 {ok, Node1Node} = luwak_tree:get(Riak, Node1),
74 {ok, Node2Node} = luwak_tree:get(Riak, Node2),
75 {ok, Node3Node} = luwak_tree:get(Riak, Node3),
76 ?assertEqual(FirstNodeChildren, Node1Node#n.children),
77 ?assertEqual(SecondNodeChildren, Node2Node#n.children),
78 ?assertEqual(ThirdNodeChildren, Node3Node#n.children)
79 end).
80
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
81 create_and_overwrite_multilevel_tree() ->
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
82 test_helper:riak_test(fun(Riak) ->
83 {ok, File} = luwak_file:create(Riak, <<"file1">>, [{tree_order,5},{block_size,1}], dict:new()),
58654cc @beerriot sanitize test data
beerriot authored
84 {ok, _Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"abcdefghijklm">>),
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
85 % ok = file:write_file("tree1.dot", luwak_tree:visualize_tree(Riak, luwak_file:get_property(File2, root))),
58654cc @beerriot sanitize test data
beerriot authored
86 {ok, _Written2, File3} = luwak_io:put_range(Riak, File2, 1, <<"zyxwvutsrq">>),
87 Blocks = [ {skerl:hexhash(512, list_to_binary([C])), 1} || C <- binary_to_list(<<"azyxwvutsrqlm">>) ],
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
88 {FirstNodeChildren, Tail1} = lists:split(5, Blocks),
89 {SecondNodeChildren, ThirdNodeChildren} = lists:split(5, Tail1),
90 Node1 = skerl:hexhash(512, term_to_binary(FirstNodeChildren)),
91 Node2 = skerl:hexhash(512, term_to_binary(SecondNodeChildren)),
92 Node3 = skerl:hexhash(512, term_to_binary(ThirdNodeChildren)),
93 RootChildren = [{Node1,5}, {Node2,5}, {Node3,3}],
94 Root1 = skerl:hexhash(512, term_to_binary(RootChildren)),
95 ok = file:write_file("tree2.dot", luwak_tree:visualize_tree(Riak, luwak_file:get_property(File3, root))),
96 ?assertEqual(Root1, luwak_file:get_property(File3, root)),
97 {ok, RootNode} = luwak_tree:get(Riak, Root1),
98 ?assertEqual(RootChildren, RootNode#n.children),
99 {ok, Node1Node} = luwak_tree:get(Riak, Node1),
100 {ok, Node2Node} = luwak_tree:get(Riak, Node2),
101 {ok, Node3Node} = luwak_tree:get(Riak, Node3),
102 ?assertEqual(FirstNodeChildren, Node1Node#n.children),
103 ?assertEqual(SecondNodeChildren, Node2Node#n.children),
104 ?assertEqual(ThirdNodeChildren, Node3Node#n.children)
105 end).
106
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
107 create_and_append() ->
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
108 test_helper:riak_test(fun(Riak) ->
109 {ok, File} = luwak_file:create(Riak, <<"file1">>, [{tree_order,3},{block_size,2}], dict:new()),
58654cc @beerriot sanitize test data
beerriot authored
110 {ok, _Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"abcdefghijklm">>),
111 {ok, _Written2, File3} = luwak_io:put_range(Riak, File2, 13, <<"nopqrstuvwxyz">>),
112 _Blocks = [ {skerl:hexhash(512, X), 2} || <<X:2/binary>> <= <<"abcdefghijklmnopqrstuvwxyz">> ],
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
113 ok = file:write_file("tree3.dot", luwak_tree:visualize_tree(Riak, luwak_file:get_property(File3, root))),
58654cc @beerriot sanitize test data
beerriot authored
114 ?assertEqual(<<"abcdefghijklmnopqrstuvwxyz">>, iolist_to_binary(luwak_io:get_range(Riak, File3, 0, 26)))
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
115 end).
116
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
117 append_beyond_pointer() ->
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
118 test_helper:riak_test(fun(Riak) ->
119 {ok, File} = luwak_file:create(Riak, <<"file1">>, [{tree_order,3},{block_size,2}], dict:new()),
58654cc @beerriot sanitize test data
beerriot authored
120 {ok, _Written1, File2} = luwak_io:put_range(Riak, File, 0, <<"abcdefghijklm">>),
121 {ok, _Written2, File3} = luwak_io:put_range(Riak, File2, 15, <<"nopqrstuvwxyz">>),
122 ?assertEqual(<<"abcdefghijklmnopqrstuvwxyz">>, iolist_to_binary(luwak_io:get_range(Riak, File3, 0, 26)))
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
123 end).
124
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
125 block_at() ->
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
126 test_helper:riak_test(fun(Riak) ->
127 {ok, File} = luwak_file:create(Riak, <<"file1">>, [{tree_order,3},{block_size,3}], dict:new()),
58654cc @beerriot sanitize test data
beerriot authored
128 {ok, _Written1, File1} = luwak_io:put_range(Riak, File, 0, <<"abcdefghijklmno">>),
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
129 {ok, Block} = luwak_tree:block_at(Riak, File1, 9),
130 Data = luwak_block:data(Block),
131 timer:sleep(1000),
58654cc @beerriot sanitize test data
beerriot authored
132 ?assertEqual(<<"jkl">>, Data)
0e1ce83 @rzezeski reinstate luwak_tree_tests
rzezeski authored
133 end).
0314547 @kellymclaughlin Refactor luwak tests to group the tests into test suites to avoid
kellymclaughlin authored
134
135 -endif.
Something went wrong with that request. Please try again.