|
| 1 | +%% --------------------------------------------------------------------- |
| 2 | +%% |
| 3 | +%% Copyright (c) 2007-2013 Basho Technologies, Inc. All Rights Reserved. |
| 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(cs743_regression_test). |
| 22 | + |
| 23 | +%% @doc Regression test for `riak_cs' <a href="https://github.com/basho/riak_cs/issues/286"> |
| 24 | +%% issue 286</a>. |
| 25 | + |
| 26 | +-export([confirm/0]). |
| 27 | + |
| 28 | +-include_lib("erlcloud/include/erlcloud_aws.hrl"). |
| 29 | +-include_lib("eunit/include/eunit.hrl"). |
| 30 | + |
| 31 | +-define(TEST_BUCKET, "riak-test-bucket"). |
| 32 | + |
| 33 | +confirm() -> |
| 34 | + Config = [{riak, rtcs:riak_config()}, {stanchion, rtcs:stanchion_config()}, |
| 35 | + {cs, |
| 36 | + [{riakc, [{mapred_timeout,1}]}] %% make storage calc timeout |
| 37 | + ++ rtcs:cs_config([{storage_archive_period, 1}])}], |
| 38 | + {UserConfig, {_RiakNodes, CSNodes, _Stanchion}} = rtcs:setup(4, Config), |
| 39 | + |
| 40 | + Begin = rtcs:datetime(), |
| 41 | + run_storage_batch(hd(CSNodes)), |
| 42 | + lager:info("creating bucket ~p", [?TEST_BUCKET]), |
| 43 | + ?assertEqual(ok, erlcloud_s3:create_bucket(?TEST_BUCKET, UserConfig)), |
| 44 | + |
| 45 | + N = 1024, |
| 46 | + lager:info("creating ~p objects in ~p", [N, ?TEST_BUCKET]), |
| 47 | + ok = etoomanyobjects(N, UserConfig), |
| 48 | + timer:sleep(1000), |
| 49 | + |
| 50 | + run_storage_batch(hd(CSNodes)), |
| 51 | + timer:sleep(1000), |
| 52 | + End = rtcs:datetime(), |
| 53 | + |
| 54 | + assert_storage_stats(UserConfig, Begin, End), |
| 55 | + pass. |
| 56 | + |
| 57 | +assert_storage_stats(UserConfig, Begin, End) -> |
| 58 | + KeyId = UserConfig#aws_config.access_key_id, |
| 59 | + StatsKey = lists:flatten(["usage/", KeyId, "/bj/", Begin, "/", End, "/"]), |
| 60 | + GetResult = erlcloud_s3:get_object("riak-cs", StatsKey, UserConfig), |
| 61 | + lager:info("Storage stats response: ~p", [GetResult]), |
| 62 | + Usage = mochijson2:decode(proplists:get_value(content, GetResult)), |
| 63 | + lager:info("Storage Usage: ~p", [Usage]), |
| 64 | + Samples = rtcs:json_get([<<"Storage">>, <<"Samples">>], Usage), |
| 65 | + |
| 66 | + ?assert(lists:any( |
| 67 | + fun(Sample) -> |
| 68 | + case rtcs:json_get(list_to_binary(?TEST_BUCKET), Sample) of |
| 69 | + notfound -> false; |
| 70 | + ErrorStr -> |
| 71 | + ?assert(not is_integer(ErrorStr)), |
| 72 | + ?assertEqual(<<"{error,{timeout,[]}}">>, ErrorStr), |
| 73 | + true |
| 74 | + end |
| 75 | + end, |
| 76 | + Samples)). |
| 77 | + %% supposed to be "{error, timeout}" |
| 78 | + |
| 79 | +run_storage_batch(CSNode) -> |
| 80 | + {ok, Status0} = rpc:call(CSNode, riak_cs_storage_d, status, []), |
| 81 | + lager:info("~p", [Status0]), |
| 82 | + ok = rpc:call(CSNode, riak_cs_storage_d, start_batch, [[{recalc,true}]]), |
| 83 | + {ok, Status1} = rpc:call(CSNode, riak_cs_storage_d, status, []), |
| 84 | + lager:info("~p", [Status1]), |
| 85 | + %%{ok, |
| 86 | + %% {calculating,[{schedule,[]},{last,undefined},{current,{{2013,12,26},{3,55,29}}}, |
| 87 | + %% {next,undefined},{elapsed,0},{users_done,1},{users_skipped,0},{users_left,0}]}} |
| 88 | + |
| 89 | + {_Status, Result} = Status1, |
| 90 | + 1 = proplists:get_value(users_done,Result), |
| 91 | + 0 = proplists:get_value(users_skipped,Result), |
| 92 | + 0 = proplists:get_value(users_left,Result). |
| 93 | + |
| 94 | +etoomanyobjects(N, UserConfig) -> |
| 95 | + SingleBlock = crypto:rand_bytes(400), |
| 96 | + lists:map(fun(I) -> |
| 97 | + R = erlcloud_s3:put_object(?TEST_BUCKET, integer_to_list(I), |
| 98 | + SingleBlock, UserConfig), |
| 99 | + [{version_id,"null"}] = R |
| 100 | + end, |
| 101 | + lists:seq(1,N)), |
| 102 | + ok. |
0 commit comments