Improve test coverage
Some additional tests following previous refactoring for abstraction, primarily to make manifest print safer an dprove co-existence of Riak and non-Riak objects.
This commit is contained in:
parent
7eb5a16899
commit
ed17e44f52
3 changed files with 71 additions and 16 deletions
|
@ -84,16 +84,32 @@ to_ledgerkey(Bucket, Key, Tag) ->
|
||||||
hash(Obj) ->
|
hash(Obj) ->
|
||||||
erlang:phash2(term_to_binary(Obj)).
|
erlang:phash2(term_to_binary(Obj)).
|
||||||
|
|
||||||
% Return a tuple of string to ease the printing of keys to logs
|
% Return a tuple of strings to ease the printing of keys to logs
|
||||||
print_key(Key) ->
|
print_key(Key) ->
|
||||||
case Key of
|
{A_STR, B_TERM, C_TERM} = case Key of
|
||||||
{o, B, K, _SK} ->
|
{o, B, K, _SK} ->
|
||||||
{"Object", B, K};
|
{"Object", B, K};
|
||||||
{o_rkv@v1, B, K, _SK} ->
|
{o_rkv@v1, B, K, _SK} ->
|
||||||
{"RiakObject", B, K};
|
{"RiakObject", B, K};
|
||||||
{i, B, {F, _V}, _K} ->
|
{i, B, {F, _V}, _K} ->
|
||||||
{"Index", B, F}
|
{"Index", B, F}
|
||||||
|
end,
|
||||||
|
{B_STR, FB} = check_for_string(B_TERM),
|
||||||
|
{C_STR, FC} = check_for_string(C_TERM),
|
||||||
|
{A_STR, B_STR, C_STR, FB, FC}.
|
||||||
|
|
||||||
|
check_for_string(Item) ->
|
||||||
|
if
|
||||||
|
is_binary(Item) == true ->
|
||||||
|
{binary_to_list(Item), "~s"};
|
||||||
|
is_integer(Item) == true ->
|
||||||
|
{integer_to_list(Item), "~s"};
|
||||||
|
is_list(Item) == true ->
|
||||||
|
{Item, "~s"};
|
||||||
|
true ->
|
||||||
|
{Item, "~w"}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
% Compare a key against a query key, only comparing elements that are non-null
|
% Compare a key against a query key, only comparing elements that are non-null
|
||||||
% in the Query key. This is used for comparing against end keys in queries.
|
% in the Query key. This is used for comparing against end keys in queries.
|
||||||
|
@ -208,5 +224,17 @@ indexspecs_test() ->
|
||||||
{1, {active, infinity}, null}}, lists:nth(2, Changes)),
|
{1, {active, infinity}, null}}, lists:nth(2, Changes)),
|
||||||
?assertMatch({{i, "Bucket", {"t1_bin", "abdc456"}, "Key2"},
|
?assertMatch({{i, "Bucket", {"t1_bin", "abdc456"}, "Key2"},
|
||||||
{1, {tomb, infinity}, null}}, lists:nth(3, Changes)).
|
{1, {tomb, infinity}, null}}, lists:nth(3, Changes)).
|
||||||
|
|
||||||
|
endkey_passed_test() ->
|
||||||
|
TestKey = {i, null, null, null},
|
||||||
|
K1 = {i, 123, {"a", "b"}, <<>>},
|
||||||
|
K2 = {o, 123, {"a", "b"}, <<>>},
|
||||||
|
?assertMatch(false, endkey_passed(TestKey, K1)),
|
||||||
|
?assertMatch(true, endkey_passed(TestKey, K2)).
|
||||||
|
|
||||||
|
stringcheck_test() ->
|
||||||
|
?assertMatch({"Bucket", "~s"}, check_for_string("Bucket")),
|
||||||
|
?assertMatch({"Bucket", "~s"}, check_for_string(<<"Bucket">>)),
|
||||||
|
?assertMatch({bucket, "~w"}, check_for_string(bucket)).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
|
@ -1022,15 +1022,18 @@ print_manifest(Manifest) ->
|
||||||
end end,
|
end end,
|
||||||
Level)
|
Level)
|
||||||
end,
|
end,
|
||||||
lists:seq(0, ?MAX_LEVELS - 1)).
|
lists:seq(0, ?MAX_LEVELS - 1)),
|
||||||
|
ok.
|
||||||
|
|
||||||
print_manifest_entry(Entry) ->
|
print_manifest_entry(Entry) ->
|
||||||
{S1, S2, S3} = leveled_codec:print_key(Entry#manifest_entry.start_key),
|
{S1, S2, S3,
|
||||||
{E1, E2, E3} = leveled_codec:print_key(Entry#manifest_entry.end_key),
|
FS2, FS3} = leveled_codec:print_key(Entry#manifest_entry.start_key),
|
||||||
|
{E1, E2, E3,
|
||||||
|
FE2, FE3} = leveled_codec:print_key(Entry#manifest_entry.end_key),
|
||||||
io:format("Manifest entry of " ++
|
io:format("Manifest entry of " ++
|
||||||
"startkey ~s ~s ~s " ++
|
"startkey ~s " ++ FS2 ++ " " ++ FS3 ++
|
||||||
"endkey ~s ~s ~s " ++
|
" endkey ~s " ++ FE2 ++ " " ++ FE3 ++
|
||||||
"filename=~s~n",
|
" filename=~s~n",
|
||||||
[S1, S2, S3, E1, E2, E3,
|
[S1, S2, S3, E1, E2, E3,
|
||||||
Entry#manifest_entry.filename]).
|
Entry#manifest_entry.filename]).
|
||||||
|
|
||||||
|
@ -1667,6 +1670,15 @@ rangequery_manifest_test() ->
|
||||||
Man),
|
Man),
|
||||||
?assertMatch([], R3).
|
?assertMatch([], R3).
|
||||||
|
|
||||||
|
print_manifest_test() ->
|
||||||
|
M1 = #manifest_entry{start_key={i, "Bucket1", {<<"Idx1">>, "Fld1"}, "K8"},
|
||||||
|
end_key={i, 4565, {"Idx1", "Fld9"}, "K93"},
|
||||||
|
filename="Z1"},
|
||||||
|
M2 = #manifest_entry{start_key={i, self(), {null, "Fld1"}, "K8"},
|
||||||
|
end_key={i, <<200:32/integer>>, {"Idx1", "Fld9"}, "K93"},
|
||||||
|
filename="Z1"},
|
||||||
|
?assertMatch(ok, print_manifest([{1, [M1, M2]}])).
|
||||||
|
|
||||||
simple_findnextkey_test() ->
|
simple_findnextkey_test() ->
|
||||||
QueryArray = [
|
QueryArray = [
|
||||||
{2, [{{o, "Bucket1", "Key1"}, {5, {active, infinity}, null}},
|
{2, [{{o, "Bucket1", "Key1"}, {5, {active, infinity}, null}},
|
||||||
|
|
|
@ -12,7 +12,8 @@ all() -> [simple_put_fetch_head,
|
||||||
many_put_fetch_head,
|
many_put_fetch_head,
|
||||||
journal_compaction,
|
journal_compaction,
|
||||||
fetchput_snapshot,
|
fetchput_snapshot,
|
||||||
load_and_count].
|
load_and_count
|
||||||
|
].
|
||||||
|
|
||||||
|
|
||||||
simple_put_fetch_head(_Config) ->
|
simple_put_fetch_head(_Config) ->
|
||||||
|
@ -36,7 +37,21 @@ simple_put_fetch_head(_Config) ->
|
||||||
check_bookie_forlist(Bookie2, ChkList1),
|
check_bookie_forlist(Bookie2, ChkList1),
|
||||||
check_bookie_forobject(Bookie2, TestObject),
|
check_bookie_forobject(Bookie2, TestObject),
|
||||||
check_bookie_formissingobject(Bookie2, "Bucket1", "Key2"),
|
check_bookie_formissingobject(Bookie2, "Bucket1", "Key2"),
|
||||||
|
ok = leveled_bookie:book_put(Bookie2, "Bucket1", "Key2", "Value2",
|
||||||
|
[{add, "Index1", "Term1"}]),
|
||||||
|
{ok, "Value2"} = leveled_bookie:book_get(Bookie2, "Bucket1", "Key2"),
|
||||||
|
{ok, {62888926, 43}} = leveled_bookie:book_head(Bookie2,
|
||||||
|
"Bucket1",
|
||||||
|
"Key2"),
|
||||||
|
check_bookie_formissingobject(Bookie2, "Bucket1", "Key2"),
|
||||||
|
ok = leveled_bookie:book_put(Bookie2, "Bucket1", "Key2", <<"Value2">>,
|
||||||
|
[{remove, "Index1", "Term1"},
|
||||||
|
{add, "Index1", <<"Term2">>}]),
|
||||||
|
{ok, <<"Value2">>} = leveled_bookie:book_get(Bookie2, "Bucket1", "Key2"),
|
||||||
ok = leveled_bookie:book_close(Bookie2),
|
ok = leveled_bookie:book_close(Bookie2),
|
||||||
|
{ok, Bookie3} = leveled_bookie:book_start(StartOpts2),
|
||||||
|
{ok, <<"Value2">>} = leveled_bookie:book_get(Bookie3, "Bucket1", "Key2"),
|
||||||
|
ok = leveled_bookie:book_close(Bookie3),
|
||||||
reset_filestructure().
|
reset_filestructure().
|
||||||
|
|
||||||
many_put_fetch_head(_Config) ->
|
many_put_fetch_head(_Config) ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue