Skip to content

Commit b6bbb1b

Browse files
fix more tests
1 parent 997dc84 commit b6bbb1b

File tree

2 files changed

+16
-73
lines changed

2 files changed

+16
-73
lines changed

x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/RollupResponseTranslationTests.java

Lines changed: 14 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -162,29 +162,14 @@ public void testMissingLiveIndex() throws Exception {
162162
SearchResponse responseWithout = mock(SearchResponse.class);
163163
when(responseWithout.getTook()).thenReturn(new TimeValue(100));
164164
List<InternalAggregation> aggTree = new ArrayList<>(1);
165-
InternalFilter filter = mock(InternalFilter.class);
166165

167166
List<InternalAggregation> subaggs = new ArrayList<>(2);
168167
Map<String, Object> metadata = Maps.newMapWithExpectedSize(1);
169168
metadata.put(RollupField.ROLLUP_META + "." + RollupField.COUNT_FIELD, "foo." + RollupField.COUNT_FIELD);
170-
Sum sum = mock(Sum.class);
171-
when(sum.value()).thenReturn(10.0);
172-
when(sum.value()).thenReturn(10.0);
173-
when(sum.getName()).thenReturn("foo");
174-
when(sum.getMetadata()).thenReturn(metadata);
175-
when(sum.getType()).thenReturn(SumAggregationBuilder.NAME);
176-
subaggs.add(sum);
177-
178-
Sum count = mock(Sum.class);
179-
when(count.value()).thenReturn(2.0);
180-
when(count.value()).thenReturn(2.0);
181-
when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD);
182-
when(count.getMetadata()).thenReturn(null);
183-
when(count.getType()).thenReturn(SumAggregationBuilder.NAME);
184-
subaggs.add(count);
185-
186-
when(filter.getAggregations()).thenReturn(InternalAggregations.from(subaggs));
187-
when(filter.getName()).thenReturn("filter_foo");
169+
subaggs.add(new Sum("foo", 10.0, DocValueFormat.RAW, metadata));
170+
subaggs.add(new Sum("foo." + RollupField.COUNT_FIELD, 2.0, DocValueFormat.RAW, null));
171+
172+
InternalFilter filter = new InternalFilter("filter_foo", 0, InternalAggregations.from(subaggs), metadata);
188173
aggTree.add(filter);
189174

