Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yosukehara committed Mar 5, 2014
1 parent 0b2e3a8 commit f717cfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
14 changes: 9 additions & 5 deletions src/leo_storage_handler_object.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@

-export([get/1, get/2, get/3, get/4, get/5,
put/1, put/2, put/3,
delete/1, delete/2, head/2,
delete/1, delete/2,
head/2,
copy/3,
prefix_search/3, prefix_search_and_remove_objects/1,
find_uploaded_objects_by_key/1
Expand Down Expand Up @@ -318,8 +319,7 @@ delete(_,_) ->
%% @doc retrieve a meta-data from mata-data-server (file).
%%
-spec(head(integer(), string()) ->
{ok, #metadata{}} |
{error, any}).
{ok, #metadata{}} | {error, any}).
head(AddrId, Key) ->
case leo_redundant_manager_api:get_redundancies_by_addr_id(get, AddrId) of
{ok, #redundancies{nodes = Redundancies}} ->
Expand All @@ -341,13 +341,17 @@ head_1([#redundant_node{node = Node,
end;
head_1([#redundant_node{node = Node,
available = true}|Rest], AddrId, Key) ->
RPCKey = rpc:async_call(Node, ?MODULE, head, [{AddrId, Key}]),
RPCKey = rpc:async_call(Node, leo_object_storage_api, head, [{AddrId, Key}]),
case rpc:nb_yield(RPCKey, ?DEF_REQ_TIMEOUT) of
{value, {ok, MetaBin}} ->
{ok, binary_to_term(MetaBin)};
_ ->
head_1(Rest, AddrId, Key)
end.
end;
head_1([_|Rest], AddrId, Key) ->
head_1(Rest, AddrId, Key).




%%--------------------------------------------------------------------
Expand Down
17 changes: 9 additions & 8 deletions test/leo_storage_handler_object_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -605,24 +605,25 @@ head_({Node0, Node1}) ->

%% 2.
meck:unload(),
meck:new(leo_object_storage_api),
meck:expect(leo_object_storage_api, head,
fun(_Key) ->
{error, []}
end),
meck:new(leo_redundant_manager_api),
meck:expect(leo_redundant_manager_api, get_redundancies_by_addr_id,
fun(get, _AddrId) ->
{ok, #redundancies{id = 0,
nodes = [#redundant_node{node = Node0,
available = true},
available = false},
#redundant_node{node = Node1,
available = true}],
n = 2, r = 1, w = 1, d = 1}}
end),

Res2 = leo_storage_handler_object:head(0, ?TEST_KEY_0),
?assertEqual({error, not_found}, Res2),
ok = rpc:call(Node1, meck, new, [leo_object_storage_api, [no_link]]),
ok = rpc:call(Node1, meck, expect, [leo_object_storage_api, head,
fun(_Arg) ->
{ok, term_to_binary(?TEST_META_0)}
end]),

{ok, Res2} = leo_storage_handler_object:head(0, ?TEST_KEY_0),
?assertEqual(?TEST_META_0, Res2),
ok.


Expand Down

0 comments on commit f717cfb

Please sign in to comment.