Skip to content

Commit a1bf415

Browse files
authored
Consolidate and cleanup the server version checks for tests (#865)
Signed-off-by: Andriy Redko <[email protected]>
1 parent 1265f19 commit a1bf415

File tree

5 files changed

+18
-37
lines changed

5 files changed

+18
-37
lines changed

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractAggregationRequestIT.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.opensearch.client.opensearch._types.aggregations.MultiTermsAggregation;
2626
import org.opensearch.client.opensearch._types.aggregations.RangeAggregation;
2727
import org.opensearch.client.opensearch._types.mapping.Property;
28-
import org.opensearch.client.opensearch.core.InfoResponse;
2928
import org.opensearch.client.opensearch.core.SearchResponse;
3029

3130
public abstract class AbstractAggregationRequestIT extends OpenSearchJavaClientTestCase {
@@ -101,15 +100,7 @@ public void testMultiTermsAggregationWithSizeBiggerThenBucketsSize() throws Exce
101100
}
102101

103102
private void checkIfOpenSearchSupportsMultiTermsAggregation() throws Exception {
104-
InfoResponse info = javaClient().info();
105-
String version = info.version().number();
106-
if (version.contains("SNAPSHOT")) {
107-
version = version.split("-")[0];
108-
}
109-
assumeTrue(
110-
"multi_terms is supported in OpenSearch 2.1.0 and later",
111-
Version.fromString(version).onOrAfter(Version.fromString("2.1.0"))
112-
);
103+
assumeTrue("multi_terms is supported in OpenSearch 2.1.0 and later", getServerVersion().onOrAfter(Version.V_2_1_0));
113104
}
114105

115106
private Aggregation getExpiryDateRangeAggregation() {

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractCatClientIT.java

+3-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.opensearch.client.opensearch.cat.segments.SegmentsRecord;
3535
import org.opensearch.client.opensearch.cat.shards.ShardsRecord;
3636
import org.opensearch.client.opensearch.core.IndexResponse;
37-
import org.opensearch.client.opensearch.core.InfoResponse;
3837
import org.opensearch.client.opensearch.core.pit.CreatePitResponse;
3938
import org.opensearch.client.opensearch.indices.CreateIndexResponse;
4039

@@ -238,15 +237,8 @@ public void testCatSegments() throws Exception {
238237

239238
@Test
240239
public void testCatPitSegments() throws Exception {
241-
InfoResponse info = javaClient().info();
242-
String version = info.version().number();
243-
if (version.contains("SNAPSHOT")) {
244-
version = version.split("-")[0];
245-
}
246-
assumeTrue(
247-
"The PIT is supported in OpenSearch 2.4.0 and later",
248-
Version.fromString(version).onOrAfter(Version.fromString("2.4.0"))
249-
);
240+
final Version version = getServerVersion();
241+
assumeTrue("The PIT is supported in OpenSearch 2.4.0 and later", version.onOrAfter(Version.V_2_4_0));
250242
createIndex("cat-pit-segments-test-index");
251243

252244
final IndexResponse index = javaClient().index(
@@ -264,7 +256,7 @@ public void testCatPitSegments() throws Exception {
264256

265257
assertNotNull("PitSegmentsResponse.segments() is null", PitSegmentsResponse.valueBody());
266258

267-
if (Version.fromString(version).onOrAfter(Version.fromString("2.10.0"))) {
259+
if (version.onOrAfter(Version.V_2_10_0)) {
268260
assertTrue("PitSegmentsResponse.segments().size() == 0", PitSegmentsResponse.valueBody().isEmpty());
269261
} else {
270262
assertTrue("PitSegmentsResponse.segments().size() == 0", PitSegmentsResponse.valueBody().size() > 0);

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractRequestIT.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -617,15 +617,7 @@ public void testCompletionSuggesterFailure() throws IOException {
617617

618618
@Test
619619
public void testPit() throws IOException {
620-
InfoResponse info = javaClient().info();
621-
String version = info.version().number();
622-
if (version.contains("SNAPSHOT")) {
623-
version = version.split("-")[0];
624-
}
625-
assumeTrue(
626-
"The PIT is supported in OpenSearch 2.4.0 and later",
627-
Version.fromString(version).onOrAfter(Version.fromString("2.4.0"))
628-
);
620+
assumeTrue("The PIT is supported in OpenSearch 2.4.0 and later", getServerVersion().onOrAfter(Version.V_2_4_0));
629621

630622
String index = "test-point-in-time";
631623

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractSearchRequestIT.java

+1-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.opensearch.client.opensearch._types.query_dsl.MatchQuery;
2020
import org.opensearch.client.opensearch._types.query_dsl.Query;
2121
import org.opensearch.client.opensearch._types.query_dsl.TermQuery;
22-
import org.opensearch.client.opensearch.core.InfoResponse;
2322
import org.opensearch.client.opensearch.core.SearchRequest;
2423
import org.opensearch.client.opensearch.core.SearchResponse;
2524
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
@@ -63,12 +62,7 @@ public void shouldReturnSearchResults() throws Exception {
6362

6463
@Test
6564
public void hybridSearchShouldReturnSearchResults() throws Exception {
66-
InfoResponse info = javaClient().info();
67-
String version = info.version().number();
68-
if (version.contains("SNAPSHOT")) {
69-
version = version.split("-")[0];
70-
}
71-
assumeTrue("Hybrid search is supported from 2.10.0", Version.fromString(version).onOrAfter(Version.fromString("2.10.0")));
65+
assumeTrue("Hybrid search is supported from 2.10.0", getServerVersion().onOrAfter(Version.V_2_10_0));
7266
final String index = "hybrid_search_request";
7367
try {
7468
createIndex(index);

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/OpenSearchJavaClientTestCase.java

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.opensearch.client.opensearch._types.ExpandWildcard;
3939
import org.opensearch.client.opensearch.cat.IndicesResponse;
4040
import org.opensearch.client.opensearch.cat.indices.IndicesRecord;
41+
import org.opensearch.client.opensearch.core.InfoResponse;
4142
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
4243
import org.opensearch.client.opensearch.nodes.NodesInfoResponse;
4344
import org.opensearch.client.opensearch.nodes.info.NodeInfo;
@@ -186,4 +187,15 @@ public static void cleanupJavaClient() throws IOException {
186187
protected boolean preserveIndicesUponCompletion() {
187188
return true;
188189
}
190+
191+
protected Version getServerVersion() throws IOException {
192+
final InfoResponse info = javaClient().info();
193+
194+
String version = info.version().number();
195+
if (version.contains("SNAPSHOT")) {
196+
version = version.split("-")[0];
197+
}
198+
199+
return Version.fromString(version);
200+
}
189201
}

0 commit comments

Comments
 (0)