Update capabilities test to handle new feature; new test for handoff encoding.

This commit is contained in:
Jesse Williamson 2013-02-25 13:08:34 -08:00
parent 38def74fa6
commit dab5006502
2 changed files with 159 additions and 5 deletions

View File

@ -1,6 +1,6 @@
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2012 Basho Technologies, Inc.
%% Copyright (c) 2012-2013 Basho Technologies, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
@ -22,6 +22,7 @@
-export([confirm/0]).
-include_lib("eunit/include/eunit.hrl").
%% 1.4 {riak_core, handoff_data_encoding} -> [encode_raw, encode_zlib]
%% 1.3 {riak_kv, anti_entropy} -> [disabled, enabled_v1]
confirm() ->
lager:info("Deploying mixed set of nodes"),
@ -37,7 +38,7 @@ confirm() ->
lager:info("Verify staged_joins == true"),
?assertEqual(ok, rt:wait_until_capability(CNode, {riak_core, staged_joins}, true)),
%% This test is written with the intent that 1.3 is 'current'
%% This test is written with the intent that 1.4 is 'current'
CCapabilities = rt:capability(CNode, all),
assert_capability(CCapabilities, {riak_kv, legacy_keylisting}, false),
assert_capability(CCapabilities, {riak_kv, listkeys_backpressure}, true),
@ -57,6 +58,10 @@ confirm() ->
assert_supported(CCapabilities, {riak_kv, mapred_system}, [pipe]),
assert_supported(CCapabilities, {riak_kv, vnode_vclocks}, [true,false]),
assert_supported(CCapabilities, {riak_pipe, trace_format}, [ordsets,sets]),
assert_supported(CCapabilities, {riak_core, handoff_data_encoding}, [encode_raw, encode_zlib]),
%% We've got a current-version node only, we should see raw selected as default:
assert_using(CNode, {riak_core, handoff_data_encoding}, encode_raw),
lager:info("Crash riak_core_capability server"),
restart_capability_server(CNode),
@ -90,7 +95,10 @@ confirm() ->
assert_supported(LCapabilities, {riak_kv, mapred_system}, [pipe]),
assert_supported(LCapabilities, {riak_kv, vnode_vclocks}, [true,false]),
assert_supported(LCapabilities, {riak_pipe, trace_format}, [ordsets,sets]),
%% We've added a legacy server: we should see zlib selected by the current-version node:
assert_using(CNode, {riak_core, handoff_data_encoding}, encode_zlib),
lager:info("Crash riak_core_capability server"),
restart_capability_server(CNode),
@ -125,11 +133,18 @@ confirm() ->
assert_supported(PCapabilities, {riak_kv, vnode_vclocks}, [true,false]),
assert_supported(PCapabilities, {riak_pipe, trace_format}, [ordsets,sets]),
%% We've added a previous version (1.2) we should (still) see zlib selected:
assert_using(CNode, {riak_core, handoff_data_encoding}, encode_zlib),
lager:info("Upgrade Legacy node"),
rt:upgrade(LNode, current),
?assertEqual(ok, rt:wait_until_all_members([CNode], [CNode, LNode, PNode])),
?assertEqual(ok, rt:wait_until_legacy_ringready(CNode)),
lager:info("Verify staged_joins == true after upgrade of legacy -> current");
lager:info("Verify staged_joins == true after upgrade of legacy -> current"),
%% We have upgraded the legacy node, but we should see zlib selected (previous node still not upgraded):
assert_using(CNode, {riak_core, handoff_data_encoding}, encode_zlib);
_ ->
lager:info("Legacy Riak not available, skipping legacy tests"),
lager:info("Adding previous node to cluster"),
@ -190,6 +205,9 @@ confirm() ->
assert_supported(CCap2, {riak_kv, vnode_vclocks}, [true,false]),
assert_supported(CCap2, {riak_pipe, trace_format}, [ordsets,sets]),
%% We've upgraded both legacy and previous versions; we should see raw selected by everyone:
[assert_using(Node, {riak_core, handoff_data_encoding}, encode_raw) || Node <- [CNode, PNode, LNode]],
%% All nodes are now current version. Test override behavior.
Override = fun(undefined, Prefer) ->
[{riak_core, [{override_capability,
@ -234,7 +252,17 @@ assert_capability(Capabilities, Capability, Value) ->
assert_supported(Capabilities, Capability, Value) ->
lager:info("Checking Capability Supported Values ~p =:= ~p", [Capability, Value]),
?assertEqual(Value, proplists:get_value(Capability, proplists:get_value('$supported', Capabilities))).
assert_using(Node, {CapabilityCategory, CapabilityName}, ExpectedCapabilityName) ->
lager:info("assert_using ~p =:= ~p", [ExpectedCapabilityName, CapabilityName]),
try ExpectedCapabilityName =:= rt:capability(Node, {CapabilityCategory, CapabilityName}) of
X -> X
catch
%% This is for catching a case in which a legacy node doesn't support capabilities at all:
exit:Exception -> lager:info("assert_using() caught exception: ~p", [Exception]),
false
end.
restart_capability_server(Node) ->
Pid = rpc:call(Node, erlang, whereis, [riak_core_capability]),
rpc:call(Node, erlang, exit, [Pid, kill]),

126
tests/verify_handoff.erl Normal file
View File

@ -0,0 +1,126 @@
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2013 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.
%%
%% -------------------------------------------------------------------
-module(verify_handoff).
-behavior(riak_test).
-export([confirm/0]).
-include_lib("eunit/include/eunit.hrl").
%% We've got a separate test for capability negotiation and other mechanisms, so the test here is fairly
%% straightforward: get a list of different versions of nodes and join them into a cluster, making sure that
%% each time our data has been replicated:
confirm() ->
NTestItems = 10, %% How many test items to write/verify?
NTestNodes = 3, %% How many nodes to spin up for tests?
TestMode = false, %% Set to false for "production tests", true if too slow.
EncodingTypes = [default, encode_raw, encode_zlib], %% Usually, you won't want to fiddle with these.
lists:foreach(fun(EncodingType) -> run_test(TestMode, NTestItems, NTestNodes, EncodingType) end, EncodingTypes),
lager:info("Test verify_handoff passed."),
pass.
run_test(TestMode, NTestItems, NTestNodes, HandoffEncoding) ->
lager:info("Testing handoff (items ~p, encoding: ~p)", [NTestItems, HandoffEncoding]),
lager:info("Spinning up test nodes"),
[RootNode | TestNodes] = Nodes = deploy_test_nodes(TestMode, NTestNodes),
rt:wait_for_service(RootNode, riak_kv),
case HandoffEncoding of
default -> lager:info("Using default encoding type."), true;
_ -> lager:info("Forcing encoding type to ~p.", [HandoffEncoding]),
OverrideData =
[
{ riak_core,
[
{ override_capability,
[
{ handoff_data_encoding,
[
{ use, HandoffEncoding},
{ prefer, HandoffEncoding}
]
}
]
}
]
}
],
rt:update_app_config(RootNode, OverrideData),
%% Update all nodes (capabilities are not re-negotiated):
lists:foreach(fun(TestNode) ->
rt:update_app_config(TestNode, OverrideData),
assert_using(RootNode, { riak_core, handoff_data_encoding }, HandoffEncoding)
end,
Nodes)
end,
lager:info("Populating root node."),
rt:systest_write(RootNode, NTestItems),
%% Test handoff on each node:
lager:info("Testing handoff for cluster."),
lists:foreach(fun(TestNode) -> test_handoff(RootNode, TestNode, NTestItems) end, TestNodes),
%% Prepare for the next call to our test:
lager:info("Bringing down test nodes."),
lists:foreach(fun(N) -> rt:leave(N), timer:sleep(50000), rt:wait_until_unpingable(N) end, TestNodes),
%% The "root" node can't leave() since it's the only node left:
lager:info("Stopping root node."),
rt:stop(RootNode), rt:wait_until_unpingable(RootNode).
%% See if we get the same data back from our new nodes as we put into the root node:
test_handoff(RootNode, NewNode, NTestItems) ->
lager:info("Waiting for service on new node."),
rt:wait_for_service(NewNode, riak_kv),
lager:info("Joining new node with cluster."),
rt:join(NewNode, RootNode),
timer:sleep(3000),
rt:wait_until_no_pending_changes([RootNode, NewNode]),
%% See if we get the same data back from the joined node that we added to the root node.
%% Note: systest_read() returns /non-matching/ items, so getting nothing back is good:
lager:info("Validating data after handoff:"),
Results = rt:systest_read(NewNode, NTestItems),
?assertEqual(0, length(Results)),
lager:info("Data looks ok.").
assert_using(Node, {CapabilityCategory, CapabilityName}, ExpectedCapabilityName) ->
lager:info("assert_using ~p =:= ~p", [ExpectedCapabilityName, CapabilityName]),
ExpectedCapabilityName =:= rt:capability(Node, {CapabilityCategory, CapabilityName}).
%% For some testing purposes, making these limits smaller is helpful:
deploy_test_nodes(false, N) ->
rt:deploy_nodes(N);
deploy_test_nodes(true, N) ->
lager:info("WARNING: Using turbo settings for testing."),
Config = [{riak_core, [{forced_ownership_handoff, 8},
{handoff_concurrency, 8},
{vnode_inactivity_timeout, 1000},
{gossip_limit, {10000000, 60000}}]}],
rt:deploy_nodes(N, Config).