Skip to content

Commit

Permalink
Merge pull request #351 from lucafavatella/dt-update-with-riak-genera…
Browse files Browse the repository at this point in the history
…ted-key

Expose CRDT update without key delegating key generation to Riak
  • Loading branch information
lukebakken committed Feb 21, 2017
2 parents 8ae580b + 778f21d commit 87958bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/riakc_pb_socket.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ fetch_type(Pid, BucketAndType, Key, Options) ->

%% @doc Updates the convergent datatype in Riak with local
%% modifications stored in the container type.
-spec update_type(pid(), bucket_and_type(), Key::binary(), Update::riakc_datatype:update(term())) ->
-spec update_type(pid(), bucket_and_type(), Key::binary()|'undefined', Update::riakc_datatype:update(term())) ->
ok | {ok, Key::binary()} | {ok, riakc_datatype:datatype()} |
{ok, Key::binary(), riakc_datatype:datatype()} | {error, term()}.
update_type(Pid, BucketAndType, Key, Update) ->
Expand All @@ -1266,7 +1266,7 @@ update_type(Pid, BucketAndType, Key, Update) ->
%% @doc Updates the convergent datatype in Riak with local
%% modifications stored in the container type, using the given request
%% options.
-spec update_type(pid(), bucket_and_type(), Key::binary(),
-spec update_type(pid(), bucket_and_type(), Key::binary()|'undefined',
Update::riakc_datatype:update(term()), [proplists:property()]) ->
ok | {ok, Key::binary()} | {ok, riakc_datatype:datatype()} |
{ok, Key::binary(), riakc_datatype:datatype()} | {error, term()}.
Expand Down
19 changes: 19 additions & 0 deletions test/riakc_pb_socket_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,25 @@ integration_tests() ->
1 == Result#search_results.num_found
end )
end)}},
{"updating without a key should generate one",
?_test(begin
riakc_test_utils:reset_riak(),
{ok, Pid} = riakc_test_utils:start_link(),
Res1 = riakc_pb_socket:update_type(Pid,
{<<"sets">>, <<"bucket">>}, undefined,
riakc_set:to_op(riakc_set:add_element(<<"X">>, riakc_set:new()))),
Res2 = riakc_pb_socket:update_type(Pid,
{<<"sets">>, <<"bucket">>}, undefined,
riakc_set:to_op(riakc_set:add_element(<<"Y">>, riakc_set:new()))),
?assertMatch({ok, _K}, Res1),
?assertMatch({ok, _K}, Res2),
{ok, K1} = Res1,
{ok, K2} = Res2,
?assertMatch(true, is_binary(K1)),
?assertMatch(true, is_binary(K2)),
% Make sure the same key isn't generated twice
?assert(Res1 =/= Res2)
end)},
{"trivial set delete",
?_test(begin
riakc_test_utils:reset_riak(),
Expand Down

0 comments on commit 87958bd

Please sign in to comment.