Skip to content

Commit

Permalink
Add an integration test that runs on JDK-8
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta committed Jan 2, 2024
1 parent a8fea24 commit 220a560
Show file tree
Hide file tree
Showing 23 changed files with 110 additions and 46 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/test-jdk8-compat-unit.yml
Original file line number Diff line number Diff line change
@@ -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
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
19 changes: 17 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 @@ -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
Expand Down Expand Up @@ -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<Test>("tests-jdk8") {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(8)
}
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,15 +18,19 @@ public class PutIndexTemplateRequestTest extends Assert {
@Test
public void deserialize_validFieldsIncluded_RequestIsBuilt() throws JsonProcessingException {
final JsonpMapper mapper = new JsonbJsonpMapper();
final Map<String, Object> indexTemplateMap = Map.of("name", "test", "index_patterns", "*", "create", true, "priority", 1);
final Map<String, Object> 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);
}

Expand Down
Loading

0 comments on commit 220a560

Please sign in to comment.