From 56b1cab22c09e23fd7057adafa5e7258ccea587e Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Mon, 23 May 2016 13:15:05 -0700 Subject: [PATCH 1/2] Modify test to test that returned object from Riak is actually a binary --- src/riakc_pb_socket.erl | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/riakc_pb_socket.erl b/src/riakc_pb_socket.erl index 95d88cc4..401d811c 100644 --- a/src/riakc_pb_socket.erl +++ b/src/riakc_pb_socket.erl @@ -3269,14 +3269,19 @@ live_node_tests() -> end)}, {"putting without a key should generate one", ?_test(begin - reset_riak(), - {ok, Pid} = start_link(test_ip(), test_port()), - PO = riakc_obj:new(<<"b">>, undefined, <<"value">>), - Res1 = ?MODULE:put(Pid, PO), - Res2 = ?MODULE:put(Pid, PO), - ?assertMatch({ok, _Key}, Res1), - % Make sure the same key isn't generated twice - ?assert(Res1 =/= Res2) + reset_riak(), + {ok, Pid} = start_link(test_ip(), test_port()), + PO = riakc_obj:new(<<"b">>, undefined, <<"value">>), + Res1 = ?MODULE:put(Pid, PO), + Res2 = ?MODULE:put(Pid, PO), + ?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)}, {"putting without a key should generate one with return_body", ?_test(begin @@ -3286,8 +3291,8 @@ live_node_tests() -> {ok, Obj1} = ?MODULE:put(Pid, PO, [return_body]), {ok, Obj2} = ?MODULE:put(Pid, PO, [return_body]), %% Make sure the same key isn't generated twice - ?assertEqual(element(1, Obj1), riakc_obj), - ?assertEqual(element(1, Obj2), riakc_obj), + ?assertEqual(riakc_obj, element(1, Obj1)), + ?assertEqual(riakc_obj, element(1, Obj2)), ?assert(riakc_obj:key(Obj1) /= riakc_obj:key(Obj2)) end)}, {"conditional gets should return unchanged if the vclock matches", From ee3d3cffdc09ff943b870b7325f21595dcf2cc37 Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Mon, 23 May 2016 14:07:25 -0700 Subject: [PATCH 2/2] Add function clause to match on an empty list for content in cases where return_body is not set Add contributor --- README.md | 7 +++++++ src/riakc_pb_socket.erl | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 005fec61..8cdd26ec 100644 --- a/README.md +++ b/README.md @@ -642,6 +642,13 @@ Troubleshooting If `start/2` or `start_link/2` return `{error,econnrefused}` the client could not connect to the server - make sure the protocol buffers interface is enabled on the server and the address/port is correct. +Contributors +============ + +This is not a comprehensive list, please see the commit history. + +* [Sam Tavakoli](https://github.com/sata) + [basho_docs]: http://docs.basho.com/ [kv_setup]: http://docs.basho.com/riak/kv/latest/setup/ [erlang_client_edocs]: http://basho.github.com/riak-erlang-client/ diff --git a/src/riakc_pb_socket.erl b/src/riakc_pb_socket.erl index 401d811c..662f29d4 100644 --- a/src/riakc_pb_socket.erl +++ b/src/riakc_pb_socket.erl @@ -1638,6 +1638,8 @@ process_response(#request{msg = rpbgetserverinforeq}, [{server_version, ServerVersion}] end, {reply, {ok, NodeInfo++VersionInfo}, State}; + +%% rpbgetreq process_response(#request{msg = #rpbgetreq{}}, rpbgetresp, State) -> %% server just returned the rpbgetresp code - no message was encoded {reply, {error, notfound}, State}; @@ -1654,16 +1656,23 @@ process_response(#request{msg = #rpbgetreq{type = Type, bucket = Bucket, key = K B = maybe_make_bucket_type(Type, Bucket), {reply, {ok, riakc_obj:new_obj(B, Key, Vclock, Contents)}, State}; +%% rpbputreq process_response(#request{msg = #rpbputreq{}}, rpbputresp, State) -> %% server just returned the rpbputresp code - no message was encoded {reply, ok, State}; -process_response(#request{ msg = #rpbputreq{}}, +process_response(#request{msg = #rpbputreq{}}, #rpbputresp{key = Key, content=undefined, vclock=undefined}, State) when is_binary(Key) -> %% server generated a key and the client didn't request return_body, but %% the created key is returned {reply, {ok, Key}, State}; +process_response(#request{msg = #rpbputreq{}}, + #rpbputresp{key = Key, content=[], vclock=undefined}, + State) when is_binary(Key) -> + %% server generated a key and the client didn't request return_body, but + %% the created key is returned + {reply, {ok, Key}, State}; process_response(#request{msg = #rpbputreq{type = Type, bucket = Bucket, key = Key}}, #rpbputresp{content = RpbContents, vclock = Vclock, key = NewKey}, State) ->