riak_test/tests/loaded_upgrade_worker_sup.erl

249 lines
9.3 KiB
Erlang
Raw Normal View History

2013-02-07 16:45:55 +00:00
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2012 Basho Technologies, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------
2013-02-07 18:25:58 +00:00
-module(loaded_upgrade_worker_sup).
2013-01-29 21:54:23 +00:00
-include_lib("eunit/include/eunit.hrl").
2013-01-31 00:30:15 +00:00
-include_lib("riakc/include/riakc.hrl").
2013-01-29 21:54:23 +00:00
-behavior(supervisor).
2013-01-29 21:54:23 +00:00
%% API
-export([assert_equal/2]).
2013-01-31 00:30:15 +00:00
-export([list_keys_tester/5, kv_tester/5, mapred_tester/5,
twoi_tester/5, search_tester/5, tester_start_link/4]).
2013-01-29 21:54:23 +00:00
-export([init/1]).
-export([start_link/5]).
2013-01-29 21:54:23 +00:00
%% Helper macro for declaring children of supervisor
-define(CHILD(Name, FunName, Node, Vsn, ReportPid), {
list_to_atom(atom_to_list(Name) ++ "_" ++ atom_to_list(FunName)),
{ ?MODULE,
tester_start_link,
[FunName, Node, Vsn, ReportPid]},
permanent, 5000, worker, [?MODULE]}).
2013-01-29 21:54:23 +00:00
start_link(Name, Node, Backend, Vsn, ReportPid) ->
supervisor:start_link(?MODULE, [Name, Node, Backend, Vsn, ReportPid]).
2013-01-29 21:54:23 +00:00
init([Name, Node, Backend, Vsn, ReportPid]) ->
2013-02-06 17:20:38 +00:00
rt:wait_for_service(Node, [riak_search,riak_kv,riak_pipe]),
2013-01-31 00:30:15 +00:00
ChildSpecs1 = [
?CHILD(Name, FunName, Node, Vsn, ReportPid)
|| FunName <- [list_keys_tester, kv_tester, search_tester]],
2013-01-31 00:30:15 +00:00
ChildSpecs = case Backend of
2013-01-31 00:30:15 +00:00
eleveldb ->
[?CHILD(Name, twoi_tester, Node, Vsn, ReportPid) | ChildSpecs1];
_ -> ChildSpecs1
2013-01-31 00:30:15 +00:00
end,
{ok, {{one_for_one, 1000, 60}, ChildSpecs}}.
2013-01-31 00:30:15 +00:00
2013-01-29 21:54:23 +00:00
%%%===================================================================
%%% Internal functions
%%%===================================================================
tester_start_link(Function, Node, Vsn, ReportPid) ->
{ok, spawn_link(?MODULE, Function, [Node, 0, undefined, Vsn, ReportPid])}.
list_keys_tester(Node, Count, Pid, Vsn, ReportPid) ->
2013-02-05 19:28:30 +00:00
PBC = pb_pid_recycler(Pid, Node),
case riakc_pb_socket:list_keys(PBC, <<"objects">>) of
{ok, Keys} ->
ActualKeys = lists:usort(Keys),
ExpectedKeys = lists:usort([loaded_upgrade:int_to_key(K) || K <- lists:seq(0, 100)]),
case assert_equal(ExpectedKeys, ActualKeys) of
2013-02-01 22:08:03 +00:00
true -> cool;
_ -> ReportPid ! {listkeys, Node, not_equal}
2013-02-05 19:28:30 +00:00
end;
2013-02-01 22:08:03 +00:00
{error, timeout} ->
ReportPid ! {listkeys, Node, timeout};
2013-02-01 22:08:03 +00:00
{error, {timeout, _}} ->
ReportPid ! {listkeys, Node, timeout};
2013-02-05 19:28:30 +00:00
Unexpected ->
ReportPid ! {listkeys, Node, Unexpected}
2013-02-05 19:28:30 +00:00
end,
list_keys_tester(Node, Count + 1, PBC, Vsn, ReportPid).
2013-01-31 00:30:15 +00:00
kv_tester(Node, Count, Pid, Vsn, ReportPid) ->
2013-02-05 19:28:30 +00:00
PBC = pb_pid_recycler(Pid, Node),
2013-01-31 00:30:15 +00:00
Key = Count rem 8000,
case riakc_pb_socket:get(PBC, loaded_upgrade:bucket(kv), loaded_upgrade:int_to_key(Key)) of
{ok, Val} ->
case loaded_upgrade:kv_valgen(Key) == riakc_obj:get_value(Val) of
2013-02-01 22:08:03 +00:00
true -> cool;
_ -> ReportPid ! {kv, Node, not_equal}
2013-02-05 19:28:30 +00:00
end;
2013-02-01 22:08:03 +00:00
{error, disconnected} ->
2013-02-05 19:28:30 +00:00
ok;
{error, notfound} ->
ReportPid ! {kv, Node, {notfound, Key}};
2013-02-05 19:28:30 +00:00
Unexpected ->
ReportPid ! {kv, Node, Unexpected}
2013-02-05 19:28:30 +00:00
end,
kv_tester(Node, Count + 1, PBC, Vsn, ReportPid).
2013-01-31 00:30:15 +00:00
mapred_tester(Node, Count, Pid, Vsn, ReportPid) ->
2013-02-05 19:28:30 +00:00
PBC = pb_pid_recycler(Pid, Node),
case riakc_pb_socket:mapred(PBC, loaded_upgrade:bucket(mapred), loaded_upgrade:erlang_mr()) of
2013-01-31 00:30:15 +00:00
{ok, [{1, [10000]}]} ->
2013-02-05 19:28:30 +00:00
ok;
{ok, R} ->
lager:warning("Bad MR result: ~p", [R]),
ReportPid ! {mapred, Node, bad_result};
{error, disconnected} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
%% Finkmaster Flex says timeouts are ok
{error, timeout} ->
2013-02-05 19:28:30 +00:00
ok;
{error, {timeout, _}} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
{error, <<"{\"phase\":\"listkeys\",\"error\":\"{badmatch,{'EXIT',noproc}}", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
{error, <<"{\"phase\":\"listkeys\",\"error\":\"{badmatch,{'EXIT',timeout}}", _/binary>>} ->
ok;
2013-02-01 22:08:03 +00:00
{error, <<"{\"phase\":0,\"error\":\"badarg", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
{error, <<"{\"phase\":0,\"error\":\"[preflist_exhausted]", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
{error, <<"{\"phase\":0,\"error\":\"{badmatch,{'EXIT',timeout}}", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
{error, <<"{\"phase\":\"listkeys\",\"error\":\"function_clause\",\"input\":\"{cover,", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
{error, <<"{\"phase\":\"listkeys\",\"error\":\"badarg\",\"input\":\"{cover,", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
{error, <<"Error processing stream message: exit:{ucs,{bad_utf8_character_code}}:[{xmerl_ucs,", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
{error, <<"{\"phase\":0,\"error\":\"[{vnode_down,{shutdown,{gen_fsm,sync_send_event,", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
2013-02-01 22:08:03 +00:00
{error, <<"{\"phase\":0,\"error\":\"[{vnode_down,noproc}]", _/binary>>} ->
2013-02-05 19:28:30 +00:00
ok;
Unexpected ->
ReportPid ! {mapred, Node, Unexpected}
2013-02-05 19:28:30 +00:00
end,
mapred_tester(Node, Count + 1, PBC, Vsn, ReportPid).
2013-01-31 00:30:15 +00:00
twoi_tester(Node, 0, undefined, legacy, ReportPid) ->
2013-02-13 21:30:14 +00:00
lager:warning("Legacy nodes do not have 2i load applied"),
twoi_tester(Node, 1, undefined, legacy, ReportPid);
twoi_tester(Node, Count, Pid, legacy, ReportPid) ->
twoi_tester(Node, Count + 1, Pid, legacy, ReportPid);
twoi_tester(Node, Count, Pid, Vsn, ReportPid) ->
2013-02-05 19:28:30 +00:00
PBC = pb_pid_recycler(Pid, Node),
2013-01-31 00:30:15 +00:00
Key = Count rem 8000,
ExpectedKeys = [loaded_upgrade:int_to_key(Key)],
case {
riakc_pb_socket:get_index(
2013-02-05 19:28:30 +00:00
PBC,
loaded_upgrade:bucket(twoi),
2013-02-05 19:28:30 +00:00
{binary_index, "plustwo"},
loaded_upgrade:int_to_key(Key + 2)),
riakc_pb_socket:get_index(
PBC,
loaded_upgrade:bucket(twoi),
2013-02-05 19:28:30 +00:00
{integer_index, "plusone"},
Key + 1)
} of
2013-07-16 20:20:49 +00:00
{{ok, ?INDEX_RESULTS{keys=BinKeys}}, {ok, ?INDEX_RESULTS{keys=IntKeys}}} ->
case {assert_equal(ExpectedKeys, BinKeys), assert_equal(ExpectedKeys, IntKeys)} of
2013-02-01 22:08:03 +00:00
{true, true} -> cool;
{false, false} ->
ReportPid ! {twoi, Node, bolth_no_match};
2013-02-01 22:08:03 +00:00
{false, true} ->
ReportPid ! {twoi, Node, bin_no_match};
2013-02-01 22:08:03 +00:00
{true, false} ->
ReportPid ! {twoi, Node, int_no_match}
2013-02-05 19:28:30 +00:00
end;
{{error, Reason}, _} ->
ReportPid ! {twoi, Node, {error, Reason}};
{_, {error, Reason}} ->
ReportPid ! {twoi, Node, {error, Reason}};
2013-02-05 19:28:30 +00:00
Unexpected ->
ReportPid ! {twoi, Node, Unexpected}
2013-02-05 19:28:30 +00:00
end,
twoi_tester(Node, Count + 1, PBC, Vsn, ReportPid).
search_tester(Node, Count, Pid, Vsn, ReportPid) ->
2013-02-05 19:28:30 +00:00
PBC = pb_pid_recycler(Pid, Node),
{Term, Size} = search_check(Count),
case riakc_pb_socket:search(PBC, loaded_upgrade:bucket(search), Term) of
{ok, Result} ->
case Size == Result#search_results.num_found of
true -> ok;
_ ->
lager:warning("Bad search result: ~p Expected: ~p", [Result#search_results.num_found, Size]),
ReportPid ! {search, Node, bad_result}
end;
2013-02-01 22:08:03 +00:00
{error, disconnected} ->
%% oh well, reconnect
2013-02-05 19:28:30 +00:00
ok;
{error, <<"Error processing incoming message: throw:{timeout,range_loop}:[{riak_search_backend", _/binary>>} ->
case rt:is_mixed_cluster(Node) of
true ->
2013-02-05 19:28:30 +00:00
ok;
_ ->
ReportPid ! {search, Node, {timeout, range_loop}}
2013-02-05 19:28:30 +00:00
end;
2013-02-06 17:20:38 +00:00
{error,<<"Error processing incoming message: error:{case_clause,", _/binary>>} ->
%% although it doesn't say so, this is the infamous badfun
case rt:is_mixed_cluster(Node) of
true ->
2013-02-06 17:20:38 +00:00
ok;
_ ->
ReportPid ! {search, Node, {error, badfun}}
2013-02-06 17:20:38 +00:00
end;
2013-02-05 19:28:30 +00:00
Unexpected ->
ReportPid ! {search, Node, Unexpected}
2013-02-05 19:28:30 +00:00
end,
search_tester(Node, Count + 1, PBC, Vsn, ReportPid).
search_check(Count) ->
case Count rem 6 of
0 -> { <<"mx.example.net">>, 187};
1 -> { <<"ZiaSun">>, 1};
2 -> { <<"headaches">>, 4};
3 -> { <<"YALSP">>, 3};
4 -> { <<"mister">>, 0};
5 -> { <<"prohibiting">>, 5}
end.
2013-01-29 21:54:23 +00:00
assert_equal(Expected, Actual) ->
case Expected -- Actual of
2013-01-29 21:54:23 +00:00
[] -> ok;
Diff -> lager:info("Expected -- Actual: ~p", [Diff])
2013-01-29 21:54:23 +00:00
end,
2013-02-01 22:08:03 +00:00
Actual == Expected.
2013-01-29 21:54:23 +00:00
2013-02-05 19:28:30 +00:00
pb_pid_recycler(undefined, Node) ->
rt:pbc(Node);
2013-02-01 22:08:03 +00:00
pb_pid_recycler(Pid, Node) ->
case riakc_pb_socket:is_connected(Pid) of
true ->
Pid;
_ ->
riakc_pb_socket:stop(Pid),
2013-02-01 22:08:03 +00:00
rt:pbc(Node)
end.