Skip to content

Commit a64b258

Browse files
Fix integrationTest builds for JDK-11 sourcesets (#968) (#971)
(cherry picked from commit de05226) Signed-off-by: Andriy Redko <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent ab69f34 commit a64b258

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

.ci/opensearch/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ ARG opensearch_path=/usr/share/opensearch
55
ARG opensearch_yml=$opensearch_path/config/opensearch.yml
66

77
ARG SECURE_INTEGRATION
8+
ENV OPENSEARCH_INITIAL_ADMIN_PASSWORD=0_aD^min_0
89
RUN if [ "$SECURE_INTEGRATION" != "true" ] ; then echo "plugins.security.disabled: true" >> $opensearch_yml; fi

.github/workflows/test-integration.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,19 @@ jobs:
4040

4141
- name: Run Docker
4242
run: |
43+
echo "PASSWORD=admin" >> $GITHUB_ENV
4344
docker-compose --project-directory .ci/opensearch build --build-arg OPENSEARCH_VERSION=${{ matrix.entry.opensearch_version }}
4445
docker-compose --project-directory .ci/opensearch up -d
4546
sleep 60
47+
48+
- name: Sets password (new versions)
49+
run: |
50+
if [[ ${{ matrix.entry.opensearch_version }} =~ ^2.1[2-9]+.[0-9]+$ ]]; then
51+
echo "PASSWORD=0_aD^min_0" >> $GITHUB_ENV
52+
fi
53+
4654
- name: Run Integration Test
47-
run: ./gradlew clean integrationTest
55+
run: ./gradlew clean integrationTest -Dpassword=${{ env.PASSWORD }}
4856

4957
- name: Upload Reports
5058
if: failure()

java-client/build.gradle.kts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ dependencies {
196196
exclude(group = "org.apache.httpcomponents.core5")
197197
}
198198
implementation("org.apache.httpcomponents.core5", "httpcore5", "5.2.4")
199+
implementation("org.apache.httpcomponents.core5", "httpcore5-h2", "5.2.4")
199200

200201
// For AwsSdk2Transport
201202
"awsSdk2SupportCompileOnly"("software.amazon.awssdk","sdk-core","[2.15,3.0)")
@@ -374,8 +375,13 @@ if (runtimeJavaVersion >= JavaVersion.VERSION_11) {
374375
sourceCompatibility = JavaVersion.VERSION_11.toString()
375376
}
376377

377-
tasks.test {
378+
tasks.named<Test>("integrationTest") {
378379
testClassesDirs += java11.output.classesDirs
379-
classpath = sourceSets["java11"].runtimeClasspath
380+
classpath += sourceSets["java11"].runtimeClasspath
381+
}
382+
383+
tasks.named<Test>("unitTest") {
384+
testClassesDirs += java11.output.classesDirs
385+
classpath += sourceSets["java11"].runtimeClasspath
380386
}
381387
}

java-client/src/main/java/org/opensearch/client/transport/rest_client/RestClientTransport.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ private <ResponseT> ResponseT decodeResponse(
369369
String contentType = null;
370370
InputStream content = null;
371371
if (entity != null) {
372+
// We may have to replay it.
373+
entity = new BufferedHttpEntity(entity);
372374
if (entity.getContentType() != null) {
373375
contentType = entity.getContentType().getValue();
374376
}

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractPingAndInfoIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.opensearch.client.opensearch.integTest;
1010

11+
import static org.hamcrest.CoreMatchers.anyOf;
1112
import static org.hamcrest.CoreMatchers.equalTo;
1213
import static org.hamcrest.CoreMatchers.is;
1314

@@ -34,7 +35,7 @@ public void testInfo() throws IOException {
3435
// compare with what the low level client outputs
3536
try (Response response = javaClient().generic().execute(Requests.builder().endpoint("/").method("GET").build())) {
3637
assertThat(response.getStatus(), equalTo(200));
37-
assertThat(response.getProtocol(), equalTo("HTTP/1.1"));
38+
assertThat(response.getProtocol(), anyOf(equalTo("HTTP"), equalTo("HTTP/1.1")));
3839
assertThat(response.getBody().isEmpty(), is(false));
3940

4041
Map<String, Object> infoAsMap = response.getBody()

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractSearchRequestIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.IOException;
1212
import java.util.Arrays;
1313
import java.util.Map;
14+
import java.util.Objects;
1415
import java.util.stream.Collectors;
1516
import org.junit.Test;
1617
import org.opensearch.Version;
@@ -65,6 +66,7 @@ public void shouldReturnSearchResults() throws Exception {
6566
@Test
6667
public void hybridSearchShouldReturnSearchResults() throws Exception {
6768
assumeTrue("Hybrid search is supported from 2.10.0", getServerVersion().onOrAfter(Version.V_2_10_0));
69+
assumeTrue("Hybrid search needs opensearch-neural-search plugin to be installed", isNeuralSearchPluginInstalled());
6870
final String index = "hybrid_search_request";
6971
try {
7072
createIndex(index);
@@ -138,6 +140,10 @@ public void shouldReturnSearchResultsWithExt() throws Exception {
138140
assertEquals(response.hits().hits().size(), 8);
139141
}
140142

143+
private boolean isNeuralSearchPluginInstalled() throws IOException {
144+
return javaClient().cat().plugins().valueBody().stream().anyMatch(p -> Objects.equals(p.component(), "opensearch-neural-search"));
145+
}
146+
141147
private void createTestDocuments(String index) throws IOException {
142148
javaClient().create(_1 -> _1.index(index).id("1").document(createItem("hummer", "huge", "yes", 2)));
143149
javaClient().create(_1 -> _1.index(index).id("2").document(createItem("jammer", "huge", "yes", 1)));

0 commit comments

Comments
 (0)