Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate and cleanup the server version checks for tests #865

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.opensearch.client.opensearch._types.aggregations.MultiTermsAggregation;
import org.opensearch.client.opensearch._types.aggregations.RangeAggregation;
import org.opensearch.client.opensearch._types.mapping.Property;
import org.opensearch.client.opensearch.core.InfoResponse;
import org.opensearch.client.opensearch.core.SearchResponse;

public abstract class AbstractAggregationRequestIT extends OpenSearchJavaClientTestCase {
Expand Down Expand Up @@ -101,15 +100,7 @@ public void testMultiTermsAggregationWithSizeBiggerThenBucketsSize() throws Exce
}

private void checkIfOpenSearchSupportsMultiTermsAggregation() throws Exception {
InfoResponse info = javaClient().info();
String version = info.version().number();
if (version.contains("SNAPSHOT")) {
version = version.split("-")[0];
}
assumeTrue(
"multi_terms is supported in OpenSearch 2.1.0 and later",
Version.fromString(version).onOrAfter(Version.fromString("2.1.0"))
);
assumeTrue("multi_terms is supported in OpenSearch 2.1.0 and later", getServerVersion().onOrAfter(Version.V_2_1_0));
}

private Aggregation getExpiryDateRangeAggregation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.opensearch.client.opensearch.cat.segments.SegmentsRecord;
import org.opensearch.client.opensearch.cat.shards.ShardsRecord;
import org.opensearch.client.opensearch.core.IndexResponse;
import org.opensearch.client.opensearch.core.InfoResponse;
import org.opensearch.client.opensearch.core.pit.CreatePitResponse;
import org.opensearch.client.opensearch.indices.CreateIndexResponse;

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

@Test
public void testCatPitSegments() throws Exception {
InfoResponse info = javaClient().info();
String version = info.version().number();
if (version.contains("SNAPSHOT")) {
version = version.split("-")[0];
}
assumeTrue(
"The PIT is supported in OpenSearch 2.4.0 and later",
Version.fromString(version).onOrAfter(Version.fromString("2.4.0"))
);
final Version version = getServerVersion();
assumeTrue("The PIT is supported in OpenSearch 2.4.0 and later", version.onOrAfter(Version.V_2_4_0));
createIndex("cat-pit-segments-test-index");

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

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

if (Version.fromString(version).onOrAfter(Version.fromString("2.10.0"))) {
if (version.onOrAfter(Version.V_2_10_0)) {
assertTrue("PitSegmentsResponse.segments().size() == 0", PitSegmentsResponse.valueBody().isEmpty());
} else {
assertTrue("PitSegmentsResponse.segments().size() == 0", PitSegmentsResponse.valueBody().size() > 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,15 +617,7 @@ public void testCompletionSuggesterFailure() throws IOException {

@Test
public void testPit() throws IOException {
InfoResponse info = javaClient().info();
String version = info.version().number();
if (version.contains("SNAPSHOT")) {
version = version.split("-")[0];
}
assumeTrue(
"The PIT is supported in OpenSearch 2.4.0 and later",
Version.fromString(version).onOrAfter(Version.fromString("2.4.0"))
);
assumeTrue("The PIT is supported in OpenSearch 2.4.0 and later", getServerVersion().onOrAfter(Version.V_2_4_0));

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.opensearch.client.opensearch._types.query_dsl.MatchQuery;
import org.opensearch.client.opensearch._types.query_dsl.Query;
import org.opensearch.client.opensearch._types.query_dsl.TermQuery;
import org.opensearch.client.opensearch.core.InfoResponse;
import org.opensearch.client.opensearch.core.SearchRequest;
import org.opensearch.client.opensearch.core.SearchResponse;
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
Expand Down Expand Up @@ -63,12 +62,7 @@ public void shouldReturnSearchResults() throws Exception {

@Test
public void hybridSearchShouldReturnSearchResults() throws Exception {
InfoResponse info = javaClient().info();
String version = info.version().number();
if (version.contains("SNAPSHOT")) {
version = version.split("-")[0];
}
assumeTrue("Hybrid search is supported from 2.10.0", Version.fromString(version).onOrAfter(Version.fromString("2.10.0")));
assumeTrue("Hybrid search is supported from 2.10.0", getServerVersion().onOrAfter(Version.V_2_10_0));
final String index = "hybrid_search_request";
try {
createIndex(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.opensearch.client.opensearch._types.ExpandWildcard;
import org.opensearch.client.opensearch.cat.IndicesResponse;
import org.opensearch.client.opensearch.cat.indices.IndicesRecord;
import org.opensearch.client.opensearch.core.InfoResponse;
import org.opensearch.client.opensearch.indices.DeleteIndexRequest;
import org.opensearch.client.opensearch.nodes.NodesInfoResponse;
import org.opensearch.client.opensearch.nodes.info.NodeInfo;
Expand Down Expand Up @@ -186,4 +187,15 @@ public static void cleanupJavaClient() throws IOException {
protected boolean preserveIndicesUponCompletion() {
return true;
}

protected Version getServerVersion() throws IOException {
final InfoResponse info = javaClient().info();

String version = info.version().number();
if (version.contains("SNAPSHOT")) {
version = version.split("-")[0];
}

return Version.fromString(version);
}
}
Loading