Skip to content

Commit

Permalink
Add an integration test that runs on JDK-8 (#795)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
reta authored Jan 3, 2024
1 parent a8fea24 commit f8ec75e
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 47 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -63,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
Expand All @@ -73,6 +80,11 @@ java {
registerFeature("awsSdk2Support") {
usingSourceSet(sourceSets.get("main"))
}

toolchain {
languageVersion = JavaLanguageVersion.of(runtimeJavaVersion.majorVersion)
vendor = JvmVendorSpec.ADOPTIUM
}
}

tasks.withType<ProcessResources> {
Expand Down Expand Up @@ -337,7 +349,7 @@ publishing {
}
}

if (JavaVersion.current() >= JavaVersion.VERSION_11) {
if (runtimeJavaVersion >= JavaVersion.VERSION_11) {
val java11: SourceSet = sourceSets.create("java11") {
java {
compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output
Expand Down Expand Up @@ -369,5 +381,4 @@ if (JavaVersion.current() >= JavaVersion.VERSION_11) {
testClassesDirs += java11.output.classesDirs
classpath = sourceSets["java11"].runtimeClasspath
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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;

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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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 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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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 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();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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 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();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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 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();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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 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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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 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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
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 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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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;

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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.opensearch.client.opensearch.core;

import java.util.List;
import java.util.Collections;
import org.junit.Assert;
import org.junit.Test;

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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.opensearch.client.opensearch.core;

import java.util.List;
import java.util.Collections;
import org.junit.Assert;
import org.junit.Test;

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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package org.opensearch.client.opensearch.core;

import java.util.List;
import java.util.Collections;
import org.junit.Assert;
import org.junit.Test;

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());
Expand Down
Loading

0 comments on commit f8ec75e

Please sign in to comment.