|
| 1 | +%% ------------------------------------------------------------------- |
| 2 | +%% |
| 3 | +%% Copyright (c) 2016 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 | +-module(kv_vnode_requests_upgrade_downgrade). |
| 21 | + |
| 22 | +-include_lib("eunit/include/eunit.hrl"). |
| 23 | + |
| 24 | +-export([confirm/0]). |
| 25 | + |
| 26 | +-define(NUM_KEYS, 100). |
| 27 | +-define(BUCKET, <<"ale">>). |
| 28 | +-define(CLUSTER_SIZE, 5). |
| 29 | +-define(CONFIG, []). |
| 30 | + |
| 31 | +confirm() -> |
| 32 | + Cluster = [Node| _ ] = rt:build_cluster(lists:duplicate(?CLUSTER_SIZE, {lts, ?CONFIG})), |
| 33 | + Clients = [rt:pbc(N) || N <- Cluster], |
| 34 | + |
| 35 | + lager:info("Writing ~p keys", [?NUM_KEYS]), |
| 36 | + rt:systest_write(Node, ?NUM_KEYS, ?BUCKET), |
| 37 | + |
| 38 | + Before = count_keys(Clients, ?BUCKET), |
| 39 | + ExpectedCounts = lists:duplicate(?CLUSTER_SIZE, ?NUM_KEYS), |
| 40 | + ?assertEqual(Before, ExpectedCounts), |
| 41 | + |
| 42 | + perform_upgrade(Cluster, current, 3), |
| 43 | + |
| 44 | + After = count_keys(Clients, ?BUCKET), |
| 45 | + ?assertEqual(Before, After), |
| 46 | + pass. |
| 47 | + |
| 48 | +count_keys(Clients, Bucket) when is_list(Clients) -> |
| 49 | + [count_keys(Client, Bucket) || Client <- Clients]; |
| 50 | +count_keys(Client, Bucket) -> |
| 51 | + {ok, Keys} = riakc_pb_socket:list_keys(Client, Bucket, 5000), |
| 52 | + length(Keys). |
| 53 | + |
| 54 | +perform_upgrade(Node, Version) -> |
| 55 | + lager:info("Upgrading node ~p", [Node]), |
| 56 | + rt:upgrade(Node, Version), |
| 57 | + lager:info("Upgrade finished on node ~p", [Node]), |
| 58 | + rt:wait_for_service(Node, riak_kv). |
| 59 | +perform_upgrade(Cluster, Version, TakeN) -> |
| 60 | + lists:foreach(fun(Node) -> perform_upgrade(Node, Version) end, |
| 61 | + lists:sublist(Cluster, TakeN)). |
0 commit comments