Skip to content

Commit

Permalink
Merge pull request #30 from wcummings/master
Browse files Browse the repository at this point in the history
start_key -> startkey
  • Loading branch information
soup-in-boots committed Mar 30, 2014
2 parents 83630e1 + 7c4af75 commit 22a658d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/cberl.erl
Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions src/cberl_worker.erl
Expand Up @@ -14,8 +14,6 @@
terminate/2,
code_change/3]).

-define(TIMEOUT, infinity).

%%%===================================================================
%%% API
%%%===================================================================
Expand Down Expand Up @@ -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.


Expand All @@ -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}) ->
Expand All @@ -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}) ->
Expand All @@ -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,
Expand All @@ -119,22 +113,19 @@ 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,
State = #instance{handle = Handle}) ->
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,
Expand Down
15 changes: 14 additions & 1 deletion test/cberl_tests.erl
Expand Up @@ -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
Expand Down Expand Up @@ -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.

0 comments on commit 22a658d

Please sign in to comment.