Skip to content

Commit 6bf70e4

Browse files
committed
Added more cases to improve coverage
Signed-off-by: expani <[email protected]>
1 parent 6432da4 commit 6bf70e4

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder;
6565
import org.junit.After;
6666
import org.junit.Before;
67+
import org.opensearch.search.aggregations.support.ValuesSourceAggregatorFactory;
6768

6869
import java.io.IOException;
6970
import java.util.ArrayList;
@@ -74,8 +75,8 @@
7475
import java.util.function.BiConsumer;
7576
import java.util.function.Function;
7677

77-
import org.mockito.Mockito;
78-
78+
import static org.mockito.Mockito.mock;
79+
import static org.mockito.Mockito.when;
7980
import static org.opensearch.search.aggregations.AggregationBuilders.avg;
8081
import static org.opensearch.search.aggregations.AggregationBuilders.count;
8182
import static org.opensearch.search.aggregations.AggregationBuilders.max;
@@ -290,10 +291,10 @@ public void testStarTreeDocValues() throws IOException {
290291
new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), circuitBreakerService).withCircuitBreaking()
291292
);
292293

293-
MetricAggregatorFactory aggregatorFactory = Mockito.mock(MetricAggregatorFactory.class);
294-
Mockito.when(aggregatorFactory.getSubFactories()).thenReturn(AggregatorFactories.EMPTY);
295-
Mockito.when(aggregatorFactory.getField()).thenReturn(FIELD_NAME);
296-
Mockito.when(aggregatorFactory.getMetricStat()).thenReturn(MetricStat.SUM);
294+
MetricAggregatorFactory aggregatorFactory = mock(MetricAggregatorFactory.class);
295+
when(aggregatorFactory.getSubFactories()).thenReturn(AggregatorFactories.EMPTY);
296+
when(aggregatorFactory.getField()).thenReturn(FIELD_NAME);
297+
when(aggregatorFactory.getMetricStat()).thenReturn(MetricStat.SUM);
297298

298299
// Case when field and metric type in aggregation are fully supported by star tree.
299300
testCase(
@@ -338,6 +339,52 @@ public void testStarTreeDocValues() throws IOException {
338339
false
339340
);
340341

342+
// Case when field is not present in supported metrics
343+
testCase(
344+
indexSearcher,
345+
query,
346+
queryBuilder,
347+
sumAggregationBuilder,
348+
starTree,
349+
supportedDimensions,
350+
List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))),
351+
verifyAggregation(InternalSum::getValue),
352+
aggregatorFactory,
353+
false
354+
);
355+
356+
AggregatorFactories aggregatorFactories = mock(AggregatorFactories.class);
357+
when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[]{mock(MetricAggregatorFactory.class)});
358+
when(aggregatorFactory.getSubFactories()).thenReturn(aggregatorFactories);
359+
360+
// Case when sub aggregations are present
361+
testCase(
362+
indexSearcher,
363+
query,
364+
queryBuilder,
365+
sumAggregationBuilder,
366+
starTree,
367+
supportedDimensions,
368+
List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))),
369+
verifyAggregation(InternalSum::getValue),
370+
aggregatorFactory,
371+
false
372+
);
373+
374+
// Case when aggregation factory is not metric aggregation
375+
testCase(
376+
indexSearcher,
377+
query,
378+
queryBuilder,
379+
sumAggregationBuilder,
380+
starTree,
381+
supportedDimensions,
382+
List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))),
383+
verifyAggregation(InternalSum::getValue),
384+
mock(ValuesSourceAggregatorFactory.class),
385+
false
386+
);
387+
341388
ir.close();
342389
directory.close();
343390
}

0 commit comments

Comments
 (0)