diff --git a/src/cberl.erl b/src/cberl.erl index 83aa345..9c56ba2 100644 --- a/src/cberl.erl +++ b/src/cberl.erl @@ -344,9 +344,9 @@ query_arg({stale, false}) -> "stale=false"; query_arg({stale, ok}) -> "stale=ok"; query_arg({stale, update_after}) -> "stale=update_after"; -query_arg({start_key, V}) when is_list(V) -> string:join(["start_key", V], "="); +query_arg({startkey, V}) when is_list(V) -> string:join(["startkey", V], "="); -query_arg({startkey_docid, V}) when is_list(V) -> string:join(["start_key", V], "="). +query_arg({startkey_docid, V}) when is_list(V) -> string:join(["startkey_docid", V], "="). view_error(<<"not_found">>) -> not_found; view_error(<<"bad_request">>) -> bad_request; diff --git a/src/cberl_worker.erl b/src/cberl_worker.erl index 6284cdc..7061581 100644 --- a/src/cberl_worker.erl +++ b/src/cberl_worker.erl @@ -14,8 +14,6 @@ terminate/2, code_change/3]). --define(TIMEOUT, infinity). - %%%=================================================================== %%% API %%%=================================================================== @@ -53,7 +51,6 @@ init([{host, Host}, {username, Username}, {password, Password}, receive ok -> {ok, #instance{handle = Handle, transcoder = Transcoder}}; {error, Error} -> {stop, Error} - after ?TIMEOUT -> {error, timeout} end. @@ -76,7 +73,6 @@ handle_call({mtouch, Keys, ExpTimesE}, _From, ok = cberl_nif:control(Handle, op(mtouch), [Keys, ExpTimesE]), receive Reply -> {reply, Reply, State} - after ?TIMEOUT -> {reply, {error, timeout}, State} end; handle_call({unlock, Key, Cas}, _From, State = #instance{handle = Handle}) -> @@ -91,7 +87,6 @@ handle_call({store, Op, Key, Value, TranscoderOpts, Exp, Cas}, _From, Transcoder:flag(TranscoderOpts), Exp, Cas]), receive Reply -> {reply, Reply, State} - after ?TIMEOUT -> {reply, {error, timeout}, State} end; handle_call({mget, Keys, Exp, Lock}, _From, State = #instance{handle = Handle, transcoder = Transcoder}) -> @@ -108,7 +103,6 @@ handle_call({mget, Keys, Exp, Lock}, _From, Result end end, Results) - after ?TIMEOUT -> {error, timeout} end, {reply, Reply, State}; handle_call({arithmetic, Key, OffSet, Exp, Create, Initial}, _From, @@ -119,7 +113,6 @@ handle_call({arithmetic, Key, OffSet, Exp, Create, Initial}, _From, {ok, {Cas, Flag, Value}} -> DecodedValue = Transcoder:decode_value(Flag, Value), {ok, Cas, DecodedValue} - after ?TIMEOUT -> {error, timeout} end, {reply, Reply, State}; handle_call({remove, Key, N}, _From, @@ -127,14 +120,12 @@ handle_call({remove, Key, N}, _From, ok = cberl_nif:control(Handle, op(remove), [Key, N]), receive Reply -> {reply, Reply, State} - after ?TIMEOUT -> {error, timeout} end; handle_call({http, Path, Body, ContentType, Method, Chunked}, _From, State = #instance{handle = Handle}) -> ok = cberl_nif:control(Handle, op(http), [Path, Body, ContentType, Method, Chunked]), receive Reply -> {reply, Reply, State} - after ?TIMEOUT -> {error, timeout} end; handle_call(_Request, _From, State) -> Reply = ok, diff --git a/test/cberl_tests.erl b/test/cberl_tests.erl index 9ef04dc..95c7342 100644 --- a/test/cberl_tests.erl +++ b/test/cberl_tests.erl @@ -8,7 +8,8 @@ cberl_test_() -> fun test_replace_add/1, fun test_get_and_touch/1, fun test_append_prepend/1, - fun test_remove/1]}]. + fun test_remove/1, + fun test_lock/1]}]. %%%=================================================================== %%% Setup / Teardown @@ -82,3 +83,15 @@ test_remove(_) -> ok = cberl:set(?POOLNAME, Key, 0, Value), ok = cberl:remove(?POOLNAME, Key), [?_assertEqual({Key, {error,key_enoent}}, cberl:get(?POOLNAME, Key))]. + +test_lock(_) -> + Key = <<"testkey">>, + Value = "testval", + Value2 = "testval2", + ok = cberl:set(?POOLNAME, Key, 0, Value), + {Key, CAS, _Exp} = cberl:get_and_lock(?POOLNAME, Key, 100000), + fun () -> + [?assertEqual({error,key_eexists}, cberl:set(?POOLNAME, Key, 0, Value2)), + ?assertEqual(ok, cberl:unlock(?POOLNAME, Key, CAS)), + ?assertEqual(ok, cberl:set(?POOLNAME, Key, 0, Value2))] + end.