From 1228084c1c691be8a481ffe6c6e97a8bc859642b Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Thu, 2 Mar 2017 10:38:16 +0100 Subject: [PATCH] Fix tests on InternalAggregation that rely on equals/hashCode. --- .../InternalAggregationTestCase.java | 16 ++++++++++------ .../valuecount/InternalValueCountTests.java | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java index 17694b8868d..f5a06e09fd3 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java @@ -29,6 +29,7 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.test.AbstractWireSerializingTestCase; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -62,16 +63,19 @@ public abstract class InternalAggregationTestCase ScriptService mockScriptService = mockScriptService(); MockBigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); if (randomBoolean() && toReduce.size() > 1) { - // we leave at least the first element in the list - List internalAggregations = randomSubsetOf(randomIntBetween(1, toReduceSize - 1), - toReduce.subList(1, toReduceSize)); - InternalAggregation.ReduceContext context = new InternalAggregation.ReduceContext(bigArrays, mockScriptService, false); + Collections.shuffle(toReduce, random()); + // we leave at least one element in the list + int r = Math.max(1, randomIntBetween(0, toReduceSize - 2)); + List internalAggregations = toReduce.subList(0, r); + InternalAggregation.ReduceContext context = + new InternalAggregation.ReduceContext(bigArrays, mockScriptService, false); @SuppressWarnings("unchecked") T reduced = (T) inputs.get(0).reduce(internalAggregations, context); - toReduce.removeAll(internalAggregations); + toReduce = toReduce.subList(r, toReduceSize); toReduce.add(reduced); } - InternalAggregation.ReduceContext context = new InternalAggregation.ReduceContext(bigArrays, mockScriptService, true); + InternalAggregation.ReduceContext context = + new InternalAggregation.ReduceContext(bigArrays, mockScriptService, true); @SuppressWarnings("unchecked") T reduced = (T) inputs.get(0).reduce(toReduce, context); assertReduced(reduced, inputs); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java index ef130655368..3de87898778 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java @@ -37,7 +37,7 @@ public class InternalValueCountTests extends InternalAggregationTestCase inputs) { - assertEquals(inputs.stream().mapToDouble(InternalValueCount::value).sum(), reduced.getValue(), 0); + assertEquals(inputs.stream().mapToLong(InternalValueCount::getValue).sum(), reduced.getValue(), 0); } @Override