Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 95C5011455 for ; Mon, 11 Aug 2014 20:19:39 +0000 (UTC) Received: (qmail 76404 invoked by uid 500); 11 Aug 2014 20:19:35 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 75922 invoked by uid 500); 11 Aug 2014 20:19:34 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 75301 invoked by uid 99); 11 Aug 2014 20:19:34 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Aug 2014 20:19:34 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 5A17581408B; Mon, 11 Aug 2014 20:19:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chewbranca@apache.org To: commits@couchdb.apache.org Date: Mon, 11 Aug 2014 20:19:57 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [25/50] couch commit: updated refs/heads/1963-eunit-bigcouch to 6845303 Port 121-stats-aggregates.t etap test suite to eunit Merged into couch_stats_tests suite. Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/af2eae0c Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/af2eae0c Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/af2eae0c Branch: refs/heads/1963-eunit-bigcouch Commit: af2eae0cea70e158c9e10a0f397b2a3af9a3ce44 Parents: bcf2dc3 Author: Alexander Shorin Authored: Tue May 27 18:27:53 2014 +0400 Committer: Russell Branca Committed: Mon Aug 11 13:10:25 2014 -0700 ---------------------------------------------------------------------- test/couchdb/couch_stats_tests.erl | 225 ++++++++++++++++++- .../couchdb/fixtures/couch_stats_aggregates.cfg | 19 ++ .../couchdb/fixtures/couch_stats_aggregates.ini | 20 ++ 3 files changed, 261 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/af2eae0c/test/couchdb/couch_stats_tests.erl ---------------------------------------------------------------------- diff --git a/test/couchdb/couch_stats_tests.erl b/test/couchdb/couch_stats_tests.erl index aaaa687..d156449 100644 --- a/test/couchdb/couch_stats_tests.erl +++ b/test/couchdb/couch_stats_tests.erl @@ -15,18 +15,41 @@ -include("couch_eunit.hrl"). -include_lib("couchdb/couch_db.hrl"). +-define(STATS_CFG_FIXTURE, + filename:join([?FIXTURESDIR, "couch_stats_aggregates.cfg"])). +-define(STATS_INI_FIXTURE, + filename:join([?FIXTURESDIR, "couch_stats_aggregates.ini"])). -define(TIMEOUT, 1000). --define(SLEEPTIME, 100). +-define(TIMEWAIT, 500). setup_collector() -> couch_stats_collector:start(), ok. +setup_aggregator(_) -> + {ok, Pid} = couch_config:start_link([?STATS_INI_FIXTURE]), + {ok, _} = couch_stats_collector:start(), + {ok, _} = couch_stats_aggregator:start(?STATS_CFG_FIXTURE), + Pid. + teardown_collector(_) -> couch_stats_collector:stop(), ok. +teardown_aggregator(_, Pid) -> + couch_stats_aggregator:stop(), + couch_stats_collector:stop(), + erlang:monitor(process, Pid), + couch_config:stop(), + receive + {'DOWN', _, _, Pid, _} -> + ok + after ?TIMEOUT -> + throw({timeout, config_stop}) + end, + ok. + couch_stats_collector_test_() -> { @@ -51,6 +74,39 @@ couch_stats_collector_test_() -> } }. +couch_stats_aggregator_test_() -> + Funs = [ + fun should_init_empty_aggregate/2, + fun should_get_empty_aggregate/2, + fun should_change_stats_on_values_add/2, + fun should_change_stats_for_all_times_on_values_add/2, + fun should_change_stats_on_values_change/2, + fun should_change_stats_for_all_times_on_values_change/2, + fun should_not_remove_data_after_some_time_for_0_sample/2, + fun should_remove_data_after_some_time_for_other_samples/2 + ], + { + "CouchDB stats aggregator tests", + [ + { + "Absolute values", + { + foreachx, + fun setup_aggregator/1, fun teardown_aggregator/2, + [{absolute, Fun} || Fun <- Funs] + } + }, + { + "Counters", + { + foreachx, + fun setup_aggregator/1, fun teardown_aggregator/2, + [{counter, Fun} || Fun <- Funs] + } + } + ] + }. + should_increment_counter() -> ?_assertEqual(100, @@ -122,7 +178,7 @@ should_decrement_counter_on_process_exit() -> end, % sleep for awhile to let collector handle the updates % suddenly, it couldn't notice process death instantly - timer:sleep(?SLEEPTIME), + timer:sleep(?TIMEWAIT), couch_stats_collector:get(hoopla) end). @@ -138,7 +194,7 @@ should_decrement_for_each_track_process_count_call_on_exit() -> after ?TIMEOUT -> throw(timeout) end, - timer:sleep(?SLEEPTIME), + timer:sleep(?TIMEWAIT), couch_stats_collector:get(hoopla) end). @@ -170,6 +226,158 @@ should_return_absolute_values() -> lists:sort(couch_stats_collector:all(absolute)) end). +should_init_empty_aggregate(absolute, _) -> + {Aggs} = couch_stats_aggregator:all(), + ?_assertEqual({[{'11', make_agg(<<"randomosity">>, + null, null, null, null, null)}]}, + couch_util:get_value(number, Aggs)); +should_init_empty_aggregate(counter, _) -> + {Aggs} = couch_stats_aggregator:all(), + ?_assertEqual({[{stuff, make_agg(<<"yay description">>, + null, null, null, null, null)}]}, + couch_util:get_value(testing, Aggs)). + +should_get_empty_aggregate(absolute, _) -> + ?_assertEqual(make_agg(<<"randomosity">>, null, null, null, null, null), + couch_stats_aggregator:get_json({number, '11'})); +should_get_empty_aggregate(counter, _) -> + ?_assertEqual(make_agg(<<"yay description">>, null, null, null, null, null), + couch_stats_aggregator:get_json({testing, stuff})). + +should_change_stats_on_values_add(absolute, _) -> + lists:foreach(fun(X) -> + couch_stats_collector:record({number, 11}, X) + end, lists:seq(0, 10)), + couch_stats_aggregator:collect_sample(), + ?_assertEqual(make_agg(<<"randomosity">>, 5.0, 5.0, null, 5.0, 5.0), + couch_stats_aggregator:get_json({number, 11})); +should_change_stats_on_values_add(counter, _) -> + lists:foreach(fun(_) -> + couch_stats_collector:increment({testing, stuff}) + end, lists:seq(1, 100)), + couch_stats_aggregator:collect_sample(), + ?_assertEqual(make_agg(<<"yay description">>, 100.0, 100.0, null, 100, 100), + couch_stats_aggregator:get_json({testing, stuff})). + +should_change_stats_for_all_times_on_values_add(absolute, _) -> + lists:foreach(fun(X) -> + couch_stats_collector:record({number, 11}, X) + end, lists:seq(0, 10)), + couch_stats_aggregator:collect_sample(), + ?_assertEqual(make_agg(<<"randomosity">>, 5.0, 5.0, null, 5.0, 5.0), + couch_stats_aggregator:get_json({number, 11}, 1)); +should_change_stats_for_all_times_on_values_add(counter, _) -> + lists:foreach(fun(_) -> + couch_stats_collector:increment({testing, stuff}) + end, lists:seq(1, 100)), + couch_stats_aggregator:collect_sample(), + ?_assertEqual(make_agg(<<"yay description">>, 100.0, 100.0, null, 100, 100), + couch_stats_aggregator:get_json({testing, stuff}, 1)). + +should_change_stats_on_values_change(absolute, _) -> + ?_assertEqual(make_agg(<<"randomosity">>, 20.0, 10.0, 7.071, 5.0, 15.0), + begin + lists:foreach(fun(X) -> + couch_stats_collector:record({number, 11}, X) + end, lists:seq(0, 10)), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_collector:record({number, 11}, 15), + couch_stats_aggregator:collect_sample(), + couch_stats_aggregator:get_json({number, 11}) + end); +should_change_stats_on_values_change(counter, _) -> + ?_assertEqual(make_agg(<<"yay description">>, 100.0, 50.0, 70.711, 0, 100), + begin + lists:foreach(fun(_) -> + couch_stats_collector:increment({testing, stuff}) + end, lists:seq(1, 100)), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_aggregator:collect_sample(), + couch_stats_aggregator:get_json({testing, stuff}) + end). + +should_change_stats_for_all_times_on_values_change(absolute, _) -> + ?_assertEqual(make_agg(<<"randomosity">>, 20.0, 10.0, 7.071, 5.0, 15.0), + begin + lists:foreach(fun(X) -> + couch_stats_collector:record({number, 11}, X) + end, lists:seq(0, 10)), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_collector:record({number, 11}, 15), + couch_stats_aggregator:collect_sample(), + couch_stats_aggregator:get_json({number, 11}, 1) + end); +should_change_stats_for_all_times_on_values_change(counter, _) -> + ?_assertEqual(make_agg(<<"yay description">>, 100.0, 50.0, 70.711, 0, 100), + begin + lists:foreach(fun(_) -> + couch_stats_collector:increment({testing, stuff}) + end, lists:seq(1, 100)), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_aggregator:collect_sample(), + couch_stats_aggregator:get_json({testing, stuff}, 1) + end). + +should_not_remove_data_after_some_time_for_0_sample(absolute, _) -> + ?_assertEqual(make_agg(<<"randomosity">>, 20.0, 10.0, 7.071, 5.0, 15.0), + begin + lists:foreach(fun(X) -> + couch_stats_collector:record({number, 11}, X) + end, lists:seq(0, 10)), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_collector:record({number, 11}, 15), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_aggregator:collect_sample(), + couch_stats_aggregator:get_json({number, 11}) + end); +should_not_remove_data_after_some_time_for_0_sample(counter, _) -> + ?_assertEqual(make_agg(<<"yay description">>, 100.0, 33.333, 57.735, 0, 100), + begin + lists:foreach(fun(_) -> + couch_stats_collector:increment({testing, stuff}) + end, lists:seq(1, 100)), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_aggregator:collect_sample(), + couch_stats_aggregator:get_json({testing, stuff}) + end). + +should_remove_data_after_some_time_for_other_samples(absolute, _) -> + ?_assertEqual(make_agg(<<"randomosity">>, 15.0, 15.0, null, 15.0, 15.0), + begin + lists:foreach(fun(X) -> + couch_stats_collector:record({number, 11}, X) + end, lists:seq(0, 10)), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_collector:record({number, 11}, 15), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_aggregator:collect_sample(), + couch_stats_aggregator:get_json({number, 11}, 1) + end); +should_remove_data_after_some_time_for_other_samples(counter, _) -> + ?_assertEqual(make_agg(<<"yay description">>, 0, 0.0, 0.0, 0, 0), + begin + lists:foreach(fun(_) -> + couch_stats_collector:increment({testing, stuff}) + end, lists:seq(1, 100)), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_aggregator:collect_sample(), + timer:sleep(?TIMEWAIT), + couch_stats_aggregator:collect_sample(), + couch_stats_aggregator:get_json({testing, stuff}, 1) + end). + spawn_and_count(N) -> Self = self(), @@ -191,3 +399,14 @@ repeat(_, 0) -> repeat(Fun, Count) -> Fun(), repeat(Fun, Count-1). + +make_agg(Desc, Sum, Mean, StdDev, Min, Max) -> + {[ + {description, Desc}, + {current, Sum}, + {sum, Sum}, + {mean, Mean}, + {stddev, StdDev}, + {min, Min}, + {max, Max} + ]}. http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/af2eae0c/test/couchdb/fixtures/couch_stats_aggregates.cfg ---------------------------------------------------------------------- diff --git a/test/couchdb/fixtures/couch_stats_aggregates.cfg b/test/couchdb/fixtures/couch_stats_aggregates.cfg new file mode 100644 index 0000000..30e475d --- /dev/null +++ b/test/couchdb/fixtures/couch_stats_aggregates.cfg @@ -0,0 +1,19 @@ +% Licensed to the Apache Software Foundation (ASF) under one +% or more contributor license agreements. See the NOTICE file +% distributed with this work for additional information +% regarding copyright ownership. The ASF licenses this file +% 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. + +{testing, stuff, "yay description"}. +{number, '11', "randomosity"}. http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/af2eae0c/test/couchdb/fixtures/couch_stats_aggregates.ini ---------------------------------------------------------------------- diff --git a/test/couchdb/fixtures/couch_stats_aggregates.ini b/test/couchdb/fixtures/couch_stats_aggregates.ini new file mode 100644 index 0000000..cc5cd21 --- /dev/null +++ b/test/couchdb/fixtures/couch_stats_aggregates.ini @@ -0,0 +1,20 @@ +; Licensed to the Apache Software Foundation (ASF) under one +; or more contributor license agreements. See the NOTICE file +; distributed with this work for additional information +; regarding copyright ownership. The ASF licenses this file +; 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. + +[stats] +rate = 10000000 ; We call collect_sample in testing +samples = [0, 1]