Polish OpenSearch and Vearch IT (#1325)

* Update LocaStack image version
* Avoid custom LocalStackContainer configuration
* Fixed Vearch image version
* Use copyFileToContainer

Note: almost all Vearch IT works with version `3.4.x`.
`should_add_embedding_with_segment_with_metadata` fails with

```
status code: 400; body: {"error":{"root_cause":[{"type":"","reason":"param have error field [long_0]"}],"type":"","reason":"param have error field [long_0]"},"status":400}
```
This commit is contained in:
Eddú Meléndez Gonzales 2024-06-20 02:13:16 -06:00 committed by GitHub
parent dc0effe67e
commit 3084c5827f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 43 deletions

View File

@ -1,6 +1,5 @@
package dev.langchain4j.store.embedding.opensearch;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.jayway.jsonpath.JsonPath;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.model.embedding.AllMiniLmL6V2QuantizedEmbeddingModel;
@ -12,7 +11,7 @@ import net.minidev.json.JSONArray;
import org.junit.jupiter.api.BeforeAll;
import org.opensearch.client.transport.aws.AwsSdk2TransportOptions;
import org.testcontainers.containers.Container.ExecResult;
import org.testcontainers.images.builder.Transferable;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
@ -30,7 +29,8 @@ import static org.awaitility.Awaitility.await;
class OpenSearchEmbeddingStoreAwsIT extends EmbeddingStoreIT {
@Container
private static final LocalStackContainer localstack = new LocalStackContainer(DockerImageName.parse("localstack/localstack:3.1.0"));
private static final LocalStackContainer localstack = new LocalStackContainer(DockerImageName.parse("localstack/localstack:3.5.0"))
.withEnv("LOCALSTACK_HOST", "localhost.localstack.cloud");
EmbeddingStore<TextSegment> embeddingStore = OpenSearchEmbeddingStore.builder()
.serverUrl(String.format("testcontainers-domain.%s.opensearch.localhost.localstack.cloud:%s", localstack.getRegion(), localstack.getMappedPort(4566)))
@ -81,25 +81,4 @@ class OpenSearchEmbeddingStoreAwsIT extends EmbeddingStoreIT {
Thread.sleep(1000);
}
static class LocalStackContainer extends org.testcontainers.containers.localstack.LocalStackContainer {
private static final String STARTER_SCRIPT = "/testcontainers_start.sh";
public LocalStackContainer(DockerImageName dockerImageName) {
super(dockerImageName);
withCreateContainerCmdModifier(cmd -> cmd.withEntrypoint("sh"));
setCommand("-c", "while [ ! -f " + STARTER_SCRIPT + " ]; do sleep 0.1; done; " + STARTER_SCRIPT);
withEnv("LOCALSTACK_HOST", "localhost.localstack.cloud");
withEnv("SERVICES", "opensearch");
}
@Override
protected void containerIsStarting(InspectContainerResponse containerInfo) {
String command = "#!/bin/bash\n";
command += "export LOCALSTACK_HOST=:" + getMappedPort(4566) + "\n";
command += "/usr/local/bin/docker-entrypoint.sh";
copyFileToContainer(Transferable.of(command, 0777), STARTER_SCRIPT);
}
}
}

View File

@ -5,17 +5,16 @@ import dev.langchain4j.model.embedding.AllMiniLmL6V2QuantizedEmbeddingModel;
import dev.langchain4j.model.embedding.EmbeddingModel;
import dev.langchain4j.store.embedding.EmbeddingStore;
import dev.langchain4j.store.embedding.EmbeddingStoreIT;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -24,12 +23,14 @@ import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
@TestMethodOrder(DeleteSpaceLastOrderer.class)
public class VearchEmbeddingStoreIT extends EmbeddingStoreIT {
@Testcontainers
class VearchEmbeddingStoreIT extends EmbeddingStoreIT {
static String configPath = VearchEmbeddingStoreIT.class.getClassLoader().getResource("config.toml").getPath();
static GenericContainer<?> vearch = new GenericContainer<>(DockerImageName.parse("vearch/vearch:latest"))
@Container
static GenericContainer<?> vearch = new GenericContainer<>(DockerImageName.parse("vearch/vearch:3.4.1"))
.withExposedPorts(9001, 8817)
.withCommand("all")
.withFileSystemBind(configPath, "/vearch/config.toml", BindMode.READ_ONLY)
.withCopyFileToContainer(MountableFile.forClasspathResource("config.toml"), "/vearch/config.toml")
.waitingFor(Wait.forLogMessage(".*INFO : server pid:1.*\\n", 1));
VearchEmbeddingStore embeddingStore;
@ -101,17 +102,6 @@ public class VearchEmbeddingStoreIT extends EmbeddingStoreIT {
.build();
}
@BeforeAll
static void beforeAll() {
vearch.setPortBindings(Arrays.asList("9001:9001", "8817:8817"));
vearch.start();
}
@AfterAll
static void afterAll() {
vearch.stop();
}
@Override
protected EmbeddingStore<TextSegment> embeddingStore() {
return embeddingStore;