Skip to content

Commit 1228084

Browse files
committed
Fix tests on InternalAggregation that rely on equals/hashCode.
1 parent 1d3f6c4 commit 1228084

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

core/src/test/java/org/elasticsearch/search/aggregations/InternalAggregationTestCase.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.elasticsearch.test.AbstractWireSerializingTestCase;
3030

3131
import java.util.ArrayList;
32+
import java.util.Collections;
3233
import java.util.HashMap;
3334
import java.util.List;
3435
import java.util.Map;
@@ -62,16 +63,19 @@ public final void testReduceRandom() {
6263
ScriptService mockScriptService = mockScriptService();
6364
MockBigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService());
6465
if (randomBoolean() && toReduce.size() > 1) {
65-
// we leave at least the first element in the list
66-
List<InternalAggregation> internalAggregations = randomSubsetOf(randomIntBetween(1, toReduceSize - 1),
67-
toReduce.subList(1, toReduceSize));
68-
InternalAggregation.ReduceContext context = new InternalAggregation.ReduceContext(bigArrays, mockScriptService, false);
66+
Collections.shuffle(toReduce, random());
67+
// we leave at least one element in the list
68+
int r = Math.max(1, randomIntBetween(0, toReduceSize - 2));
69+
List<InternalAggregation> internalAggregations = toReduce.subList(0, r);
70+
InternalAggregation.ReduceContext context =
71+
new InternalAggregation.ReduceContext(bigArrays, mockScriptService, false);
6972
@SuppressWarnings("unchecked")
7073
T reduced = (T) inputs.get(0).reduce(internalAggregations, context);
71-
toReduce.removeAll(internalAggregations);
74+
toReduce = toReduce.subList(r, toReduceSize);
7275
toReduce.add(reduced);
7376
}
74-
InternalAggregation.ReduceContext context = new InternalAggregation.ReduceContext(bigArrays, mockScriptService, true);
77+
InternalAggregation.ReduceContext context =
78+
new InternalAggregation.ReduceContext(bigArrays, mockScriptService, true);
7579
@SuppressWarnings("unchecked")
7680
T reduced = (T) inputs.get(0).reduce(toReduce, context);
7781
assertReduced(reduced, inputs);

core/src/test/java/org/elasticsearch/search/aggregations/metrics/valuecount/InternalValueCountTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ protected InternalValueCount createTestInstance(String name,
3737

3838
@Override
3939
protected void assertReduced(InternalValueCount reduced, List<InternalValueCount> inputs) {
40-
assertEquals(inputs.stream().mapToDouble(InternalValueCount::value).sum(), reduced.getValue(), 0);
40+
assertEquals(inputs.stream().mapToLong(InternalValueCount::getValue).sum(), reduced.getValue(), 0);
4141
}
4242

4343
@Override

0 commit comments

Comments
 (0)