Skip to content

Commit

Permalink
Fix integrationTest builds for JDK-11 sourcesets (#968) (#971)
Browse files Browse the repository at this point in the history
(cherry picked from commit de05226)

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
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>
  • Loading branch information
1 parent ab69f34 commit a64b258
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions .ci/opensearch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 9 additions & 1 deletion .github/workflows/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down Expand Up @@ -374,8 +375,13 @@ if (runtimeJavaVersion >= JavaVersion.VERSION_11) {
sourceCompatibility = JavaVersion.VERSION_11.toString()
}

tasks.test {
tasks.named<Test>("integrationTest") {
testClassesDirs += java11.output.classesDirs
classpath = sourceSets["java11"].runtimeClasspath
classpath += sourceSets["java11"].runtimeClasspath
}

tasks.named<Test>("unitTest") {
testClassesDirs += java11.output.classesDirs
classpath += sourceSets["java11"].runtimeClasspath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ private <ResponseT> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.client.opensearch.integTest;

import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;

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

Map<String, Object> infoAsMap = response.getBody()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));
Expand Down

0 comments on commit a64b258

Please sign in to comment.