190175
InternalAggregations mockAggsWithout = InternalAggregations.from(aggTree);
@@ -285,33 +270,15 @@ public void testVerifyMissingNormal() {
285270
public void testTranslateRollup() throws Exception {
286271
SearchResponse response = mock(SearchResponse.class);
287272
when(response.getTook()).thenReturn(new TimeValue(100));
288-
List<InternalAggregation> aggTree = new ArrayList<>(1);
289-
InternalFilter filter = mock(InternalFilter.class);
290273

291274
List<InternalAggregation> subaggs = new ArrayList<>(2);
292275
Map<String, Object> metadata = Maps.newMapWithExpectedSize(1);
293276
metadata.put(RollupField.ROLLUP_META + "." + RollupField.COUNT_FIELD, "foo." + RollupField.COUNT_FIELD);
294-
Sum sum = mock(Sum.class);
295-
when(sum.value()).thenReturn(10.0);
296-
when(sum.value()).thenReturn(10.0);
297-
when(sum.getName()).thenReturn("foo");
298-
when(sum.getMetadata()).thenReturn(metadata);
299-
when(sum.getType()).thenReturn(SumAggregationBuilder.NAME);
300-
subaggs.add(sum);
301-
302-
Sum count = mock(Sum.class);
303-
when(count.value()).thenReturn(2.0);
304-
when(count.value()).thenReturn(2.0);
305-
when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD);
306-
when(count.getMetadata()).thenReturn(null);
307-
when(count.getType()).thenReturn(SumAggregationBuilder.NAME);
308-
subaggs.add(count);
309-
310-
when(filter.getAggregations()).thenReturn(InternalAggregations.from(subaggs));
311-
when(filter.getName()).thenReturn("filter_foo");
312-
aggTree.add(filter);
313-
314-
InternalAggregations mockAggs = InternalAggregations.from(aggTree);
277+
subaggs.add(new Sum("foo", 10.0, DocValueFormat.RAW, metadata));
278+
subaggs.add(new Sum("foo." + RollupField.COUNT_FIELD, 2.0, DocValueFormat.RAW, null));
279+
InternalAggregations mockAggs = InternalAggregations.from(
280+
new InternalFilter("filter_foo", 0, InternalAggregations.from(subaggs), null)
281+
);
315282
when(response.getAggregations()).thenReturn(mockAggs);
316283
MultiSearchResponse multiSearchResponse = new MultiSearchResponse(
317284
new MultiSearchResponse.Item[] { new MultiSearchResponse.Item(response, null) },
@@ -434,33 +401,15 @@ public void testSimpleReduction() throws Exception {
434401

435402
SearchResponse responseWithout = mock(SearchResponse.class);
436403
when(responseWithout.getTook()).thenReturn(new TimeValue(100));
437-
List<InternalAggregation> aggTree = new ArrayList<>(1);
438-
InternalFilter filter = mock(InternalFilter.class);
439404

440405
List<InternalAggregation> subaggs = new ArrayList<>(2);
441406
Map<String, Object> metadata = Maps.newMapWithExpectedSize(1);
442407
metadata.put(RollupField.ROLLUP_META + "." + RollupField.COUNT_FIELD, "foo." + RollupField.COUNT_FIELD);
443-
Sum sum = mock(Sum.class);
444-
when(sum.value()).thenReturn(10.0);
445-
when(sum.value()).thenReturn(10.0);
446-
when(sum.getName()).thenReturn("foo");
447-
when(sum.getMetadata()).thenReturn(metadata);
448-
when(sum.getType()).thenReturn(SumAggregationBuilder.NAME);
449-
subaggs.add(sum);
450-
451-
Sum count = mock(Sum.class);
452-
when(count.value()).thenReturn(2.0);
453-
when(count.value()).thenReturn(2.0);
454-
when(count.getName()).thenReturn("foo." + RollupField.COUNT_FIELD);
455-
when(count.getMetadata()).thenReturn(null);
456-
when(count.getType()).thenReturn(SumAggregationBuilder.NAME);
457-
subaggs.add(count);
458-
459-
when(filter.getAggregations()).thenReturn(InternalAggregations.from(subaggs));
460-
when(filter.getName()).thenReturn("filter_foo");
461-
aggTree.add(filter);
462-
463-
InternalAggregations mockAggsWithout = InternalAggregations.from(aggTree);
408+
subaggs.add(new Sum("foo", 10.0, DocValueFormat.RAW, metadata));
409+
subaggs.add(new Sum("foo." + RollupField.COUNT_FIELD, 2.0, DocValueFormat.RAW, null));
410+
InternalAggregations mockAggsWithout = InternalAggregations.from(
411+
new InternalFilter("filter_foo", 0, InternalAggregations.from(subaggs), Map.of())
412+
);
464413
when(responseWithout.getAggregations()).thenReturn(mockAggsWithout);
465414
MultiSearchResponse.Item rolledResponse = new MultiSearchResponse.Item(responseWithout, null);
466415

x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/rollup/action/SearchActionTests.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,6 @@ public void testRollupOnly() throws Exception {
713713
SearchResponse response = mock(SearchResponse.class);
714714
when(response.getTook()).thenReturn(new TimeValue(100));
715715
List<InternalAggregation> aggTree = new ArrayList<>(1);
716-
InternalFilter filter = mock(InternalFilter.class);
717716

718717
List<InternalAggregation> subaggs = new ArrayList<>(2);
719718
Map<String, Object> metadata = Maps.newMapWithExpectedSize(1);
@@ -732,9 +731,7 @@ public void testRollupOnly() throws Exception {
732731
when(count.getType()).thenReturn(SumAggregationBuilder.NAME);
733732
subaggs.add(count);
734733

735-
when(filter.getAggregations()).thenReturn(InternalAggregations.from(subaggs));
736-
when(filter.getName()).thenReturn("filter_foo");
737-
aggTree.add(filter);
734+
aggTree.add(new InternalFilter("filter_foo", 0, InternalAggregations.from(subaggs), null));
738735

739736
InternalAggregations mockAggs = InternalAggregations.from(aggTree);
740737
when(response.getAggregations()).thenReturn(mockAggs);
@@ -852,7 +849,6 @@ public void testBoth() throws Exception {
852849
SearchResponse responseWithout = mock(SearchResponse.class);
853850
when(responseWithout.getTook()).thenReturn(new TimeValue(100));
854851
List<InternalAggregation> aggTree = new ArrayList<>(1);
855-
InternalFilter filter = mock(InternalFilter.class);
856852

857853
List<InternalAggregation> subaggs = new ArrayList<>(2);
858854
Map<String, Object> metadata = Maps.newMapWithExpectedSize(1);
@@ -871,9 +867,7 @@ public void testBoth() throws Exception {
871867
when(count.getType()).thenReturn(SumAggregationBuilder.NAME);
872868
subaggs.add(count);
873869

874-
when(filter.getAggregations()).thenReturn(InternalAggregations.from(subaggs));
875-
when(filter.getName()).thenReturn("filter_foo");
876-
aggTree.add(filter);
870+
aggTree.add(new InternalFilter("filter_foo", 0, InternalAggregations.from(subaggs), null));
877871

878872
InternalAggregations mockAggsWithout = InternalAggregations.from(aggTree);
879873
when(responseWithout.getAggregations()).thenReturn(mockAggsWithout);

0 commit comments

Comments
 (0)