|
| 1 | +%% ------------------------------------------------------------------- |
| 2 | +%% |
| 3 | +%% Copyright (c) 2010-2015 Basho Technologies, Inc. |
| 4 | +%% |
| 5 | +%% This file is provided to you under the Apache License, |
| 6 | +%% Version 2.0 (the "License"); you may not use this file |
| 7 | +%% except in compliance with the License. You may obtain |
| 8 | +%% a copy of the License at |
| 9 | +%% |
| 10 | +%% http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +%% |
| 12 | +%% Unless required by applicable law or agreed to in writing, |
| 13 | +%% software distributed under the License is distributed on an |
| 14 | +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +%% KIND, either express or implied. See the License for the |
| 16 | +%% specific language governing permissions and limitations |
| 17 | +%% under the License. |
| 18 | +%% |
| 19 | +%% ------------------------------------------------------------------- |
| 20 | + |
| 21 | +-module(verify_snmp_repl). |
| 22 | +-behavior(riak_test). |
| 23 | +-export([confirm/0]). |
| 24 | +-include_lib("eunit/include/eunit.hrl"). |
| 25 | +-compile({parse_transform, rt_intercept_pt}). |
| 26 | + |
| 27 | +confirm() -> |
| 28 | + Clusters = make_clusters(["cluster-1", "cluster-2", "cluster-3"], 1), |
| 29 | + [{_, Leader, _}|_] = Clusters, |
| 30 | + intercept_riak_snmp_stat_poller(Leader), |
| 31 | + wait_for_snmp_stat_poller(). |
| 32 | + |
| 33 | +make_clusters(Names, NodeCount) -> |
| 34 | + ClusterCount = length(Names), |
| 35 | + Config = [{riak_snmp, [{polling_interval, 100}]}], |
| 36 | + AllNodes = make_nodes(NodeCount, ClusterCount, Config), |
| 37 | + Clusters = lists:zip(Names, AllNodes), |
| 38 | + lists:foreach(fun make_named_cluster/1, Clusters), |
| 39 | + lists:foreach(fun wait_until_ring_converged/1, Clusters), |
| 40 | + lists:foreach(fun wait_until_leader_converge/1, Clusters), |
| 41 | + |
| 42 | + ClustersWithLeaders = [{Name, repl_util:get_leader(hd(Nodes)), Nodes} || {Name, Nodes} <- Clusters], |
| 43 | + enable_realtime(ClustersWithLeaders), |
| 44 | + ClustersWithLeaders. |
| 45 | + |
| 46 | +intercept_riak_snmp_stat_poller(Node) -> |
| 47 | + RiakTestProcess = self(), |
| 48 | + rt_intercept:add( |
| 49 | + Node, |
| 50 | + {riak_snmp_stat_poller, |
| 51 | + [{{set_rows, 4}, |
| 52 | + {[RiakTestProcess], |
| 53 | + fun(Table, Indexes, Cols, IndexCol) |
| 54 | + when Table =:= replRealtimeStatusTable; Table =:= replFullsyncStatusTable -> |
| 55 | + lager:log(info, self(), "JVOEGELE> set_rows(~p, ~p, ~p, ~p)", [Table, Indexes, Cols, IndexCol]), |
| 56 | + try |
| 57 | + riak_snmp_stat_poller_orig:set_rows_orig(Table, Indexes, Cols, IndexCol), |
| 58 | + RiakTestProcess ! pass |
| 59 | + catch |
| 60 | + Exception:Reason -> |
| 61 | + RiakTestProcess ! {fail, {Exception, Reason}}, |
| 62 | + error({Exception, Reason}) |
| 63 | + end |
| 64 | + end}}]}). |
| 65 | + |
| 66 | +wait_for_snmp_stat_poller() -> |
| 67 | + receive |
| 68 | + pass -> pass; |
| 69 | + {fail, Reason} -> {fail, Reason}; |
| 70 | + X -> {fail, {unknown, X}} |
| 71 | + after |
| 72 | + 1000 -> {fail, timeout} |
| 73 | + end. |
| 74 | + |
| 75 | +make_nodes(NodeCount, ClusterCount, Config) -> |
| 76 | + Nodes = rt:deploy_nodes(NodeCount * ClusterCount, Config), |
| 77 | + sublists(Nodes, NodeCount). |
| 78 | + |
| 79 | +sublists(List, Len) -> |
| 80 | + lists:map( |
| 81 | + fun(I) -> lists:sublist(List, I, Len) end, |
| 82 | + lists:seq(1, length(List), Len)). |
| 83 | + |
| 84 | +make_named_cluster({Name, Nodes}) -> |
| 85 | + repl_util:make_cluster(Nodes), |
| 86 | + repl_util:name_cluster(hd(Nodes), Name). |
| 87 | + |
| 88 | +wait_until_ring_converged({_Name, Nodes}) -> |
| 89 | + rt:wait_until_ring_converged(Nodes). |
| 90 | + |
| 91 | +wait_until_leader_converge({_Name, Nodes}) -> |
| 92 | + repl_util:wait_until_leader_converge(Nodes). |
| 93 | + |
| 94 | +enable_realtime([{_, Node, _}|OtherClusters]) -> |
| 95 | + lists:foreach( |
| 96 | + fun({Cluster, _, _}) -> |
| 97 | + repl_util:enable_realtime(Node, Cluster) |
| 98 | + end, |
| 99 | + OtherClusters). |
| 100 | + |
0 commit comments