Added a new update method that takes args to pass to the fun.
This commit is contained in:
parent
824ec5ef69
commit
f20e46d756
|
@ -17,7 +17,7 @@
|
||||||
put_r/3, put_r/4,
|
put_r/3, put_r/4,
|
||||||
get/2, get/3,
|
get/2, get/3,
|
||||||
get_r/2, get_r/3,
|
get_r/2, get_r/3,
|
||||||
update/3]).
|
update/3, update/4]).
|
||||||
|
|
||||||
-include("bdberl.hrl").
|
-include("bdberl.hrl").
|
||||||
|
|
||||||
|
@ -167,9 +167,15 @@ get_r(Db, Key, Opts) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
update(Db, Key, Fun) ->
|
update(Db, Key, Fun) ->
|
||||||
|
update(Db, Key, Fun, undefined).
|
||||||
|
|
||||||
|
update(Db, Key, Fun, Args) ->
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
{ok, Value} = get(Db, Key, [rmw]),
|
{ok, Value} = get(Db, Key, [rmw]),
|
||||||
NewValue = Fun(Key, Value),
|
NewValue = case Args of
|
||||||
|
undefined -> Fun(Key, Value);
|
||||||
|
Args -> Fun(Key, Value, Args)
|
||||||
|
end,
|
||||||
ok = put(Db, Key, NewValue),
|
ok = put(Db, Key, NewValue),
|
||||||
NewValue
|
NewValue
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -22,6 +22,7 @@ all() ->
|
||||||
transaction_should_abort_on_exception,
|
transaction_should_abort_on_exception,
|
||||||
transaction_should_abort_on_user_abort,
|
transaction_should_abort_on_user_abort,
|
||||||
update_should_save_value_if_successful,
|
update_should_save_value_if_successful,
|
||||||
|
update_should_accept_args_for_fun,
|
||||||
port_should_tune_transaction_timeouts].
|
port_should_tune_transaction_timeouts].
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,6 +108,17 @@ update_should_save_value_if_successful(Config) ->
|
||||||
{ok, newvalue} = bdberl:update(Db, mykey, F),
|
{ok, newvalue} = bdberl:update(Db, mykey, F),
|
||||||
{ok, newvalue} = bdberl:get(Db, mykey).
|
{ok, newvalue} = bdberl:get(Db, mykey).
|
||||||
|
|
||||||
|
update_should_accept_args_for_fun(Config) ->
|
||||||
|
Db = ?config(db, Config),
|
||||||
|
ok = bdberl:put(Db, mykey, avalue),
|
||||||
|
|
||||||
|
F = fun(_Key, _Value, Args) ->
|
||||||
|
look_at_me = Args, % This is all we are interested in
|
||||||
|
newvalue
|
||||||
|
end,
|
||||||
|
|
||||||
|
{ok, newvalue} = bdberl:update(Db, mykey, F, look_at_me).
|
||||||
|
|
||||||
port_should_tune_transaction_timeouts(_Config) ->
|
port_should_tune_transaction_timeouts(_Config) ->
|
||||||
%% Test transaction timeouts
|
%% Test transaction timeouts
|
||||||
{ok, 500000} = bdberl:get_txn_timeout(),
|
{ok, 500000} = bdberl:get_txn_timeout(),
|
||||||
|
|
Loading…
Reference in a new issue