You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/07/31 23:25:32 UTC
[44/50] folsom commit: updated refs/heads/import-master to 4824aec
Added a test case for downsizing sliding window
Project: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/commit/13549b40
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/tree/13549b40
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-folsom/diff/13549b40
Branch: refs/heads/import-master
Commit: 13549b407dbedd6fdb78dfd665727882b98735c9
Parents: 5694f42
Author: Vasco <va...@vas.io>
Authored: Thu Jan 9 19:24:18 2014 +0000
Committer: Vasco <va...@vas.io>
Committed: Thu Jan 9 19:24:18 2014 +0000
----------------------------------------------------------------------
src/folsom_sample_slide.erl | 2 +-
src/folsom_sample_slide_uniform.erl | 2 +-
test/folsom_sample_slide_test.erl | 59 +++++++++++++++++++++++++++++---
3 files changed, 57 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/13549b40/src/folsom_sample_slide.erl
----------------------------------------------------------------------
diff --git a/src/folsom_sample_slide.erl b/src/folsom_sample_slide.erl
index b82acf9..e1dd455 100644
--- a/src/folsom_sample_slide.erl
+++ b/src/folsom_sample_slide.erl
@@ -29,7 +29,7 @@
get_values/1,
moment/0,
trim/2,
- resize/2
+ resize/2
]).
-include("folsom.hrl").
http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/13549b40/src/folsom_sample_slide_uniform.erl
----------------------------------------------------------------------
diff --git a/src/folsom_sample_slide_uniform.erl b/src/folsom_sample_slide_uniform.erl
index d99373f..906e5d8 100644
--- a/src/folsom_sample_slide_uniform.erl
+++ b/src/folsom_sample_slide_uniform.erl
@@ -29,7 +29,7 @@
get_values/1,
moment/0,
trim/2,
- resize/2
+ resize/2
]).
-include("folsom.hrl").
http://git-wip-us.apache.org/repos/asf/couchdb-folsom/blob/13549b40/test/folsom_sample_slide_test.erl
----------------------------------------------------------------------
diff --git a/test/folsom_sample_slide_test.erl b/test/folsom_sample_slide_test.erl
index dc08d95..dc88bc9 100644
--- a/test/folsom_sample_slide_test.erl
+++ b/test/folsom_sample_slide_test.erl
@@ -44,8 +44,11 @@ slide_test_() ->
fun create/0},
{"test sliding window",
{timeout, 30, fun exercise/0}},
- {"resize sliding window",
- {timeout, 30, fun resize_window/0}}
+ {"resize sliding window (expand)",
+ {timeout, 30, fun expand_window/0}},
+ {"resize sliding window (shrink)",
+ {timeout, 30, fun shrink_window/0}}
+
]}.
create() ->
@@ -91,7 +94,7 @@ exercise() ->
check_table(Slide, []),
ok.
-resize_window() ->
+expand_window() ->
%% create a new histogram
%% will leave the trim server running, as resize() needs it
ok = folsom_metrics:new_histogram(?HISTO2, slide, ?WINDOW),
@@ -114,7 +117,7 @@ resize_window() ->
Values = lists:sort(folsom_sample_slide:get_values(Slide)),
?assertEqual(ExpectedValues, Values),
- %%resize the sliding window
+ %%expand the sliding window
NewSlide = folsom_sample_slide:resize(Slide, ?DOUBLE_WINDOW),
%% get values only returns last ?WINDOW*2 seconds
@@ -136,6 +139,54 @@ resize_window() ->
Trimmed2 = folsom_sample_slide:trim(NewSlide#slide.reservoir, ?DOUBLE_WINDOW),
?assertEqual((?RUNTIME * ?READINGS) - ((?RUNTIME - ?DOUBLE_WINDOW - 1) * ?READINGS), Trimmed2),
check_table(NewSlide, []),
+ ok = folsom_metrics:delete_metric(?HISTO2).
+
+
+shrink_window() ->
+ %% create a new histogram
+ %% will leave the trim server running, as resize() needs it
+ ok = folsom_metrics:new_histogram(?HISTO2, slide, ?DOUBLE_WINDOW),
+ #histogram{sample=Slide} = folsom_metrics_histogram:get_value(?HISTO2),
+ Moments = lists:seq(1, ?RUNTIME ),
+ %% pump in 90 seconds worth of readings
+ Moment = lists:foldl(fun(_X, Tick) ->
+ Tock = tick(Tick),
+ [folsom_sample_slide:update(Slide, N) ||
+ N <- lists:duplicate(?READINGS, Tock)],
+ Tock end,
+ 0,
+ Moments),
+ %% are all readings in the table?
+ check_table(Slide, Moments),
+
+ %% get values only returns last ?DOUBLE_WINDOW seconds
+ ExpectedValues = lists:sort(lists:flatten([lists:duplicate(?READINGS, N) ||
+ N <- lists:seq(?RUNTIME - ?DOUBLE_WINDOW, ?RUNTIME)])),
+ Values = lists:sort(folsom_sample_slide:get_values(Slide)),
+ ?assertEqual(ExpectedValues, Values),
+
+ %%shrink the sliding window
+ NewSlide = folsom_sample_slide:resize(Slide, ?WINDOW),
+
+ %% get values only returns last ?WINDOW*2 seconds
+ NewExpectedValues = lists:sort(lists:flatten([lists:duplicate(?READINGS, N) ||
+ N <- lists:seq(?RUNTIME - ?WINDOW, ?RUNTIME)])),
+ NewValues = lists:sort(folsom_sample_slide:get_values(NewSlide)),
+ ?assertEqual(NewExpectedValues, NewValues),
+
+
+ %% trim the table
+ Trimmed = folsom_sample_slide:trim(NewSlide#slide.reservoir, ?WINDOW),
+ ?assertEqual((?RUNTIME - ?WINDOW - 1) * ?READINGS, Trimmed),
+ check_table(NewSlide, lists:seq(?RUNTIME - ?WINDOW, ?RUNTIME)),
+ %% increment the clock past the window
+ tick(Moment, ?WINDOW*2),
+ %% get values should be empty
+ ?assertEqual([], folsom_sample_slide:get_values(NewSlide)),
+ %% trim, and table should be empty
+ Trimmed2 = folsom_sample_slide:trim(NewSlide#slide.reservoir, ?WINDOW),
+ ?assertEqual((?RUNTIME * ?READINGS) - ((?RUNTIME - ?WINDOW - 1) * ?READINGS), Trimmed2),
+ check_table(NewSlide, []),
ok.
tick(Moment0, IncrBy) ->