End-to-end testing of corrupted bloom
Add a unit test calling the API of a SFT file clerk with a corrupted bloom
This commit is contained in:
parent
05338a1e85
commit
5a36f053d9
1 changed files with 67 additions and 18 deletions
|
@ -822,8 +822,14 @@ write_keys(Handle,
|
||||||
[{LowKey_Slot, SegFilter, LengthList}]),
|
[{LowKey_Slot, SegFilter, LengthList}]),
|
||||||
UpdSlots = <<SerialisedSlots/binary, SerialisedSlot/binary>>,
|
UpdSlots = <<SerialisedSlots/binary, SerialisedSlot/binary>>,
|
||||||
SNExtremes = {min(LSN_Slot, LSN), max(HSN_Slot, HSN)},
|
SNExtremes = {min(LSN_Slot, LSN), max(HSN_Slot, HSN)},
|
||||||
FinalKey = case LastKey_Slot of null -> LastKey; _ -> LastKey_Slot end,
|
FinalKey = case LastKey_Slot of
|
||||||
FirstKey = case LowKey of null -> LowKey_Slot; _ -> LowKey end,
|
null -> LastKey;
|
||||||
|
_ -> LastKey_Slot
|
||||||
|
end,
|
||||||
|
FirstKey = case LowKey of
|
||||||
|
null -> LowKey_Slot;
|
||||||
|
_ -> LowKey
|
||||||
|
end,
|
||||||
case Status of
|
case Status of
|
||||||
partial ->
|
partial ->
|
||||||
UpdHandle = WriteFun(slots , {Handle, UpdSlots}),
|
UpdHandle = WriteFun(slots , {Handle, UpdSlots}),
|
||||||
|
@ -1900,6 +1906,43 @@ key_dominates_test() ->
|
||||||
key_dominates([KV7|KL2], [KV2], {true, 1})).
|
key_dominates([KV7|KL2], [KV2], {true, 1})).
|
||||||
|
|
||||||
|
|
||||||
|
corrupted_sft_test() ->
|
||||||
|
Filename = "../test/bigcorrupttest1.sft",
|
||||||
|
{KL1, KL2} = {lists:ukeysort(1, generate_randomkeys(10000)), []},
|
||||||
|
{InitHandle, InitFileMD} = create_file(Filename),
|
||||||
|
{Handle, _FileMD, _Rems} = complete_file(InitHandle,
|
||||||
|
InitFileMD,
|
||||||
|
KL1, KL2,
|
||||||
|
#level{level=1}),
|
||||||
|
{ok, Lengths} = file:pread(Handle, 12, 12),
|
||||||
|
<<BlocksLength:32/integer,
|
||||||
|
IndexLength:32/integer,
|
||||||
|
FilterLength:32/integer>> = Lengths,
|
||||||
|
ok = file:close(Handle),
|
||||||
|
|
||||||
|
{ok, Corrupter} = file:open(Filename , [binary, raw, read, write]),
|
||||||
|
lists:foreach(fun(X) ->
|
||||||
|
case X * 5 of
|
||||||
|
Y when Y < FilterLength ->
|
||||||
|
Position = ?HEADER_LEN + X * 5
|
||||||
|
+ BlocksLength + IndexLength,
|
||||||
|
file:pwrite(Corrupter,
|
||||||
|
Position,
|
||||||
|
<<0:8/integer>>);
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
lists:seq(1, 100)),
|
||||||
|
ok = file:close(Corrupter),
|
||||||
|
|
||||||
|
{ok, SFTr, _KeyExtremes} = sft_open(Filename),
|
||||||
|
lists:foreach(fun({K, V}) ->
|
||||||
|
?assertMatch({K, V}, sft_get(SFTr, K))
|
||||||
|
end,
|
||||||
|
KL1),
|
||||||
|
ok = sft_clear(SFTr).
|
||||||
|
|
||||||
big_iterator_test() ->
|
big_iterator_test() ->
|
||||||
Filename = "../test/bigtest1.sft",
|
Filename = "../test/bigtest1.sft",
|
||||||
{KL1, KL2} = {lists:sort(generate_randomkeys(10000)), []},
|
{KL1, KL2} = {lists:sort(generate_randomkeys(10000)), []},
|
||||||
|
@ -1907,26 +1950,32 @@ big_iterator_test() ->
|
||||||
{Handle, FileMD, {KL1Rem, KL2Rem}} = complete_file(InitHandle, InitFileMD,
|
{Handle, FileMD, {KL1Rem, KL2Rem}} = complete_file(InitHandle, InitFileMD,
|
||||||
KL1, KL2,
|
KL1, KL2,
|
||||||
#level{level=1}),
|
#level{level=1}),
|
||||||
io:format("Remainder lengths are ~w and ~w ~n", [length(KL1Rem), length(KL2Rem)]),
|
io:format("Remainder lengths are ~w and ~w ~n", [length(KL1Rem),
|
||||||
{complete, Result1} = fetch_range_keysonly(Handle,
|
length(KL2Rem)]),
|
||||||
FileMD,
|
{complete,
|
||||||
{o, "Bucket0000", "Key0000", null},
|
Result1} = fetch_range_keysonly(Handle,
|
||||||
{o, "Bucket9999", "Key9999", null},
|
FileMD,
|
||||||
256),
|
{o, "Bucket0000", "Key0000", null},
|
||||||
|
{o, "Bucket9999", "Key9999", null},
|
||||||
|
256),
|
||||||
NumFoundKeys1 = length(Result1),
|
NumFoundKeys1 = length(Result1),
|
||||||
NumAddedKeys = 10000 - length(KL1Rem),
|
NumAddedKeys = 10000 - length(KL1Rem),
|
||||||
?assertMatch(NumFoundKeys1, NumAddedKeys),
|
?assertMatch(NumFoundKeys1, NumAddedKeys),
|
||||||
{partial, Result2, _} = fetch_range_keysonly(Handle,
|
{partial,
|
||||||
FileMD,
|
Result2,
|
||||||
{o, "Bucket0000", "Key0000", null},
|
_} = fetch_range_keysonly(Handle,
|
||||||
{o, "Bucket9999", "Key9999", null},
|
FileMD,
|
||||||
32),
|
{o, "Bucket0000", "Key0000", null},
|
||||||
|
{o, "Bucket9999", "Key9999", null},
|
||||||
|
32),
|
||||||
?assertMatch(32 * 128, length(Result2)),
|
?assertMatch(32 * 128, length(Result2)),
|
||||||
{partial, Result3, _} = fetch_range_keysonly(Handle,
|
{partial,
|
||||||
FileMD,
|
Result3,
|
||||||
{o, "Bucket0000", "Key0000", null},
|
_} = fetch_range_keysonly(Handle,
|
||||||
{o, "Bucket9999", "Key9999", null},
|
FileMD,
|
||||||
4),
|
{o, "Bucket0000", "Key0000", null},
|
||||||
|
{o, "Bucket9999", "Key9999", null},
|
||||||
|
4),
|
||||||
?assertMatch(4 * 128, length(Result3)),
|
?assertMatch(4 * 128, length(Result3)),
|
||||||
ok = file:close(Handle),
|
ok = file:close(Handle),
|
||||||
ok = file:delete(Filename).
|
ok = file:delete(Filename).
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue