Skip to content

Commit f8ec75e

Browse files
authored
Add an integration test that runs on JDK-8 (opensearch-project#795)
* Add an integration test that runs on JDK-8 Signed-off-by: Andriy Redko <[email protected]> * Refactor the runtime Java selection Signed-off-by: Andriy Redko <[email protected]> --------- Signed-off-by: Andriy Redko <[email protected]>
1 parent a8fea24 commit f8ec75e

23 files changed

+90
-47
lines changed

.github/workflows/test-unit.yml

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ${{ matrix.os }}
88
strategy:
99
matrix:
10-
java: [ 11, 17, 21 ]
10+
java: [ 8, 11, 17, 21 ]
1111
os: [ubuntu-latest, windows-latest, macOS-latest]
1212
steps:
1313
- name: Checkout Java Client
@@ -21,4 +21,17 @@ jobs:
2121
cache: 'gradle'
2222

2323
- name: Run Unit Test
24+
if: ${{ matrix.java != 8 }}
2425
run: ./gradlew clean unitTest
26+
27+
- name: Set up JDK 11
28+
uses: actions/setup-java@v3
29+
if: ${{ matrix.java == 8 }}
30+
with:
31+
java-version: 11
32+
distribution: 'temurin'
33+
cache: 'gradle'
34+
35+
- name: Run Unit Test
36+
if: ${{ matrix.java == 8 }}
37+
run: ./gradlew clean unitTest -D"runtime.java=8"

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ This section is for maintaining a changelog for all breaking changes for the cli
4949

5050
### Changed
5151
- Restore support for Java 8 ([#767](https://github.com/opensearch-project/opensearch-java/pull/767))
52+
- Add an integration test that runs on JDK-8 ([#795](https://github.com/opensearch-project/opensearch-java/pull/795))
5253

5354
### Deprecated
5455
- Deprecated "_toQuery()" in Query and QueryVariant ([#760](https://github.com/opensearch-project/opensearch-java/pull/760)

java-client/build.gradle.kts

+13-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import com.github.jk1.license.ProjectData
3434
import com.github.jk1.license.render.ReportRenderer
35+
import org.gradle.api.tasks.testing.Test
3536
import java.io.FileWriter
3637

3738
buildscript {
@@ -63,6 +64,12 @@ configurations {
6364
}
6465
}
6566

67+
val runtimeJavaVersion = (System.getProperty("runtime.java")?.toInt())?.let(JavaVersion::toVersion) ?: JavaVersion.current()
68+
logger.quiet("=======================================")
69+
logger.quiet(" Runtime JDK Version : " + runtimeJavaVersion)
70+
logger.quiet(" Gradle JDK Version : " + JavaVersion.current())
71+
logger.quiet("=======================================")
72+
6673
java {
6774
targetCompatibility = JavaVersion.VERSION_1_8
6875
sourceCompatibility = JavaVersion.VERSION_1_8
@@ -73,6 +80,11 @@ java {
7380
registerFeature("awsSdk2Support") {
7481
usingSourceSet(sourceSets.get("main"))
7582
}
83+
84+
toolchain {
85+
languageVersion = JavaLanguageVersion.of(runtimeJavaVersion.majorVersion)
86+
vendor = JvmVendorSpec.ADOPTIUM
87+
}
7688
}
7789

7890
tasks.withType<ProcessResources> {
@@ -337,7 +349,7 @@ publishing {
337349
}
338350
}
339351

340-
if (JavaVersion.current() >= JavaVersion.VERSION_11) {
352+
if (runtimeJavaVersion >= JavaVersion.VERSION_11) {
341353
val java11: SourceSet = sourceSets.create("java11") {
342354
java {
343355
compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
@@ -369,5 +381,4 @@ if (JavaVersion.current() >= JavaVersion.VERSION_11) {
369381
testClassesDirs += java11.output.classesDirs
370382
classpath = sourceSets["java11"].runtimeClasspath
371383
}
372-
373384
}

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQueryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch._types.GeoLocation;
66
import org.opensearch.client.opensearch.model.ModelTestCase;
@@ -9,7 +9,7 @@ public class GeoDistanceQueryTest extends ModelTestCase {
99
@Test
1010
public void toBuilder() {
1111
GeoDistanceQuery origin = new GeoDistanceQuery.Builder().field("field")
12-
.location(new GeoLocation.Builder().coords(List.of(1.0)).build())
12+
.location(new GeoLocation.Builder().coords(Collections.singletonList(1.0)).build())
1313
.build();
1414
GeoDistanceQuery copied = origin.toBuilder().build();
1515

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQueryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch._types.FieldValue;
66
import org.opensearch.client.opensearch.model.ModelTestCase;
77

88
public class PinnedQueryTest extends ModelTestCase {
99
@Test
1010
public void toBuilder() {
11-
PinnedQuery origin = new PinnedQuery.Builder().organic(buildDummyQuery()).ids(List.of("1")).build();
11+
PinnedQuery origin = new PinnedQuery.Builder().organic(buildDummyQuery()).ids(Collections.singletonList("1")).build();
1212
PinnedQuery copied = origin.toBuilder().build();
1313

1414
assertEquals(toJson(copied), toJson(origin));

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQueryTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch.model.ModelTestCase;
66

77
public class SpanContainingQueryTest extends ModelTestCase {
88
@Test
99
public void toBuilder() {
1010
SpanContainingQuery origin = new SpanContainingQuery.Builder().big(
11-
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()
12-
).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build();
11+
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
12+
).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build();
1313
SpanContainingQuery copied = origin.toBuilder().build();
1414

1515
assertEquals(toJson(copied), toJson(origin));

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQueryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch.model.ModelTestCase;
66

77
public class SpanFieldMaskingQueryTest extends ModelTestCase {
88
@Test
99
public void toBuilder() {
1010
SpanFieldMaskingQuery origin = new SpanFieldMaskingQuery.Builder().field("field")
11-
.query(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build())
11+
.query(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build())
1212
.build();
1313
SpanFieldMaskingQuery copied = origin.toBuilder().build();
1414

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQueryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch.model.ModelTestCase;
66

77
public class SpanFirstQueryTest extends ModelTestCase {
88
@Test
99
public void toBuilder() {
1010
SpanFirstQuery origin = new SpanFirstQuery.Builder().end(1)
11-
.match(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build())
11+
.match(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build())
1212
.build();
1313
SpanFirstQuery copied = origin.toBuilder().build();
1414

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQueryTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch.model.ModelTestCase;
66

77
public class SpanNearQueryTest extends ModelTestCase {
88
@Test
99
public void toBuilder() {
1010
SpanNearQuery origin = new SpanNearQuery.Builder().clauses(
11-
List.of(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build())
11+
Collections.singletonList(
12+
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
13+
)
1214
).build();
1315
SpanNearQuery copied = origin.toBuilder().build();
1416

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQueryTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch.model.ModelTestCase;
66

77
public class SpanNotQueryTest extends ModelTestCase {
88
@Test
99
public void toBuilder() {
1010
SpanNotQuery origin = new SpanNotQuery.Builder().include(
11-
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()
12-
).exclude(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build();
11+
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
12+
).exclude(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build();
1313
SpanNotQuery copied = origin.toBuilder().build();
1414

1515
assertEquals(toJson(copied), toJson(origin));

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQueryTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch.model.ModelTestCase;
66

77
public class SpanOrQueryTest extends ModelTestCase {
88
@Test
99
public void toBuilder() {
1010
SpanOrQuery origin = new SpanOrQuery.Builder().clauses(
11-
List.of(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build())
11+
Collections.singletonList(
12+
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
13+
)
1214
).build();
1315
SpanOrQuery copied = origin.toBuilder().build();
1416

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanQueryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch.model.ModelTestCase;
66

77
public class SpanQueryTest extends ModelTestCase {
88
@Test
99
public void toBuilder() {
10-
SpanQuery origin = new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build();
10+
SpanQuery origin = new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build();
1111
SpanQuery copied = origin.toBuilder().build();
1212

1313
assertEquals(toJson(copied), toJson(origin));

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQueryTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch.model.ModelTestCase;
66

77
public class SpanWithinQueryTest extends ModelTestCase {
88
@Test
99
public void toBuilder() {
1010
SpanWithinQuery origin = new SpanWithinQuery.Builder().big(
11-
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()
12-
).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(List.of()).build()).build()).build();
11+
new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()
12+
).little(new SpanQuery.Builder().spanOr(new SpanOrQuery.Builder().clauses(Collections.emptyList()).build()).build()).build();
1313
SpanWithinQuery copied = origin.toBuilder().build();
1414

1515
assertEquals(toJson(copied), toJson(origin));

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryFieldTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch._types.FieldValue;
66
import org.opensearch.client.opensearch.model.ModelTestCase;
77

88
public class TermsQueryFieldTest extends ModelTestCase {
99
@Test
1010
public void toBuilder() {
11-
TermsQueryField origin = new TermsQueryField.Builder().value(List.of(FieldValue.of("1"))).build();
11+
TermsQueryField origin = new TermsQueryField.Builder().value(Collections.singletonList(FieldValue.of("1"))).build();
1212
TermsQueryField copied = origin.toBuilder().build();
1313

1414
assertEquals(toJson(copied), toJson(origin));

java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQueryTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.opensearch.client.opensearch._types.query_dsl;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Test;
55
import org.opensearch.client.opensearch._types.FieldValue;
66
import org.opensearch.client.opensearch.model.ModelTestCase;
@@ -9,7 +9,7 @@ public class TermsQueryTest extends ModelTestCase {
99
@Test
1010
public void toBuilder() {
1111
TermsQuery origin = new TermsQuery.Builder().field("field")
12-
.terms(new TermsQueryField.Builder().value(List.of(FieldValue.of("1"))).build())
12+
.terms(new TermsQueryField.Builder().value(Collections.singletonList(FieldValue.of("1"))).build())
1313
.build();
1414
TermsQuery copied = origin.toBuilder().build();
1515

java-client/src/test/java/org/opensearch/client/opensearch/core/BulkRequestTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.opensearch.client.opensearch.core;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Assert;
55
import org.junit.Test;
66
import org.opensearch.client.opensearch.core.bulk.BulkOperation;
@@ -11,7 +11,9 @@ public class BulkRequestTest extends Assert {
1111
@Test
1212
public void toBuilder() {
1313
BulkRequest origin = new BulkRequest.Builder().index("index")
14-
.operations(List.of(new BulkOperation.Builder().delete(new DeleteOperation.Builder().id("id").build()).build()))
14+
.operations(
15+
Collections.singletonList(new BulkOperation.Builder().delete(new DeleteOperation.Builder().id("id").build()).build())
16+
)
1517
.build();
1618
BulkRequest copied = origin.toBuilder().build();
1719

java-client/src/test/java/org/opensearch/client/opensearch/core/ClearScrollRequestTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.opensearch.client.opensearch.core;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Assert;
55
import org.junit.Test;
66

77
public class ClearScrollRequestTest extends Assert {
88

99
@Test
1010
public void toBuilder() {
11-
ClearScrollRequest origin = new ClearScrollRequest.Builder().scrollId(List.of("1")).build();
11+
ClearScrollRequest origin = new ClearScrollRequest.Builder().scrollId(Collections.singletonList("1")).build();
1212
ClearScrollRequest copied = origin.toBuilder().build();
1313

1414
assertEquals(copied.scrollId(), origin.scrollId());

java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchRequestTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.opensearch.client.opensearch.core;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Assert;
55
import org.junit.Test;
66

77
public class MsearchRequestTest extends Assert {
88

99
@Test
1010
public void toBuilder() {
11-
MsearchRequest origin = new MsearchRequest.Builder().index("index").searches(List.of()).build();
11+
MsearchRequest origin = new MsearchRequest.Builder().index("index").searches(Collections.emptyList()).build();
1212
MsearchRequest copied = origin.toBuilder().build();
1313

1414
assertEquals(copied.index(), origin.index());

java-client/src/test/java/org/opensearch/client/opensearch/core/MsearchTemplateRequestTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
package org.opensearch.client.opensearch.core;
22

3-
import java.util.List;
3+
import java.util.Collections;
44
import org.junit.Assert;
55
import org.junit.Test;
66

77
public class MsearchTemplateRequestTest extends Assert {
88

99
@Test
1010
public void toBuilder() {
11-
MsearchTemplateRequest origin = new MsearchTemplateRequest.Builder().index("index").searchTemplates(List.of()).build();
11+
MsearchTemplateRequest origin = new MsearchTemplateRequest.Builder().index("index")
12+
.searchTemplates(Collections.emptyList())
13+
.build();
1214
MsearchTemplateRequest copied = origin.toBuilder().build();
1315

1416
assertEquals(copied.index(), origin.index());

0 commit comments

Comments
 (0)