|
29 | 29 | import org.elasticsearch.test.AbstractWireSerializingTestCase; |
30 | 30 |
|
31 | 31 | import java.util.ArrayList; |
| 32 | +import java.util.Collections; |
32 | 33 | import java.util.HashMap; |
33 | 34 | import java.util.List; |
34 | 35 | import java.util.Map; |
@@ -62,16 +63,19 @@ public final void testReduceRandom() { |
62 | 63 | ScriptService mockScriptService = mockScriptService(); |
63 | 64 | MockBigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); |
64 | 65 | 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); |
69 | 72 | @SuppressWarnings("unchecked") |
70 | 73 | T reduced = (T) inputs.get(0).reduce(internalAggregations, context); |
71 | | - toReduce.removeAll(internalAggregations); |
| 74 | + toReduce = toReduce.subList(r, toReduceSize); |
72 | 75 | toReduce.add(reduced); |
73 | 76 | } |
74 | | - InternalAggregation.ReduceContext context = new InternalAggregation.ReduceContext(bigArrays, mockScriptService, true); |
| 77 | + InternalAggregation.ReduceContext context = |
| 78 | + new InternalAggregation.ReduceContext(bigArrays, mockScriptService, true); |
75 | 79 | @SuppressWarnings("unchecked") |
76 | 80 | T reduced = (T) inputs.get(0).reduce(toReduce, context); |
77 | 81 | assertReduced(reduced, inputs); |
|
0 commit comments