From 09399f803718f07c338641c6c12c9810b7680fb8 Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Tue, 22 Oct 2019 11:36:12 +1000 Subject: [PATCH] Fix aggs integration tests where buckets can be empty This commit fixes integration tests for aggregations that use a date_histogram aggregation, where a bucker may have no documents with a specific seed value. For example, build.bat seed:41075 integrate 7.4.0 "readonly" --- .../BucketScript/BucketScriptAggregationUsageTests.cs | 3 +++ .../Pipeline/Derivative/DerivativeAggregationUsageTests.cs | 3 +++ .../MovingAverageEwmaAggregationUsageTests.cs | 3 +++ .../MovingAverageHoltLinearAggregationUsageTests.cs | 5 ++++- .../MovingAverageHoltWintersAggregationUsageTests.cs | 7 +++++-- .../MovingAverageSimpleAggregationUsageTests.cs | 5 ++++- .../SerialDifferencingAggregationUsageTests.cs | 5 ++++- 7 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/Tests/Tests/Aggregations/Pipeline/BucketScript/BucketScriptAggregationUsageTests.cs b/src/Tests/Tests/Aggregations/Pipeline/BucketScript/BucketScriptAggregationUsageTests.cs index 8218893723a..62b6a8260cf 100644 --- a/src/Tests/Tests/Aggregations/Pipeline/BucketScript/BucketScriptAggregationUsageTests.cs +++ b/src/Tests/Tests/Aggregations/Pipeline/BucketScript/BucketScriptAggregationUsageTests.cs @@ -20,6 +20,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage { field = "startedOn", interval = "month", + min_doc_count = 1 }, aggs = new { @@ -77,6 +78,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage .DateHistogram("projects_started_per_month", dh => dh .Field(p => p.StartedOn) .Interval(DateInterval.Month) + .MinimumDocumentCount(1) .Aggregations(aa => aa .Sum("commits", sm => sm .Field(p => p.NumberOfCommits) @@ -106,6 +108,7 @@ public BucketScriptAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage { Field = "startedOn", Interval = DateInterval.Month, + MinimumDocumentCount = 1, Aggregations = new SumAggregation("commits", "numberOfCommits") && new FilterAggregation("stable_state") diff --git a/src/Tests/Tests/Aggregations/Pipeline/Derivative/DerivativeAggregationUsageTests.cs b/src/Tests/Tests/Aggregations/Pipeline/Derivative/DerivativeAggregationUsageTests.cs index 42f45cd2f7b..e737cc25a6f 100644 --- a/src/Tests/Tests/Aggregations/Pipeline/Derivative/DerivativeAggregationUsageTests.cs +++ b/src/Tests/Tests/Aggregations/Pipeline/Derivative/DerivativeAggregationUsageTests.cs @@ -21,6 +21,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us { field = "startedOn", interval = "month", + min_doc_count = 1 }, aggs = new { @@ -47,6 +48,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us .DateHistogram("projects_started_per_month", dh => dh .Field(p => p.StartedOn) .Interval(DateInterval.Month) + .MinimumDocumentCount(1) .Aggregations(aa => aa .Sum("commits", sm => sm .Field(p => p.NumberOfCommits) @@ -62,6 +64,7 @@ public DerivativeAggregationUsageTests(ReadOnlyCluster cluster, EndpointUsage us { Field = "startedOn", Interval = DateInterval.Month, + MinimumDocumentCount = 1, Aggregations = new SumAggregation("commits", "numberOfCommits") && new DerivativeAggregation("commits_derivative", "commits") diff --git a/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageEwmaAggregationUsageTests.cs b/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageEwmaAggregationUsageTests.cs index 0784f88d2b1..b270199602d 100644 --- a/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageEwmaAggregationUsageTests.cs +++ b/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageEwmaAggregationUsageTests.cs @@ -23,6 +23,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU { field = "startedOn", interval = "month", + min_doc_count = 1 }, aggs = new { @@ -54,6 +55,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU .DateHistogram("projects_started_per_month", dh => dh .Field(p => p.StartedOn) .Interval(DateInterval.Month) + .MinimumDocumentCount(1) .Aggregations(aa => aa .Sum("commits", sm => sm .Field(p => p.NumberOfCommits) @@ -74,6 +76,7 @@ public MovingAverageEwmaAggregationUsageTests(ReadOnlyCluster cluster, EndpointU { Field = "startedOn", Interval = DateInterval.Month, + MinimumDocumentCount = 1, Aggregations = new SumAggregation("commits", "numberOfCommits") && new MovingAverageAggregation("commits_moving_avg", "commits") diff --git a/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltLinearAggregationUsageTests.cs b/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltLinearAggregationUsageTests.cs index ed8c1c520ab..66ef05d7cde 100644 --- a/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltLinearAggregationUsageTests.cs +++ b/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltLinearAggregationUsageTests.cs @@ -22,7 +22,8 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End date_histogram = new { field = "startedOn", - interval = "month" + interval = "month", + min_doc_count = 1 }, aggs = new { @@ -55,6 +56,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End .DateHistogram("projects_started_per_month", dh => dh .Field(p => p.StartedOn) .Interval(DateInterval.Month) + .MinimumDocumentCount(1) .Aggregations(aa => aa .Sum("commits", sm => sm.Field(p => p.NumberOfCommits)) .MovingAverage("commits_moving_avg", mv => mv @@ -74,6 +76,7 @@ public MovingAverageHoltLinearAggregationUsageTests(ReadOnlyCluster cluster, End { Field = "startedOn", Interval = DateInterval.Month, + MinimumDocumentCount = 1, Aggregations = new SumAggregation("commits", "numberOfCommits") && new MovingAverageAggregation("commits_moving_avg", "commits") diff --git a/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltWintersAggregationUsageTests.cs b/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltWintersAggregationUsageTests.cs index dd49ee1ee95..8bd3d24c4e6 100644 --- a/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltWintersAggregationUsageTests.cs +++ b/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageHoltWintersAggregationUsageTests.cs @@ -21,7 +21,8 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage date_histogram = new { field = "startedOn", - interval = "month" + interval = "month", + min_doc_count = 1 }, aggs = new { @@ -59,6 +60,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage .DateHistogram("projects_started_per_month", dh => dh .Field(p => p.StartedOn) .Interval(DateInterval.Month) + .MinimumDocumentCount(1) .Aggregations(aa => aa .Sum("commits", sm => sm .Field(p => p.NumberOfCommits) @@ -85,6 +87,7 @@ public MovingAverageHoltWintersUsageTests(ReadOnlyCluster cluster, EndpointUsage { Field = "startedOn", Interval = DateInterval.Month, + MinimumDocumentCount = 1, Aggregations = new SumAggregation("commits", "numberOfCommits") && new MovingAverageAggregation("commits_moving_avg", "commits") @@ -124,7 +127,7 @@ protected override void ExpectResponse(ISearchResponse response) var movingAverage = item.MovingAverage("commits_moving_avg"); // Moving Average specifies a window of 4 so - // moving average values should exist from 5th bucketr onwards + // moving average values should exist from 5th bucket onwards if (bucketCount <= 4) movingAverage.Should().BeNull(); else diff --git a/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageSimpleAggregationUsageTests.cs b/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageSimpleAggregationUsageTests.cs index 2c9c91cd753..82e6f7fd12c 100644 --- a/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageSimpleAggregationUsageTests.cs +++ b/src/Tests/Tests/Aggregations/Pipeline/MovingAverage/MovingAverageSimpleAggregationUsageTests.cs @@ -22,7 +22,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin date_histogram = new { field = "startedOn", - interval = "month", + interval = "month" }, aggs = new { @@ -41,6 +41,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin model = "simple", window = 30, predict = 10, + gap_policy = "insert_zeros", settings = new { } } } @@ -61,6 +62,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin .BucketsPath("commits") .Window(30) .Predict(10) + .GapPolicy(GapPolicy.InsertZeros) .Model(m => m .Simple() ) @@ -79,6 +81,7 @@ public MovingAverageSimpleAggregationUsageTests(ReadOnlyCluster cluster, Endpoin { Window = 30, Predict = 10, + GapPolicy = GapPolicy.InsertZeros, Model = new SimpleModel() } }; diff --git a/src/Tests/Tests/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregationUsageTests.cs b/src/Tests/Tests/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregationUsageTests.cs index ea7e42c121c..a21781c8584 100644 --- a/src/Tests/Tests/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregationUsageTests.cs +++ b/src/Tests/Tests/Aggregations/Pipeline/SerialDifferencing/SerialDifferencingAggregationUsageTests.cs @@ -19,7 +19,8 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint date_histogram = new { field = "startedOn", - interval = "month" + interval = "month", + min_doc_count = 1 }, aggs = new { @@ -47,6 +48,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint .DateHistogram("projects_started_per_month", dh => dh .Field(p => p.StartedOn) .Interval(DateInterval.Month) + .MinimumDocumentCount(1) .Aggregations(aa => aa .Sum("commits", sm => sm .Field(p => p.NumberOfCommits) @@ -63,6 +65,7 @@ public SerialDifferencingAggregationUsageTests(ReadOnlyCluster cluster, Endpoint { Field = "startedOn", Interval = DateInterval.Month, + MinimumDocumentCount = 1, Aggregations = new SumAggregation("commits", "numberOfCommits") && new SerialDifferencingAggregation("second_difference", "commits")