Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wcummings committed Dec 6, 2016
1 parent c8460e4 commit 60be0c6
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions test/cberl_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,44 @@ clean_up(_) ->
test_set_and_get(_) ->
Key = <<"testkey">>,
Value = "testval",
ok = cberl:set(?POOLNAME, Key, 0, Value),
{ok, CAS1} = cberl:set(?POOLNAME, Key, 0, Value),
Get1 = cberl:get(?POOLNAME, Key),
ok = cberl:set(?POOLNAME, Key, 0, Value, json),
{ok, CAS2} = cberl:set(?POOLNAME, Key, 0, Value, json),
Get2 = cberl:get(?POOLNAME, Key),
ok = cberl:set(?POOLNAME, Key, 0, Value, raw_binary),
{ok, CAS3} = cberl:set(?POOLNAME, Key, 0, Value, raw_binary),
Get3 = cberl:get(?POOLNAME, Key),
[?_assertMatch({Key, _, Value}, Get1),
?_assertMatch({Key, _, Value}, Get2),
?_assertMatch({Key, _, Value}, Get3)
[?_assertMatch({Key, CAS1, Value}, Get1),
?_assertMatch({Key, CAS2, Value}, Get2),
?_assertMatch({Key, CAS3, Value}, Get3)
].

test_multi_get(_) ->
Value = "testval",
Keys = lists:map(fun(N) -> list_to_binary(integer_to_list(N)) end, lists:seq(1, 1000)),
lists:map(fun(Key) -> ok = cberl:set(?POOLNAME, Key, 0, Value) end, Keys),
lists:map(fun(Key) -> {ok, _} = cberl:set(?POOLNAME, Key, 0, Value) end, Keys),
[?_assertMatch({<<"1">>,_, "testval"}, lists:nth(1, cberl:mget(?POOLNAME, Keys)))].

test_replace_add(_) ->
Key = <<"testkey">>,
Value = "testval",
ok = cberl:set(?POOLNAME, Key, 0, Value),
{ok, _} = cberl:set(?POOLNAME, Key, 0, Value),
AddFail = cberl:add(?POOLNAME, Key, 0, Value),
AddPass = cberl:add(?POOLNAME, <<"testkey1">>, 0, Value),
ReplaceFail = cberl:replace(?POOLNAME, <<"notestkey">>, 0, Value),
ok = cberl:replace(?POOLNAME, Key, 0, "testval1"),
{ok, _} = cberl:replace(?POOLNAME, Key, 0, "testval1"),
Get1 = cberl:get(?POOLNAME, Key),
[?_assertEqual({error, key_eexists}, AddFail),
?_assertEqual(ok, AddPass),
?_assertMatch({ok, _}, AddPass),
?_assertEqual({error, key_enoent}, ReplaceFail),
?_assertMatch({Key, _, "testval1"}, Get1)
].

test_append_prepend(_) ->
Key = <<"testkey">>,
ok = cberl:set(?POOLNAME, Key, 0, "base", str),
ok = cberl:append(?POOLNAME, Key, "tail"),
{ok, _} = cberl:set(?POOLNAME, Key, 0, "base", str),
{ok, _} = cberl:append(?POOLNAME, Key, "tail"),
Get1 = cberl:get(?POOLNAME, Key),
ok = cberl:prepend(?POOLNAME, Key, "head"),
{ok, _} = cberl:prepend(?POOLNAME, Key, "head"),
Get2 = cberl:get(?POOLNAME, Key),
[?_assertMatch({Key, _, "basetail"}, Get1),
?_assertMatch({Key, _, "headbasetail"}, Get2)
Expand All @@ -86,42 +86,42 @@ test_append_prepend(_) ->
test_get_and_touch(_) ->
Key = <<"testkey">>,
Value = "testval",
ok = cberl:set(?POOLNAME, Key, 0, Value),
{ok, _} = cberl:set(?POOLNAME, Key, 0, Value),
cberl:get_and_touch(?POOLNAME, Key, 1),
timer:sleep(5000),
[?_assertEqual({Key, {error,key_enoent}}, cberl:get(?POOLNAME, Key))].

test_touch(_) ->
Key = <<"testkey">>,
Value = "testval",
ok = cberl:set(?POOLNAME, Key, 0, Value),
{ok, _} = cberl:set(?POOLNAME, Key, 0, Value),
{ok, _} = cberl:touch(?POOLNAME, Key, 1),
timer:sleep(5000),
[?_assertEqual({Key, {error,key_enoent}}, cberl:get(?POOLNAME, Key))].

test_remove(_) ->
Key = <<"testkey">>,
Value = "testval",
ok = cberl:set(?POOLNAME, Key, 0, Value),
{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),
{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))]
?assertMatch({ok, _}, cberl:set(?POOLNAME, Key, 0, Value2))]
end.

test_flush(_) ->
Key = <<"testkey">>,
Value = "testval",
ok = cberl:set(?POOLNAME, Key, 0, Value),
{ok, _} = cberl:set(?POOLNAME, Key, 0, Value),
fun() ->
[?assertMatch(ok, cberl:flush(?POOLNAME, "default")),
?assertMatch({Key, {error, key_enoent}}, cberl:get(?POOLNAME, Key))]
Expand All @@ -130,7 +130,7 @@ test_flush(_) ->
test_flush_1(_) ->
Key = <<"testkey">>,
Value = "testval",
ok = cberl:set(?POOLNAME, Key, 0, Value),
{ok, _} = cberl:set(?POOLNAME, Key, 0, Value),
fun() ->
[?assertMatch(ok, cberl:flush(?POOLNAME)),
?assertMatch({Key, {error, key_enoent}}, cberl:get(?POOLNAME, Key))]
Expand Down

0 comments on commit 60be0c6

Please sign in to comment.