From 46781999fa648176e13d0945c43e456c7db11506 Mon Sep 17 00:00:00 2001 From: David Venable Date: Thu, 5 May 2022 20:03:16 -0500 Subject: [PATCH] Build this project and unit test using JDK 8. The integration tests compile and run using JDK 11. Uses OpenSearch low-level client 1.3.2 since this supports Java 8. #156 Signed-off-by: David Venable --- DEVELOPER_GUIDE.md | 4 +- config/checkstyle/checkstyle_suppressions.xml | 2 +- java-client/build.gradle.kts | 49 +++++++++++++++---- .../opensearch/integTest/ClusterClientIT.java | 0 .../client/opensearch/integTest/CrudIT.java | 0 .../opensearch/integTest/IndicesClientIT.java | 0 ...OpenSearchRestHighLevelClientTestCase.java | 0 .../opensearch/integTest/PingAndInfoIT.java | 0 .../opensearch/integTest/RequestTest.java | 0 .../opensearch/json/JsonpMapperTest.java | 14 +++++- 10 files changed, 55 insertions(+), 14 deletions(-) rename java-client/src/{test => integrationTest}/java/org/opensearch/client/opensearch/integTest/ClusterClientIT.java (100%) rename java-client/src/{test => integrationTest}/java/org/opensearch/client/opensearch/integTest/CrudIT.java (100%) rename java-client/src/{test => integrationTest}/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java (100%) rename java-client/src/{test => integrationTest}/java/org/opensearch/client/opensearch/integTest/OpenSearchRestHighLevelClientTestCase.java (100%) rename java-client/src/{test => integrationTest}/java/org/opensearch/client/opensearch/integTest/PingAndInfoIT.java (100%) rename java-client/src/{test => integrationTest}/java/org/opensearch/client/opensearch/integTest/RequestTest.java (100%) diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 0a6d9a4a63..f52be5f4d6 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -26,7 +26,9 @@ Fork [opensearch-project/opensearch-java](https://github.com/opensearch-project/ ### Install Prerequisites -To run the full suite of tests, download and install [JDK 14](https://jdk.java.net/archive/). Any JDK >= 11 works. +To run the full suite of tests, download and install [JDK 11](https://jdk.java.net/archive/). Any JDK >= 11 works. + +The build will additionally use a JDK 8 to compile the library. You may install your own SDK, or Gradle will install one. #### Docker diff --git a/config/checkstyle/checkstyle_suppressions.xml b/config/checkstyle/checkstyle_suppressions.xml index 20cd909876..12978d903d 100644 --- a/config/checkstyle/checkstyle_suppressions.xml +++ b/config/checkstyle/checkstyle_suppressions.xml @@ -41,5 +41,5 @@ - + diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index be30d29d34..7885407274 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -56,8 +56,9 @@ checkstyle { } java { - targetCompatibility = JavaVersion.VERSION_11 - sourceCompatibility = JavaVersion.VERSION_11 + toolchain { + languageVersion.set(JavaLanguageVersion.of(8)) + } withJavadocJar() withSourcesJar() @@ -94,6 +95,28 @@ tasks.withType { } } +sourceSets { + create("integrationTest") { + compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output + runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output + java { + setSrcDirs(listOf("src/integrationTest/java")) + } + } +} + +val integrationTestImplementation by configurations.getting { + extendsFrom(configurations.testImplementation.get()) +} + +configurations["integrationTestRuntimeOnly"].extendsFrom(configurations.runtimeOnly.get()) + +tasks.named("compileIntegrationTestJava").configure { + javaCompiler.set(javaToolchains.compilerFor { + languageVersion.set(JavaLanguageVersion.of(11)) + }) +} + tasks.test { systemProperty("tests.security.manager", "false") @@ -105,15 +128,20 @@ tasks.test { } val unitTest = task("unitTest") { - filter { - excludeTestsMatching("org.opensearch.client.opensearch.integTest.*") - } } val integrationTest = task("integrationTest") { - filter { - includeTestsMatching("org.opensearch.client.opensearch.integTest.*") - } + description = "Runs integration tests." + group = "verification" + + testClassesDirs = sourceSets["integrationTest"].output.classesDirs + classpath = sourceSets["integrationTest"].runtimeClasspath + shouldRunAfter("test") + + javaLauncher.set(javaToolchains.launcherFor { + languageVersion.set(JavaLanguageVersion.of(11)) + }) + systemProperty("tests.security.manager", "false") // Basic auth settings for integration test systemProperty("https", System.getProperty("https", "true")) @@ -128,8 +156,8 @@ dependencies { val jacksonDatabindVersion = "2.12.6.1" // Apache 2.0 - implementation("org.opensearch.client", "opensearch-rest-client", opensearchVersion) - testImplementation("org.opensearch.test", "framework", opensearchVersion) + implementation("org.opensearch.client", "opensearch-rest-client", "1.3.2") + integrationTestImplementation("org.opensearch.test", "framework", opensearchVersion) implementation("org.apache.logging.log4j", "log4j-core", "2.17.2") // Apache 2.0 @@ -158,6 +186,7 @@ dependencies { // EPL-2.0 OR BSD-3-Clause // https://eclipse-ee4j.github.io/yasson/ implementation("org.eclipse", "yasson", "2.0.2") + testImplementation("org.hamcrest:hamcrest:2.1") // https://github.com/classgraph/classgraph testImplementation("io.github.classgraph:classgraph:4.8.116") diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/ClusterClientIT.java b/java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/ClusterClientIT.java similarity index 100% rename from java-client/src/test/java/org/opensearch/client/opensearch/integTest/ClusterClientIT.java rename to java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/ClusterClientIT.java diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/CrudIT.java b/java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/CrudIT.java similarity index 100% rename from java-client/src/test/java/org/opensearch/client/opensearch/integTest/CrudIT.java rename to java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/CrudIT.java diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java b/java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java similarity index 100% rename from java-client/src/test/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java rename to java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/IndicesClientIT.java diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchRestHighLevelClientTestCase.java b/java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/OpenSearchRestHighLevelClientTestCase.java similarity index 100% rename from java-client/src/test/java/org/opensearch/client/opensearch/integTest/OpenSearchRestHighLevelClientTestCase.java rename to java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/OpenSearchRestHighLevelClientTestCase.java diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/PingAndInfoIT.java b/java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/PingAndInfoIT.java similarity index 100% rename from java-client/src/test/java/org/opensearch/client/opensearch/integTest/PingAndInfoIT.java rename to java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/PingAndInfoIT.java diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/integTest/RequestTest.java b/java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/RequestTest.java similarity index 100% rename from java-client/src/test/java/org/opensearch/client/opensearch/integTest/RequestTest.java rename to java-client/src/integrationTest/java/org/opensearch/client/opensearch/integTest/RequestTest.java diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpMapperTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpMapperTest.java index 5c024e8124..bcdfb9b267 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpMapperTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/json/JsonpMapperTest.java @@ -48,8 +48,9 @@ import jakarta.json.stream.JsonParser; import org.junit.Assert; import org.junit.Test; -import org.opensearch.core.internal.io.IOUtils; +import java.io.Closeable; +import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import java.io.Writer; @@ -113,7 +114,7 @@ public void testJacksonCustomJsonFactory() { } testDeserialize(mapper, writer.toString()); - IOUtils.closeWhileHandlingException(writer); + closeWhileHandlingException(writer); } private void testSerialize(JsonpMapper mapper, String expected) { @@ -196,4 +197,13 @@ public void setChildren(List children) { this.children = children; } } + + private static void closeWhileHandlingException(final Closeable closeable) { + // noinspection EmptyCatchBlock + try { + if (closeable != null) { + closeable.close(); + } + } catch (final IOException | RuntimeException e) {} + } }