2015-04-30 12:20:21 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2007-2015 Basho Technologies, Inc. All Rights Reserved.
|
|
|
|
%%
|
|
|
|
%% 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.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(machi_flu_psup_test).
|
|
|
|
|
|
|
|
-ifdef(TEST).
|
2015-06-02 13:13:15 +00:00
|
|
|
-ifndef(PULSE).
|
2015-04-30 12:20:21 +00:00
|
|
|
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
2015-05-01 15:33:49 +00:00
|
|
|
-include("machi_projection.hrl").
|
|
|
|
|
|
|
|
%% smoke_test2() will try repeatedly to make a TCP connection to ports
|
|
|
|
%% on localhost that have no listener.
|
|
|
|
%% If you use 'sysctl -w net.inet.icmp.icmplim=3' before running this
|
|
|
|
%% test, you'll get to exercise some timeout handling in
|
|
|
|
%% machi_chain_manager1:perhaps_call_t().
|
|
|
|
%% The default for net.inet.icmp.icmplim is 50.
|
|
|
|
|
|
|
|
smoke_test_() ->
|
|
|
|
{timeout, 5*60, fun() -> smoke_test2() end}.
|
|
|
|
|
|
|
|
smoke_test2() ->
|
2015-12-09 03:29:59 +00:00
|
|
|
Ps = [{a,#p_srvr{name=a, address="localhost", port=5550, props="./data.a"}},
|
|
|
|
{b,#p_srvr{name=b, address="localhost", port=5551, props="./data.b"}},
|
|
|
|
{c,#p_srvr{name=c, address="localhost", port=5552, props="./data.c"}}
|
2015-05-01 15:33:49 +00:00
|
|
|
],
|
|
|
|
[os:cmd("rm -rf " ++ P#p_srvr.props) || {_,P} <- Ps],
|
2015-11-19 08:42:01 +00:00
|
|
|
{ok, SupPid} = machi_sup:start_link(),
|
2015-04-30 12:20:21 +00:00
|
|
|
try
|
2015-05-02 07:59:28 +00:00
|
|
|
%% Only run a, don't run b & c so we have 100% failures talking to them
|
2015-05-01 15:33:49 +00:00
|
|
|
[begin
|
|
|
|
#p_srvr{name=Name, port=Port, props=Dir} = P,
|
|
|
|
{ok, _} = machi_flu_psup:start_flu_package(Name, Port, Dir, [])
|
|
|
|
end || {_,P} <- [hd(Ps)]],
|
2015-05-01 05:51:42 +00:00
|
|
|
|
2015-07-03 07:18:40 +00:00
|
|
|
[machi_chain_manager1:trigger_react_to_env(a_chmgr) || _ <-lists:seq(1,5)],
|
2015-05-01 15:33:49 +00:00
|
|
|
machi_chain_manager1:set_chain_members(a_chmgr, orddict:from_list(Ps)),
|
2015-07-03 07:18:40 +00:00
|
|
|
[machi_chain_manager1:trigger_react_to_env(a_chmgr) || _ <-lists:seq(1,5)],
|
2015-05-02 07:59:28 +00:00
|
|
|
ok
|
|
|
|
after
|
|
|
|
exit(SupPid, normal),
|
|
|
|
[os:cmd("rm -rf " ++ P#p_srvr.props) || {_,P} <- Ps],
|
|
|
|
machi_util:wait_for_death(SupPid, 100),
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
2015-05-08 06:36:53 +00:00
|
|
|
partial_stop_restart_test_() ->
|
|
|
|
{timeout, 5*60, fun() -> partial_stop_restart2() end}.
|
2015-05-02 07:59:28 +00:00
|
|
|
|
2015-05-08 06:36:53 +00:00
|
|
|
partial_stop_restart2() ->
|
2015-12-09 03:29:59 +00:00
|
|
|
Ps = [{a,#p_srvr{name=a, address="localhost", port=5560, props="./data.a"}},
|
|
|
|
{b,#p_srvr{name=b, address="localhost", port=5561, props="./data.b"}},
|
|
|
|
{c,#p_srvr{name=c, address="localhost", port=5562, props="./data.c"}}
|
2015-05-02 07:59:28 +00:00
|
|
|
],
|
2015-05-08 06:36:53 +00:00
|
|
|
ChMgrs = [machi_flu_psup:make_mgr_supname(P#p_srvr.name) || {_,P} <-Ps],
|
|
|
|
PStores = [machi_flu_psup:make_proj_supname(P#p_srvr.name) || {_,P} <-Ps],
|
|
|
|
Dict = orddict:from_list(Ps),
|
2015-05-02 07:59:28 +00:00
|
|
|
[os:cmd("rm -rf " ++ P#p_srvr.props) || {_,P} <- Ps],
|
2015-11-19 08:42:01 +00:00
|
|
|
{ok, SupPid} = machi_sup:start_link(),
|
2015-07-21 08:29:33 +00:00
|
|
|
DbgProps = [{initial_wedged, true}],
|
2015-05-08 08:07:03 +00:00
|
|
|
Start = fun({_,P}) ->
|
|
|
|
#p_srvr{name=Name, port=Port, props=Dir} = P,
|
|
|
|
{ok, _} = machi_flu_psup:start_flu_package(
|
2015-05-13 08:58:54 +00:00
|
|
|
Name, Port, Dir, [{active_mode,false}|DbgProps])
|
2015-05-08 08:07:03 +00:00
|
|
|
end,
|
|
|
|
WedgeStatus = fun({_,#p_srvr{address=Addr, port=TcpPort}}) ->
|
|
|
|
machi_flu1_client:wedge_status(Addr, TcpPort)
|
|
|
|
end,
|
2015-12-28 03:58:26 +00:00
|
|
|
NSInfo = undefined,
|
2015-07-01 08:46:35 +00:00
|
|
|
Append = fun({_,#p_srvr{address=Addr, port=TcpPort}}, EpochID) ->
|
2015-12-23 06:47:38 +00:00
|
|
|
NoCSum = <<>>,
|
2015-05-08 09:22:44 +00:00
|
|
|
machi_flu1_client:append_chunk(Addr, TcpPort,
|
2015-12-23 06:47:38 +00:00
|
|
|
NSInfo, EpochID,
|
|
|
|
<<"prefix">>,
|
|
|
|
<<"data">>, NoCSum)
|
2015-05-08 09:22:44 +00:00
|
|
|
end,
|
2015-05-02 07:59:28 +00:00
|
|
|
try
|
2015-05-08 06:36:53 +00:00
|
|
|
[Start(P) || P <- Ps],
|
2015-05-08 08:07:03 +00:00
|
|
|
[{ok, {true, _}} = WedgeStatus(P) || P <- Ps], % all are wedged
|
2015-07-01 08:46:35 +00:00
|
|
|
[{error,wedged} = Append(P, ?DUMMY_PV1_EPOCH) || P <- Ps], % all are wedged
|
2015-05-02 07:59:28 +00:00
|
|
|
|
|
|
|
[machi_chain_manager1:set_chain_members(ChMgr, Dict) ||
|
|
|
|
ChMgr <- ChMgrs ],
|
2015-07-01 08:46:35 +00:00
|
|
|
{ok, {false, EpochID1}} = WedgeStatus(hd(Ps)),
|
|
|
|
[{ok, {false, EpochID1}} = WedgeStatus(P) || P <- Ps], % *not* wedged
|
|
|
|
[{ok,_} = Append(P, EpochID1) || P <- Ps], % *not* wedged
|
2015-07-02 16:58:13 +00:00
|
|
|
{ok, {_,_,File1}} = Append(hd(Ps), EpochID1),
|
2015-05-02 07:59:28 +00:00
|
|
|
|
2015-07-03 07:18:40 +00:00
|
|
|
{_,_,_} = machi_chain_manager1:trigger_react_to_env(hd(ChMgrs)),
|
2015-05-02 07:59:28 +00:00
|
|
|
[begin
|
2015-07-03 07:18:40 +00:00
|
|
|
_QQa = machi_chain_manager1:trigger_react_to_env(ChMgr)
|
2015-06-15 04:02:25 +00:00
|
|
|
end || _ <- lists:seq(1,125), ChMgr <- ChMgrs],
|
2015-05-02 07:59:28 +00:00
|
|
|
|
2015-05-08 06:36:53 +00:00
|
|
|
%% All chain managers & projection stores should be using the
|
2015-05-02 07:59:28 +00:00
|
|
|
%% same projection which is max projection in each store.
|
2015-07-03 07:18:40 +00:00
|
|
|
{no_change,_,Epoch_m} = machi_chain_manager1:trigger_react_to_env(
|
2015-05-08 06:36:53 +00:00
|
|
|
hd(ChMgrs)),
|
2015-07-03 07:18:40 +00:00
|
|
|
[{no_change,_,Epoch_m} = machi_chain_manager1:trigger_react_to_env(
|
2015-05-02 07:59:28 +00:00
|
|
|
ChMgr )|| ChMgr <- ChMgrs],
|
2015-05-08 06:36:53 +00:00
|
|
|
{ok, Proj_m} = machi_projection_store:read_latest_projection(
|
2015-05-02 07:59:28 +00:00
|
|
|
hd(PStores), public),
|
2015-04-30 14:16:08 +00:00
|
|
|
[begin
|
2015-06-15 04:02:25 +00:00
|
|
|
{ok, Proj_m2} = machi_projection_store:read_latest_projection(
|
|
|
|
PStore, ProjType),
|
|
|
|
true = (machi_projection:update_dbg2(Proj_m, []) ==
|
|
|
|
machi_projection:update_dbg2(Proj_m2, []))
|
2015-05-02 07:59:28 +00:00
|
|
|
end || ProjType <- [public, private], PStore <- PStores ],
|
2015-05-08 06:36:53 +00:00
|
|
|
Epoch_m = Proj_m#projection_v1.epoch_number,
|
2015-05-08 09:17:41 +00:00
|
|
|
%% Confirm that all FLUs are *not* wedged, with correct proj & epoch
|
|
|
|
Proj_mCSum = Proj_m#projection_v1.epoch_csum,
|
|
|
|
[{ok, {false, {Epoch_m, Proj_mCSum}}} = WedgeStatus(P) || % *not* wedged
|
|
|
|
P <- Ps],
|
2015-07-17 08:19:33 +00:00
|
|
|
{ok, {false, EpochID1}} = WedgeStatus(hd(Ps)),
|
|
|
|
[{ok,_} = Append(P, EpochID1) || P <- Ps], % *not* wedged
|
2015-05-08 06:36:53 +00:00
|
|
|
|
|
|
|
%% Stop all but 'a'.
|
|
|
|
[ok = machi_flu_psup:stop_flu_package(Name) || {Name,_} <- tl(Ps)],
|
|
|
|
|
|
|
|
%% Stop and restart a.
|
|
|
|
{FluName_a, _} = hd(Ps),
|
|
|
|
ok = machi_flu_psup:stop_flu_package(FluName_a),
|
|
|
|
{ok, _} = Start(hd(Ps)),
|
2015-08-26 05:38:56 +00:00
|
|
|
timer:sleep(123), % TODO fix server socket available race condition in better way
|
2015-05-08 06:36:53 +00:00
|
|
|
%% Remember: 'a' is not in active mode.
|
2015-06-15 04:02:25 +00:00
|
|
|
{ok, Proj_m3} = machi_projection_store:read_latest_projection(
|
|
|
|
hd(PStores), private),
|
|
|
|
true = (machi_projection:update_dbg2(Proj_m, []) ==
|
2015-08-26 05:38:56 +00:00
|
|
|
machi_projection:update_dbg2(Proj_m3, [])),
|
2015-05-08 10:07:57 +00:00
|
|
|
%% Confirm that 'a' is wedged
|
2015-07-17 08:19:33 +00:00
|
|
|
{error, wedged} = Append(hd(Ps), EpochID1),
|
2015-05-08 10:50:47 +00:00
|
|
|
{_, #p_srvr{address=Addr_a, port=TcpPort_a}} = hd(Ps),
|
|
|
|
{error, wedged} = machi_flu1_client:read_chunk(
|
2015-12-28 03:58:26 +00:00
|
|
|
Addr_a, TcpPort_a, NSInfo, ?DUMMY_PV1_EPOCH,
|
2015-12-29 09:47:08 +00:00
|
|
|
<<>>, 99999999, 1, undefined),
|
2015-12-29 08:24:09 +00:00
|
|
|
{error, bad_arg} = machi_flu1_client:checksum_list(
|
|
|
|
Addr_a, TcpPort_a, <<>>),
|
2015-07-01 08:57:23 +00:00
|
|
|
%% list_files() is permitted despite wedged status
|
|
|
|
{ok, _} = machi_flu1_client:list_files(
|
2015-05-08 10:50:47 +00:00
|
|
|
Addr_a, TcpPort_a, ?DUMMY_PV1_EPOCH),
|
|
|
|
|
2015-05-08 10:07:57 +00:00
|
|
|
%% Iterate through humming consensus once
|
2015-07-03 07:18:40 +00:00
|
|
|
{now_using,_,Epoch_n} = machi_chain_manager1:trigger_react_to_env(
|
2015-05-08 06:36:53 +00:00
|
|
|
hd(ChMgrs)),
|
|
|
|
true = (Epoch_n > Epoch_m),
|
2015-07-01 08:46:35 +00:00
|
|
|
{ok, {false, EpochID3}} = WedgeStatus(hd(Ps)),
|
2015-07-02 16:58:13 +00:00
|
|
|
%% The file we're assigned should be different with the epoch change.
|
|
|
|
{ok, {_,_,File3}} = Append(hd(Ps), EpochID3),
|
2015-07-17 08:19:33 +00:00
|
|
|
true = (File1 /= File3),
|
2015-07-01 08:46:35 +00:00
|
|
|
|
2015-05-08 10:07:57 +00:00
|
|
|
%% Confirm that 'a' is *not* wedged
|
2015-07-01 08:46:35 +00:00
|
|
|
{ok, _} = Append(hd(Ps), EpochID3),
|
2015-05-08 06:36:53 +00:00
|
|
|
|
2015-04-30 12:20:21 +00:00
|
|
|
ok
|
|
|
|
after
|
2015-05-01 05:51:42 +00:00
|
|
|
exit(SupPid, normal),
|
2015-05-01 15:33:49 +00:00
|
|
|
[os:cmd("rm -rf " ++ P#p_srvr.props) || {_,P} <- Ps],
|
2015-05-01 05:51:42 +00:00
|
|
|
machi_util:wait_for_death(SupPid, 100),
|
|
|
|
ok
|
2015-04-30 12:20:21 +00:00
|
|
|
end.
|
|
|
|
|
2015-12-04 07:37:05 +00:00
|
|
|
p_srvr_rec_test() ->
|
|
|
|
P = #p_srvr{name=a, address="localhost", port=1024, props=[yo]},
|
|
|
|
[P] = machi_flu_sup:sanitize_p_srvr_records([P]),
|
|
|
|
[P] = machi_flu_sup:sanitize_p_srvr_records([P,P]),
|
|
|
|
[] = machi_flu_sup:sanitize_p_srvr_records([nope]),
|
|
|
|
[] = machi_flu_sup:sanitize_p_srvr_records([#p_srvr{proto_mod=does_not_exist}]),
|
|
|
|
[] = machi_flu_sup:sanitize_p_srvr_records([#p_srvr{proto_mod="lists"}]),
|
|
|
|
[] = machi_flu_sup:sanitize_p_srvr_records([#p_srvr{address=7}]),
|
|
|
|
[] = machi_flu_sup:sanitize_p_srvr_records([#p_srvr{port=5}]),
|
|
|
|
[] = machi_flu_sup:sanitize_p_srvr_records([#p_srvr{port=foo}]),
|
|
|
|
[] = machi_flu_sup:sanitize_p_srvr_records([#p_srvr{props=foo}]),
|
|
|
|
ok.
|
|
|
|
|
2015-06-02 13:13:15 +00:00
|
|
|
-endif. % !PULSE
|
2015-04-30 12:20:21 +00:00
|
|
|
-endif. % TEST
|
|
|
|
|
|
|
|
|
|
|
|
|