From c731bf12e1b273bfa0dce4904e8076ba2f876cb0 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Sat, 9 May 2015 15:27:35 -0300 Subject: [PATCH 1/2] [Fix #147] '' --- src/sumo_store_mnesia.erl | 9 ++++++--- test/sumo_basic_SUITE.erl | 10 ++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/sumo_store_mnesia.erl b/src/sumo_store_mnesia.erl index 1c001d4..130ea81 100644 --- a/src/sumo_store_mnesia.erl +++ b/src/sumo_store_mnesia.erl @@ -149,9 +149,12 @@ find_by(DocName, Conditions, [], Limit, Offset, State) -> fun() -> mnesia:select(DocName, MatchSpec) end; Limit -> fun() -> - {ManyItems, _Cont} = - mnesia:select(DocName, MatchSpec, Offset + Limit, read), - lists:sublist(ManyItems, Offset + 1, Limit) + case mnesia:select(DocName, MatchSpec, Offset + Limit, read) of + {ManyItems, _Cont} -> + lists:sublist(ManyItems, Offset + 1, Limit); + '$end_of_table' -> + [] + end end end, case mnesia:transaction(Transaction) of diff --git a/test/sumo_basic_SUITE.erl b/test/sumo_basic_SUITE.erl index ad65643..814c076 100644 --- a/test/sumo_basic_SUITE.erl +++ b/test/sumo_basic_SUITE.erl @@ -8,6 +8,7 @@ ]). -export([ + find/1, find_all/1, find_by/1, delete_all/1, @@ -54,6 +55,9 @@ end_per_suite(Config) -> %%% Exported Tests Functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +find(_Config) -> + run_all_stores(fun find_module/1). + find_all(_Config) -> run_all_stores(fun find_all_module/1). @@ -84,6 +88,12 @@ init_store(Module) -> %% Sync Timeout. sync_timeout(Module). +find_module(Module) -> + [First, Second | _] = sumo:find_all(Module), + First = sumo:find(Module, Module:id(First)), + Second = sumo:find(Module, Module:id(Second)), + notfound = sumo:find(Module, 0). + find_all_module(Module) -> 6 = length(sumo:find_all(Module)). From d7b6f0ca08165e16f7017787e43f63a3dd8193a9 Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Sat, 9 May 2015 15:32:38 -0300 Subject: [PATCH 2/2] [#147] Elvis fix --- src/sumo_store_mnesia.erl | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/sumo_store_mnesia.erl b/src/sumo_store_mnesia.erl index 130ea81..89a65c1 100644 --- a/src/sumo_store_mnesia.erl +++ b/src/sumo_store_mnesia.erl @@ -143,19 +143,20 @@ find_by(DocName, Conditions, Limit, Offset, State) -> sumo_store:result([sumo_internal:doc()], state()). find_by(DocName, Conditions, [], Limit, Offset, State) -> MatchSpec = build_match_spec(DocName, Conditions), + Transaction0 = fun() -> mnesia:select(DocName, MatchSpec) end, + TransactionL = + fun() -> + case mnesia:select(DocName, MatchSpec, Offset + Limit, read) of + {ManyItems, _Cont} -> + lists:sublist(ManyItems, Offset + 1, Limit); + '$end_of_table' -> + [] + end + end, Transaction = case Limit of - 0 -> - fun() -> mnesia:select(DocName, MatchSpec) end; - Limit -> - fun() -> - case mnesia:select(DocName, MatchSpec, Offset + Limit, read) of - {ManyItems, _Cont} -> - lists:sublist(ManyItems, Offset + 1, Limit); - '$end_of_table' -> - [] - end - end + 0 -> Transaction0; + Limit -> TransactionL end, case mnesia:transaction(Transaction) of {aborted, Reason} ->