Skip to content

Commit

Permalink
Test case for invalid execution hint added
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Rayabharam <maitreya2954@gmail.com>
  • Loading branch information
maitreya2954 committed Sep 13, 2024
1 parent 7accb1d commit 96f9b83
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import org.apache.lucene.util.BytesRef;
import org.opensearch.common.CheckedConsumer;
import org.opensearch.common.geo.GeoPoint;
import org.opensearch.common.network.InetAddresses;
import org.opensearch.core.common.breaker.CircuitBreaker;
import org.opensearch.core.indices.breaker.NoneCircuitBreakerService;
import org.opensearch.index.mapper.*;
Expand All @@ -59,8 +58,6 @@
import org.opensearch.search.aggregations.support.AggregationInspectionHelper;

import java.io.IOException;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -529,6 +526,21 @@ private void testAggregationExecutionHint(
}
}

public void testInvalidExecutionHint() throws IOException {
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder("_name").field("number").executionHint("invalid");
assertThrows(IllegalArgumentException.class, () -> testAggregationExecutionHint(aggregationBuilder, new MatchAllDocsQuery(), iw -> {
iw.addDocument(singleton(new NumericDocValuesField("number", 7)));
iw.addDocument(singleton(new NumericDocValuesField("number", 8)));
iw.addDocument(singleton(new NumericDocValuesField("number", 9)));
}, card -> {
assertEquals(3, card.getValue(), 0);
assertTrue(AggregationInspectionHelper.hasValue(card));
}, collector -> {
assertTrue(collector instanceof CardinalityAggregator.DirectCollector);
}, fieldType));
}

public void testNoExecutionHintWithNumericDocValues() throws IOException {
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
final CardinalityAggregationBuilder aggregationBuilder = new CardinalityAggregationBuilder("_name").field("number");
Expand Down

0 comments on commit 96f9b83

Please sign in to comment.