Skip to content

Commit 179f819

Browse files
committed
add unit tests
Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
1 parent f3f787e commit 179f819

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

server/src/test/java/org/opensearch/index/query/CombineIntervalsSourceProviderTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@
3232

3333
package org.opensearch.index.query;
3434

35+
import org.apache.lucene.queries.intervals.Intervals;
36+
import org.apache.lucene.queries.intervals.IntervalsSource;
3537
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
3638
import org.opensearch.core.common.io.stream.Writeable;
3739
import org.opensearch.core.xcontent.XContentParser;
40+
import org.opensearch.index.query.IntervalsSourceProvider.Combine;
3841
import org.opensearch.search.SearchModule;
3942
import org.opensearch.test.AbstractSerializingTestCase;
4043

4144
import java.io.IOException;
45+
import java.util.ArrayList;
4246
import java.util.List;
4347

4448
import static org.opensearch.index.query.IntervalsSourceProvider.Combine;
@@ -104,4 +108,28 @@ protected Combine doParseInstance(XContentParser parser) throws IOException {
104108
assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
105109
return combine;
106110
}
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+
}
107135
}

0 commit comments

Comments
 (0)