|
32 | 32 |
|
33 | 33 | package org.opensearch.index.query; |
34 | 34 |
|
| 35 | +import org.apache.lucene.queries.intervals.Intervals; |
| 36 | +import org.apache.lucene.queries.intervals.IntervalsSource; |
35 | 37 | import org.opensearch.core.common.io.stream.NamedWriteableRegistry; |
36 | 38 | import org.opensearch.core.common.io.stream.Writeable; |
37 | 39 | import org.opensearch.core.xcontent.XContentParser; |
| 40 | +import org.opensearch.index.query.IntervalsSourceProvider.Combine; |
38 | 41 | import org.opensearch.search.SearchModule; |
39 | 42 | import org.opensearch.test.AbstractSerializingTestCase; |
40 | 43 |
|
41 | 44 | import java.io.IOException; |
| 45 | +import java.util.ArrayList; |
42 | 46 | import java.util.List; |
43 | 47 |
|
44 | 48 | import static org.opensearch.index.query.IntervalsSourceProvider.Combine; |
@@ -104,4 +108,28 @@ protected Combine doParseInstance(XContentParser parser) throws IOException { |
104 | 108 | assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken()); |
105 | 109 | return combine; |
106 | 110 | } |
| 111 | + |
| 112 | + public void testCanCombineSourcesFail() { |
| 113 | + List<IntervalsSource> sources = new ArrayList<>(); |
| 114 | + |
| 115 | + for (int i = 0; i < 11; i++) { |
| 116 | + IntervalsSource source1 = Intervals.maxgaps(0, Intervals.ordered(Intervals.term("term_" + 2 * i))); |
| 117 | + IntervalsSource source2 = Intervals.maxgaps(0, Intervals.ordered(Intervals.term("term_" + (2 * i + 1)))); |
| 118 | + sources.add(Intervals.or(source1, source2)); |
| 119 | + } |
| 120 | + |
| 121 | + assertFalse(IntervalBuilder.canCombineSources(sources)); |
| 122 | + } |
| 123 | + |
| 124 | + public void testCanCombineSourcesSuccess() { |
| 125 | + List<IntervalsSource> sources = new ArrayList<>(); |
| 126 | + |
| 127 | + for (int i = 0; i < 10; i++) { |
| 128 | + IntervalsSource source1 = Intervals.maxgaps(0, Intervals.ordered(Intervals.term("term_" + 2 * i))); |
| 129 | + IntervalsSource source2 = Intervals.maxgaps(0, Intervals.ordered(Intervals.term("term_" + (2 * i + 1)))); |
| 130 | + sources.add(Intervals.or(source1, source2)); |
| 131 | + } |
| 132 | + |
| 133 | + assertTrue(IntervalBuilder.canCombineSources(sources)); |
| 134 | + } |
107 | 135 | } |
0 commit comments