From 35fe5cfef4119da7f838a788e13634a0b453bd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 15 Jun 2018 11:52:00 +0200 Subject: [PATCH] [Tests] Fix edge case in ScriptedMetricAggregatorTests An expected exception is only thrown when there are documents in the index created in the test setup. Fixed the test by making sure there is at least one. Closes #31307 --- .../scripted/ScriptedMetricAggregatorTests.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java index 9417cc092d828..7a7c66d21aada 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorTests.java @@ -118,7 +118,7 @@ public static void initMockScripts() { SCRIPTS.put("initScriptParams", params -> { Map agg = (Map) params.get("_agg"); Integer initialValue = (Integer)params.get("initialValue"); - ArrayList collector = new ArrayList(); + ArrayList collector = new ArrayList<>(); collector.add(initialValue); agg.put("collector", collector); return agg; @@ -175,7 +175,6 @@ public void testNoDocs() throws IOException { /** * without combine script, the "_aggs" map should contain a list of the size of the number of documents matched */ - @SuppressWarnings("unchecked") public void testScriptedMetricWithoutCombine() throws IOException { try (Directory directory = newDirectory()) { int numDocs = randomInt(100); @@ -190,8 +189,11 @@ public void testScriptedMetricWithoutCombine() throws IOException { ScriptedMetric scriptedMetric = search(newSearcher(indexReader, true, true), new MatchAllDocsQuery(), aggregationBuilder); assertEquals(AGG_NAME, scriptedMetric.getName()); assertNotNull(scriptedMetric.aggregation()); + @SuppressWarnings("unchecked") Map agg = (Map) scriptedMetric.aggregation(); - assertEquals(numDocs, ((List) agg.get("collector")).size()); + @SuppressWarnings("unchecked") + List list = (List) agg.get("collector"); + assertEquals(numDocs, list.size()); } } } @@ -300,10 +302,9 @@ public void testSelfReferencingAggStateAfterInit() throws IOException { } } - @AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/31307") public void testSelfReferencingAggStateAfterMap() throws IOException { try (Directory directory = newDirectory()) { - Integer numDocs = randomInt(100); + Integer numDocs = randomIntBetween(1, 100); try (RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory)) { for (int i = 0; i < numDocs; i++) { indexWriter.addDocument(singleton(new SortedNumericDocValuesField("number", i)));