From 1ec0efdb7d0dd765f4a4feb7a3de0d729ef3e6aa Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 7 May 2024 07:04:09 +0000 Subject: [PATCH] Fix integrationTest builds for JDK-11 sourcesets (#968) Signed-off-by: Andriy Redko (cherry picked from commit de05226dbf29401a83580510c6067518f99087dc) Signed-off-by: github-actions[bot] Signed-off-by: Andriy Redko --- .ci/opensearch/Dockerfile | 1 + .github/workflows/test-integration.yml | 10 +++++++++- java-client/build.gradle.kts | 10 ++++++++-- .../transport/rest_client/RestClientTransport.java | 2 ++ .../opensearch/integTest/AbstractSearchRequestIT.java | 6 ++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.ci/opensearch/Dockerfile b/.ci/opensearch/Dockerfile index 33b2f77dff..b2322ce110 100644 --- a/.ci/opensearch/Dockerfile +++ b/.ci/opensearch/Dockerfile @@ -5,4 +5,5 @@ ARG opensearch_path=/usr/share/opensearch ARG opensearch_yml=$opensearch_path/config/opensearch.yml ARG SECURE_INTEGRATION +ENV OPENSEARCH_INITIAL_ADMIN_PASSWORD=0_aD^min_0 RUN if [ "$SECURE_INTEGRATION" != "true" ] ; then echo "plugins.security.disabled: true" >> $opensearch_yml; fi diff --git a/.github/workflows/test-integration.yml b/.github/workflows/test-integration.yml index ab31265580..7758a38f12 100644 --- a/.github/workflows/test-integration.yml +++ b/.github/workflows/test-integration.yml @@ -40,11 +40,19 @@ jobs: - name: Run Docker run: | + echo "PASSWORD=admin" >> $GITHUB_ENV docker-compose --project-directory .ci/opensearch build --build-arg OPENSEARCH_VERSION=${{ matrix.entry.opensearch_version }} docker-compose --project-directory .ci/opensearch up -d sleep 60 + + - name: Sets password (new versions) + run: | + if [[ ${{ matrix.entry.opensearch_version }} =~ ^2.1[2-9]+.[0-9]+$ ]]; then + echo "PASSWORD=0_aD^min_0" >> $GITHUB_ENV + fi + - name: Run Integration Test - run: ./gradlew clean integrationTest + run: ./gradlew clean integrationTest -Dpassword=${{ env.PASSWORD }} - name: Upload Reports if: failure() diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index 5616174874..b068e7ce8f 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -196,6 +196,7 @@ dependencies { exclude(group = "org.apache.httpcomponents.core5") } implementation("org.apache.httpcomponents.core5", "httpcore5", "5.2.4") + implementation("org.apache.httpcomponents.core5", "httpcore5-h2", "5.2.4") // For AwsSdk2Transport "awsSdk2SupportCompileOnly"("software.amazon.awssdk","sdk-core","[2.15,3.0)") @@ -374,8 +375,13 @@ if (runtimeJavaVersion >= JavaVersion.VERSION_11) { sourceCompatibility = JavaVersion.VERSION_11.toString() } - tasks.test { + tasks.named("integrationTest") { testClassesDirs += java11.output.classesDirs - classpath = sourceSets["java11"].runtimeClasspath + classpath += sourceSets["java11"].runtimeClasspath + } + + tasks.named("unitTest") { + testClassesDirs += java11.output.classesDirs + classpath += sourceSets["java11"].runtimeClasspath } } diff --git a/java-client/src/main/java/org/opensearch/client/transport/rest_client/RestClientTransport.java b/java-client/src/main/java/org/opensearch/client/transport/rest_client/RestClientTransport.java index dfd83611ea..6ad1ce5417 100644 --- a/java-client/src/main/java/org/opensearch/client/transport/rest_client/RestClientTransport.java +++ b/java-client/src/main/java/org/opensearch/client/transport/rest_client/RestClientTransport.java @@ -369,6 +369,8 @@ private ResponseT decodeResponse( String contentType = null; InputStream content = null; if (entity != null) { + // We may have to replay it. + entity = new BufferedHttpEntity(entity); if (entity.getContentType() != null) { contentType = entity.getContentType().getValue(); } diff --git a/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractSearchRequestIT.java b/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractSearchRequestIT.java index a34584f9f9..4874c33b85 100644 --- a/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractSearchRequestIT.java +++ b/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractSearchRequestIT.java @@ -11,6 +11,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; import org.junit.Test; import org.opensearch.Version; @@ -65,6 +66,7 @@ public void shouldReturnSearchResults() throws Exception { @Test public void hybridSearchShouldReturnSearchResults() throws Exception { assumeTrue("Hybrid search is supported from 2.10.0", getServerVersion().onOrAfter(Version.V_2_10_0)); + assumeTrue("Hybrid search needs opensearch-neural-search plugin to be installed", isNeuralSearchPluginInstalled()); final String index = "hybrid_search_request"; try { createIndex(index); @@ -138,6 +140,10 @@ public void shouldReturnSearchResultsWithExt() throws Exception { assertEquals(response.hits().hits().size(), 8); } + private boolean isNeuralSearchPluginInstalled() throws IOException { + return javaClient().cat().plugins().valueBody().stream().anyMatch(p -> Objects.equals(p.component(), "opensearch-neural-search")); + } + private void createTestDocuments(String index) throws IOException { javaClient().create(_1 -> _1.index(index).id("1").document(createItem("hummer", "huge", "yes", 2))); javaClient().create(_1 -> _1.index(index).id("2").document(createItem("jammer", "huge", "yes", 1)));