Permalink
Browse files

Fix leo-project/leofs#146

  • Loading branch information...
1 parent 0b2e3a8 commit f717cfbe85f2e1746704fe633a3488ad5aa2520d @yosukehara yosukehara committed Mar 5, 2014
Showing with 18 additions and 13 deletions.
  1. +9 −5 src/leo_storage_handler_object.erl
  2. +9 −8 test/leo_storage_handler_object_tests.erl
@@ -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
@@ -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}} ->
@@ -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).
+
+
%%--------------------------------------------------------------------
@@ -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.

0 comments on commit f717cfb

Please sign in to comment.