From 220a5600eccdb49636aba376b801be5417ec28d7 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Tue, 2 Jan 2024 15:10:41 -0500 Subject: [PATCH 1/2] Add an integration test that runs on JDK-8 Signed-off-by: Andriy Redko --- .github/workflows/test-jdk8-compat-unit.yml | 30 +++++++++++++++++++ CHANGELOG.md | 1 + java-client/build.gradle.kts | 19 ++++++++++-- .../query_dsl/GeoDistanceQueryTest.java | 4 +-- .../_types/query_dsl/PinnedQueryTest.java | 4 +-- .../query_dsl/SpanContainingQueryTest.java | 6 ++-- .../query_dsl/SpanFieldMaskingQueryTest.java | 4 +-- .../_types/query_dsl/SpanFirstQueryTest.java | 4 +-- .../_types/query_dsl/SpanNearQueryTest.java | 6 ++-- .../_types/query_dsl/SpanNotQueryTest.java | 6 ++-- .../_types/query_dsl/SpanOrQueryTest.java | 6 ++-- .../_types/query_dsl/SpanQueryTest.java | 4 +-- .../_types/query_dsl/SpanWithinQueryTest.java | 6 ++-- .../_types/query_dsl/TermsQueryFieldTest.java | 4 +-- .../_types/query_dsl/TermsQueryTest.java | 4 +-- .../opensearch/core/BulkRequestTest.java | 6 ++-- .../core/ClearScrollRequestTest.java | 4 +-- .../opensearch/core/MsearchRequestTest.java | 4 +-- .../core/MsearchTemplateRequestTest.java | 6 ++-- .../core/PutIndexTemplateRequestTest.java | 14 ++++++--- .../opensearch/core/RankEvalRequestTest.java | 4 +-- .../opensearch/core/search/InnerHitsTest.java | 4 +-- settings.gradle.kts | 6 +++- 23 files changed, 110 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/test-jdk8-compat-unit.yml diff --git a/.github/workflows/test-jdk8-compat-unit.yml b/.github/workflows/test-jdk8-compat-unit.yml new file mode 100644 index 0000000000..bf7bffc184 --- /dev/null +++ b/.github/workflows/test-jdk8-compat-unit.yml @@ -0,0 +1,30 @@ +name: Compatibility Unit Tests (JDK-8) + +on: [push, pull_request] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + steps: + - name: Checkout Java Client + uses: actions/checkout@v3 + + - name: Set up JDK 8 + uses: actions/setup-java@v3 + with: + java-version: 8 + distribution: 'temurin' + cache: 'gradle' + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: 'temurin' + cache: 'gradle' + + - name: Run Unit Test + run: ./gradlew clean unitTest -Pcheck-jdk8-compatibility=true diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b2e51cc03..379ff94bcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Changed - Restore support for Java 8 ([#767](https://github.com/opensearch-project/opensearch-java/pull/767)) +- Add an integration test that runs on JDK-8 ([#795](https://github.com/opensearch-project/opensearch-java/pull/795)) ### Deprecated - Deprecated "_toQuery()" in Query and QueryVariant ([#760](https://github.com/opensearch-project/opensearch-java/pull/760) diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index 8d0522d4d0..dd29517d09 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -32,6 +32,7 @@ import com.github.jk1.license.ProjectData import com.github.jk1.license.render.ReportRenderer +import org.gradle.api.tasks.testing.Test import java.io.FileWriter buildscript { @@ -337,7 +338,9 @@ publishing { } } -if (JavaVersion.current() >= JavaVersion.VERSION_11) { +// Use `-Pcheck-jdk8-compatibility=true` to +val jdk8compatibility = (project.findProperty("check-jdk8-compatibility") as String?).toBoolean() +if (JavaVersion.current() >= JavaVersion.VERSION_11 && jdk8compatibility == false) { val java11: SourceSet = sourceSets.create("java11") { java { compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output @@ -369,5 +372,17 @@ if (JavaVersion.current() >= JavaVersion.VERSION_11) { testClassesDirs += java11.output.classesDirs classpath = sourceSets["java11"].runtimeClasspath } - +} else if (jdk8compatibility == true) { + java { + toolchain { + languageVersion = JavaLanguageVersion.of(8) + vendor = JvmVendorSpec.ADOPTIUM + } + } + + tasks.register("tests-jdk8") { + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(8) + } + } } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQueryTest.java index edaa9edf56..289f5c75a8 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch._types.GeoLocation; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -9,7 +9,7 @@ public class GeoDistanceQueryTest extends ModelTestCase { @Test public void toBuilder() { GeoDistanceQuery origin = new GeoDistanceQuery.Builder().field("field") - .location(new GeoLocation.Builder().coords(List.of(1.0)).build()) + .location(new GeoLocation.Builder().coords(Collections.singletonList(1.0)).build()) .build(); GeoDistanceQuery copied = origin.toBuilder().build(); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQueryTest.java index 3c779919de..074b7ead70 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch._types.FieldValue; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,7 +8,7 @@ public class PinnedQueryTest extends ModelTestCase { @Test public void toBuilder() { - PinnedQuery origin = new PinnedQuery.Builder().organic(buildDummyQuery()).ids(List.of("1")).build(); + PinnedQuery origin = new PinnedQuery.Builder().organic(buildDummyQuery()).ids(Collections.singletonList("1")).build(); PinnedQuery copied = origin.toBuilder().build(); assertEquals(toJson(copied), toJson(origin)); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQueryTest.java index fabb167771..cbcfa17886 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,8 +8,8 @@ public class SpanContainingQueryTest extends ModelTestCase { @Test public void toBuilder() { SpanContainingQuery origin = new SpanContainingQuery.Builder().big( - new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build() - ).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build(); + new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build() + ).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build(); SpanContainingQuery copied = origin.toBuilder().build(); assertEquals(toJson(copied), toJson(origin)); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQueryTest.java index af176824f7..d420c9242c 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,7 +8,7 @@ public class SpanFieldMaskingQueryTest extends ModelTestCase { @Test public void toBuilder() { SpanFieldMaskingQuery origin = new SpanFieldMaskingQuery.Builder().field("field") - .query(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()) + .query(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()) .build(); SpanFieldMaskingQuery copied = origin.toBuilder().build(); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQueryTest.java index 3b0fbac20c..f9fc4afe7d 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,7 +8,7 @@ public class SpanFirstQueryTest extends ModelTestCase { @Test public void toBuilder() { SpanFirstQuery origin = new SpanFirstQuery.Builder().end(1) - .match(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()) + .match(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()) .build(); SpanFirstQuery copied = origin.toBuilder().build(); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQueryTest.java index ffff730cf1..f48ded1f69 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,7 +8,9 @@ public class SpanNearQueryTest extends ModelTestCase { @Test public void toBuilder() { SpanNearQuery origin = new SpanNearQuery.Builder().clauses( - List.of(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()) + Collections.singletonList( + new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build() + ) ).build(); SpanNearQuery copied = origin.toBuilder().build(); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQueryTest.java index 2a2757d1a6..a5d9d9b14a 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,8 +8,8 @@ public class SpanNotQueryTest extends ModelTestCase { @Test public void toBuilder() { SpanNotQuery origin = new SpanNotQuery.Builder().include( - new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build() - ).exclude(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build(); + new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build() + ).exclude(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build(); SpanNotQuery copied = origin.toBuilder().build(); assertEquals(toJson(copied), toJson(origin)); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQueryTest.java index 407c0717c9..a0c3a83eee 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,7 +8,9 @@ public class SpanOrQueryTest extends ModelTestCase { @Test public void toBuilder() { SpanOrQuery origin = new SpanOrQuery.Builder().clauses( - List.of(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()) + Collections.singletonList( + new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build() + ) ).build(); SpanOrQuery copied = origin.toBuilder().build(); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQueryTest.java index 5d941045ee..942e67d177 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQueryTest.java @@ -1,13 +1,13 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch.model.ModelTestCase; public class SpanQueryTest extends ModelTestCase { @Test public void toBuilder() { - SpanQuery origin = new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build(); + SpanQuery origin = new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build(); SpanQuery copied = origin.toBuilder().build(); assertEquals(toJson(copied), toJson(origin)); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQueryTest.java index ce71e79c33..42208a9372 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,8 +8,8 @@ public class SpanWithinQueryTest extends ModelTestCase { @Test public void toBuilder() { SpanWithinQuery origin = new SpanWithinQuery.Builder().big( - new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build() - ).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build(); + new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build() + ).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build(); SpanWithinQuery copied = origin.toBuilder().build(); assertEquals(toJson(copied), toJson(origin)); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryFieldTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryFieldTest.java index 41fb249d51..5af873b206 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryFieldTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryFieldTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch._types.FieldValue; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -8,7 +8,7 @@ public class TermsQueryFieldTest extends ModelTestCase { @Test public void toBuilder() { - TermsQueryField origin = new TermsQueryField.Builder().value(List.of(FieldValue.of("1"))).build(); + TermsQueryField origin = new TermsQueryField.Builder().value(Collections.singletonList(FieldValue.of("1"))).build(); TermsQueryField copied = origin.toBuilder().build(); assertEquals(toJson(copied), toJson(origin)); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryTest.java index a8bea25397..bf9ed792ec 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch._types.query_dsl; -import java.util.List; +import java.util.Collections; import org.junit.Test; import org.opensearch.client.opensearch._types.FieldValue; import org.opensearch.client.opensearch.model.ModelTestCase; @@ -9,7 +9,7 @@ public class TermsQueryTest extends ModelTestCase { @Test public void toBuilder() { TermsQuery origin = new TermsQuery.Builder().field("field") - .terms(new TermsQueryField.Builder().value(List.of(FieldValue.of("1"))).build()) + .terms(new TermsQueryField.Builder().value(Collections.singletonList(FieldValue.of("1"))).build()) .build(); TermsQuery copied = origin.toBuilder().build(); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/BulkRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/BulkRequestTest.java index c173f1482d..bdb5e01aa2 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/BulkRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/BulkRequestTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch.core; -import java.util.List; +import java.util.Collections; import org.junit.Assert; import org.junit.Test; import org.opensearch.client.opensearch.core.bulk.BulkOperation; @@ -11,7 +11,9 @@ public class BulkRequestTest extends Assert { @Test public void toBuilder() { BulkRequest origin = new BulkRequest.Builder().index("index") - .operations(List.of(new BulkOperation.Builder().delete(new DeleteOperation.Builder().id("id").build()).build())) + .operations( + Collections.singletonList(new BulkOperation.Builder().delete(new DeleteOperation.Builder().id("id").build()).build()) + ) .build(); BulkRequest copied = origin.toBuilder().build(); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/ClearScrollRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/ClearScrollRequestTest.java index cc80c857d7..fea512e074 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/ClearScrollRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/ClearScrollRequestTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch.core; -import java.util.List; +import java.util.Collections; import org.junit.Assert; import org.junit.Test; @@ -8,7 +8,7 @@ public class ClearScrollRequestTest extends Assert { @Test public void toBuilder() { - ClearScrollRequest origin = new ClearScrollRequest.Builder().scrollId(List.of("1")).build(); + ClearScrollRequest origin = new ClearScrollRequest.Builder().scrollId(Collections.singletonList("1")).build(); ClearScrollRequest copied = origin.toBuilder().build(); assertEquals(copied.scrollId(), origin.scrollId()); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java index 166a2e0e6c..da470f0d31 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch.core; -import java.util.List; +import java.util.Collections; import org.junit.Assert; import org.junit.Test; @@ -8,7 +8,7 @@ public class MsearchRequestTest extends Assert { @Test public void toBuilder() { - MsearchRequest origin = new MsearchRequest.Builder().index("index").searches(List.of()).build(); + MsearchRequest origin = new MsearchRequest.Builder().index("index").searches(Collections.emptyList()).build(); MsearchRequest copied = origin.toBuilder().build(); assertEquals(copied.index(), origin.index()); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchTemplateRequestTest.java index c741332568..c2a41d7d1c 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchTemplateRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchTemplateRequestTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch.core; -import java.util.List; +import java.util.Collections; import org.junit.Assert; import org.junit.Test; @@ -8,7 +8,9 @@ public class MsearchTemplateRequestTest extends Assert { @Test public void toBuilder() { - MsearchTemplateRequest origin = new MsearchTemplateRequest.Builder().index("index").searchTemplates(List.of()).build(); + MsearchTemplateRequest origin = new MsearchTemplateRequest.Builder().index("index") + .searchTemplates(Collections.emptyList()) + .build(); MsearchTemplateRequest copied = origin.toBuilder().build(); assertEquals(copied.index(), origin.index()); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java index eb95320333..6de5b06252 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/PutIndexTemplateRequestTest.java @@ -2,8 +2,10 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.json.stream.JsonParser; import java.io.StringReader; -import java.util.List; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; import org.junit.Assert; import org.junit.Test; @@ -16,15 +18,19 @@ public class PutIndexTemplateRequestTest extends Assert { @Test public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException { final JsonpMapper mapper = new JsonbJsonpMapper(); - final Map indexTemplateMap = Map.of("name", "test", "index_patterns", "*", "create", true, "priority", 1); + final Map indexTemplateMap = new HashMap<>(); + indexTemplateMap.put("name", "test"); + indexTemplateMap.put("index_patterns", "*"); + indexTemplateMap.put("create", true); + indexTemplateMap.put("priority", 1); final String indexTemplate = new ObjectMapper().writeValueAsString(indexTemplateMap); - final var parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); + final JsonParser parser = mapper.jsonProvider().createParser(new StringReader(indexTemplate)); final PutIndexTemplateRequest putIndexTemplateRequest = PutIndexTemplateRequest._DESERIALIZER.deserialize(parser, mapper); assertEquals(putIndexTemplateRequest.name(), "test"); - assertEquals(putIndexTemplateRequest.indexPatterns(), List.of("*")); + assertEquals(putIndexTemplateRequest.indexPatterns(), Collections.singletonList("*")); assertEquals((int) putIndexTemplateRequest.priority(), 1); } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/RankEvalRequestTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/RankEvalRequestTest.java index babf2a7aec..83e8f27057 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/RankEvalRequestTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/RankEvalRequestTest.java @@ -1,6 +1,6 @@ package org.opensearch.client.opensearch.core; -import java.util.List; +import java.util.Collections; import org.junit.Assert; import org.junit.Test; @@ -8,7 +8,7 @@ public class RankEvalRequestTest extends Assert { @Test public void toBuilder() { - RankEvalRequest origin = new RankEvalRequest.Builder().index("index").requests(List.of()).build(); + RankEvalRequest origin = new RankEvalRequest.Builder().index("index").requests(Collections.emptyList()).build(); RankEvalRequest copied = origin.toBuilder().build(); assertEquals(copied.index(), origin.index()); diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/core/search/InnerHitsTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/core/search/InnerHitsTest.java index 1269ebb0df..b9b4cdfa71 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/core/search/InnerHitsTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/core/search/InnerHitsTest.java @@ -9,7 +9,7 @@ import jakarta.json.stream.JsonParser; import java.io.StringReader; import java.io.StringWriter; -import java.util.List; +import java.util.Arrays; import org.junit.Test; import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.JsonpSerializable; @@ -26,7 +26,7 @@ public class InnerHitsTest { */ @Test public void testInnerHitStoredFields() { - InnerHits hits = InnerHits.of((it) -> it.storedFields(List.of("field1", "field2"))); + InnerHits hits = InnerHits.of((it) -> it.storedFields(Arrays.asList("field1", "field2"))); assertTrue(toJson(hits).contains("stored_fields")); } diff --git a/settings.gradle.kts b/settings.gradle.kts index 6d462291d4..9c04316123 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -30,6 +30,10 @@ * GitHub history for details. */ +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version("0.7.0") +} + rootProject.name = "opensearch-java" include("java-client") -include("samples") \ No newline at end of file +include("samples") From 983fc94610479341ac8ea2b71d92c2a15a80ab98 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Wed, 3 Jan 2024 11:13:58 -0500 Subject: [PATCH 2/2] Refactor the runtime Java selection Signed-off-by: Andriy Redko --- .github/workflows/test-jdk8-compat-unit.yml | 30 --------------------- .github/workflows/test-unit.yml | 15 ++++++++++- java-client/build.gradle.kts | 28 +++++++++---------- 3 files changed, 26 insertions(+), 47 deletions(-) delete mode 100644 .github/workflows/test-jdk8-compat-unit.yml diff --git a/.github/workflows/test-jdk8-compat-unit.yml b/.github/workflows/test-jdk8-compat-unit.yml deleted file mode 100644 index bf7bffc184..0000000000 --- a/.github/workflows/test-jdk8-compat-unit.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Compatibility Unit Tests (JDK-8) - -on: [push, pull_request] - -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] - steps: - - name: Checkout Java Client - uses: actions/checkout@v3 - - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: 8 - distribution: 'temurin' - cache: 'gradle' - - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: 11 - distribution: 'temurin' - cache: 'gradle' - - - name: Run Unit Test - run: ./gradlew clean unitTest -Pcheck-jdk8-compatibility=true diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 982d3d957a..14fa9a538f 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - java: [ 11, 17, 21 ] + java: [ 8, 11, 17, 21 ] os: [ubuntu-latest, windows-latest, macOS-latest] steps: - name: Checkout Java Client @@ -21,4 +21,17 @@ jobs: cache: 'gradle' - name: Run Unit Test + if: ${{ matrix.java != 8 }} run: ./gradlew clean unitTest + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + if: ${{ matrix.java == 8 }} + with: + java-version: 11 + distribution: 'temurin' + cache: 'gradle' + + - name: Run Unit Test + if: ${{ matrix.java == 8 }} + run: ./gradlew clean unitTest -D"runtime.java=8" diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index dd29517d09..06c07a4b03 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -64,6 +64,12 @@ configurations { } } +val runtimeJavaVersion = (System.getProperty("runtime.java")?.toInt())?.let(JavaVersion::toVersion) ?: JavaVersion.current() +logger.quiet("=======================================") +logger.quiet(" Runtime JDK Version : " + runtimeJavaVersion) +logger.quiet(" Gradle JDK Version : " + JavaVersion.current()) +logger.quiet("=======================================") + java { targetCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8 @@ -74,6 +80,11 @@ java { registerFeature("awsSdk2Support") { usingSourceSet(sourceSets.get("main")) } + + toolchain { + languageVersion = JavaLanguageVersion.of(runtimeJavaVersion.majorVersion) + vendor = JvmVendorSpec.ADOPTIUM + } } tasks.withType { @@ -338,9 +349,7 @@ publishing { } } -// Use `-Pcheck-jdk8-compatibility=true` to -val jdk8compatibility = (project.findProperty("check-jdk8-compatibility") as String?).toBoolean() -if (JavaVersion.current() >= JavaVersion.VERSION_11 && jdk8compatibility == false) { +if (runtimeJavaVersion >= JavaVersion.VERSION_11) { val java11: SourceSet = sourceSets.create("java11") { java { compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output @@ -372,17 +381,4 @@ if (JavaVersion.current() >= JavaVersion.VERSION_11 && jdk8compatibility == fals testClassesDirs += java11.output.classesDirs classpath = sourceSets["java11"].runtimeClasspath } -} else if (jdk8compatibility == true) { - java { - toolchain { - languageVersion = JavaLanguageVersion.of(8) - vendor = JvmVendorSpec.ADOPTIUM - } - } - - tasks.register("tests-jdk8") { - javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(8) - } - } }