Skip to content

Commit

Permalink
Build this project and unit test using JDK 8. The integration tests c…
Browse files Browse the repository at this point in the history
…ompile and run using JDK 11. Uses OpenSearch low-level client 1.3.2 since this supports Java 8. opensearch-project#156
  • Loading branch information
dlvenable committed May 6, 2022
1 parent e14fb59 commit 711be71
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/checkstyle/checkstyle_suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
<suppress files="client[/\\]src[/\\]main[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]opensearch[^.]*\.java" checks="UnusedImports" />
<suppress files="client[/\\]src[/\\]main[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]opensearch[/\\]OpenSearch[^.]*\.java" checks="LineLength" />
<suppress files="client[/\\]src[/\\]main[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]opensearch[/\\]OpenSearch[^.]*\.java" checks="UnusedImports" />
<suppress files="client[/\\]src[/\\]test[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]opensearch[/\\]integTest[^.]*\.java" checks="Header" />
<suppress files="client[/\\]src[/\\]integrationTest[/\\]java[/\\]org[/\\]opensearch[/\\]client[/\\]opensearch[/\\]integTest[^.]*\.java" checks="Header" />
</suppressions>
49 changes: 39 additions & 10 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ checkstyle {
}

java {
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_11
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}

withJavadocJar()
withSourcesJar()
Expand Down Expand Up @@ -94,6 +95,28 @@ tasks.withType<Jar> {
}
}

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<JavaCompile>("compileIntegrationTestJava").configure {
javaCompiler.set(javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(11))
})
}

tasks.test {
systemProperty("tests.security.manager", "false")

Expand All @@ -105,15 +128,20 @@ tasks.test {
}

val unitTest = task<Test>("unitTest") {
filter {
excludeTestsMatching("org.opensearch.client.opensearch.integTest.*")
}
}

val integrationTest = task<Test>("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"))
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,7 +114,7 @@ public void testJacksonCustomJsonFactory() {
}

testDeserialize(mapper, writer.toString());
IOUtils.closeWhileHandlingException(writer);
closeWhileHandlingException(writer);
}

private void testSerialize(JsonpMapper mapper, String expected) {
Expand Down Expand Up @@ -196,4 +197,13 @@ public void setChildren(List<SomeClass> children) {
this.children = children;
}
}

private static void closeWhileHandlingException(final Closeable closeable) {
// noinspection EmptyCatchBlock
try {
if (closeable != null) {
closeable.close();
}
} catch (final IOException | RuntimeException e) {}
}
}

0 comments on commit 711be71

Please sign in to comment.