diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfigurationIT.java index 8535b8247..75d7fa9f9 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/ollama/OllamaAutoConfigurationIT.java @@ -16,7 +16,7 @@ package org.springframework.ai.autoconfigure.ollama; -import java.util.Map; +import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -30,8 +30,6 @@ import org.testcontainers.junit.jupiter.Testcontainers; import org.springframework.ai.ollama.client.OllamaClient; import org.springframework.boot.autoconfigure.AutoConfigurations; import org.springframework.boot.test.context.runner.ApplicationContextRunner; -import org.springframework.http.HttpEntity; -import org.springframework.web.client.RestTemplate; import static org.assertj.core.api.Assertions.assertThat; @@ -42,18 +40,17 @@ public class OllamaAutoConfigurationIT { private static final Log logger = LogFactory.getLog(OllamaAutoConfigurationIT.class); @Container - static GenericContainer ollamaContainer = new GenericContainer<>("ollama/ollama").withExposedPorts(11434); + static GenericContainer ollamaContainer = new GenericContainer<>("ollama/ollama:0.1.10").withExposedPorts(11434); private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withPropertyValues("spring.ai.ollama.baseUrl=http://localhost:" + ollamaContainer.getMappedPort(11434), - "spring.ai.ollama.model=orca-mini") + .withPropertyValues("spring.ai.ollama.baseUrl=http://" + ollamaContainer.getHost() + ":" + + ollamaContainer.getMappedPort(11434), "spring.ai.ollama.model=orca-mini") .withConfiguration(AutoConfigurations.of(OllamaAutoConfiguration.class)); @BeforeAll - public static void beforeAll() { + public static void beforeAll() throws IOException, InterruptedException { logger.info("Start pulling the 'orca-mini' model (3GB) ... would take several minutes ..."); - new RestTemplate().postForLocation("http://localhost:{port}/api/pull", - new HttpEntity<>(Map.of("name", "orca-mini")), ollamaContainer.getMappedPort(11434)); + ollamaContainer.execInContainer("ollama", "pull", "orca-mini"); logger.info("orca-mini pulling competed!"); } @@ -61,7 +58,8 @@ public class OllamaAutoConfigurationIT { void generate() { contextRunner.run(context -> { OllamaClient client = context.getBean(OllamaClient.class); - assertThat(client.getBaseUrl()).isEqualTo("http://localhost:" + ollamaContainer.getMappedPort(11434)); + assertThat(client.getBaseUrl()) + .isEqualTo("http://" + ollamaContainer.getHost() + ":" + ollamaContainer.getMappedPort(11434)); assertThat(client.getModel()).isEqualTo("orca-mini"); String response = client.generate("Hello"); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/chroma/ChromaVectorStoreAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/chroma/ChromaVectorStoreAutoConfigurationIT.java index 30bba69cf..2e4de2962 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/chroma/ChromaVectorStoreAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/chroma/ChromaVectorStoreAutoConfigurationIT.java @@ -49,7 +49,7 @@ public class ChromaVectorStoreAutoConfigurationIT { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of(ChromaVectorStoreAutoConfiguration.class)) .withUserConfiguration(Config.class) - .withPropertyValues("spring.ai.vectorstore.chroma.client.host=http://localhost", + .withPropertyValues("spring.ai.vectorstore.chroma.client.host=http://" + chromaContainer.getHost(), "spring.ai.vectorstore.chroma.client.port=" + chromaContainer.getMappedPort(8000), "spring.ai.vectorstore.chroma.store.collectionName=TestCollection"); diff --git a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/pgvector/PgVectorStoreAutoConfigurationIT.java b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/pgvector/PgVectorStoreAutoConfigurationIT.java index 33bdca50a..54a89c66b 100644 --- a/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/pgvector/PgVectorStoreAutoConfigurationIT.java +++ b/spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/vectorstore/pgvector/PgVectorStoreAutoConfigurationIT.java @@ -48,7 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class PgVectorStoreAutoConfigurationIT { @Container - static GenericContainer postgresContainer = new GenericContainer<>("ankane/pgvector") + static GenericContainer postgresContainer = new GenericContainer<>("ankane/pgvector:v0.5.1") .withEnv("POSTGRES_USER", "postgres") .withEnv("POSTGRES_PASSWORD", "postgres") .withExposedPorts(5432); @@ -74,7 +74,7 @@ public class PgVectorStoreAutoConfigurationIT { .withUserConfiguration(Config.class) .withPropertyValues("spring.ai.vectorstore.pgvector.distanceType=CosineDistance", // JdbcTemplate configuration - String.format("spring.datasource.url=jdbc:postgresql://localhost:%d/%s", + String.format("spring.datasource.url=jdbc:postgresql://%s:%d/%s", postgresContainer.getHost(), postgresContainer.getMappedPort(5432), "postgres"), "spring.datasource.username=postgres", "spring.datasource.password=postgres"); diff --git a/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/chroma/ChromaApiIT.java b/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/chroma/ChromaApiIT.java index 1b95393e0..125a6959d 100644 --- a/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/chroma/ChromaApiIT.java +++ b/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/chroma/ChromaApiIT.java @@ -176,9 +176,10 @@ public class ChromaApiIT { @Bean public ChromaApi chromaApi(RestTemplate restTemplate) { - + String host = chromaContainer.getHost(); int port = chromaContainer.getMappedPort(8000); - return new ChromaApi("http://localhost:" + port, restTemplate); + String baseUrl = "http://%s:%d".formatted(host, port); + return new ChromaApi(baseUrl, restTemplate); } } diff --git a/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/BasicAuthChromaWhereIT.java b/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/BasicAuthChromaWhereIT.java index 9e789943b..c57c5739a 100644 --- a/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/BasicAuthChromaWhereIT.java +++ b/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/BasicAuthChromaWhereIT.java @@ -58,8 +58,6 @@ import static org.assertj.core.api.Assertions.assertThat; @Testcontainers public class BasicAuthChromaWhereIT { - public static String CHROMA_SERVER_URL = "http://localhost:"; - /** * ChromaDB with Basic Authentication: * https://docs.trychroma.com/usage-guide#basic-authentication @@ -113,8 +111,10 @@ public class BasicAuthChromaWhereIT { @Bean public ChromaApi chromaApi(RestTemplate restTemplate) { + String host = chromaContainer.getHost(); int port = chromaContainer.getMappedPort(8000); - return new ChromaApi(CHROMA_SERVER_URL + port, restTemplate).withBasicAuthCredentials("admin", "admin"); + String baseUrl = "http://%s:%d".formatted(host, port); + return new ChromaApi(baseUrl, restTemplate).withBasicAuthCredentials("admin", "admin"); } @Bean diff --git a/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/ChromaVectorStoreIT.java b/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/ChromaVectorStoreIT.java index 7bddd4e98..f6e88c0f1 100644 --- a/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/ChromaVectorStoreIT.java +++ b/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/ChromaVectorStoreIT.java @@ -212,8 +212,10 @@ public class ChromaVectorStoreIT { @Bean public ChromaApi chromaApi(RestTemplate restTemplate) { + String host = chromaContainer.getHost(); int port = chromaContainer.getMappedPort(8000); - return new ChromaApi("http://localhost:" + port, restTemplate); + String baseUrl = "http://%s:%d".formatted(host, port); + return new ChromaApi(baseUrl, restTemplate); } @Bean diff --git a/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/TokenSecuredChromaWhereIT.java b/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/TokenSecuredChromaWhereIT.java index b7d7922f4..0c28a85e0 100644 --- a/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/TokenSecuredChromaWhereIT.java +++ b/vector-stores/spring-ai-chroma/src/test/java/org/springframework/experimental/ai/vectorstore/TokenSecuredChromaWhereIT.java @@ -57,8 +57,6 @@ import static org.assertj.core.api.Assertions.assertThat; @Testcontainers public class TokenSecuredChromaWhereIT { - public static String CHROMA_SERVER_URL = "http://localhost:"; - public static String CHROMA_SERVER_AUTH_CREDENTIALS = "test-token"; /** @@ -144,8 +142,10 @@ public class TokenSecuredChromaWhereIT { @Bean public ChromaApi chromaApi(RestTemplate restTemplate) { + String host = chromaContainer.getHost(); int port = chromaContainer.getMappedPort(8000); - var chromaApi = new ChromaApi(CHROMA_SERVER_URL + port, restTemplate); + String baseurl = "http://%s:%d".formatted(host, port); + var chromaApi = new ChromaApi(baseurl, restTemplate); chromaApi.withKeyToken(CHROMA_SERVER_AUTH_CREDENTIALS); return chromaApi; } diff --git a/vector-stores/spring-ai-milvus-store/src/test/java/org/springframework/ai/vectorstore/MilvusVectorStoreIT.java b/vector-stores/spring-ai-milvus-store/src/test/java/org/springframework/ai/vectorstore/MilvusVectorStoreIT.java index 039d308e5..fd19b8fdf 100644 --- a/vector-stores/spring-ai-milvus-store/src/test/java/org/springframework/ai/vectorstore/MilvusVectorStoreIT.java +++ b/vector-stores/spring-ai-milvus-store/src/test/java/org/springframework/ai/vectorstore/MilvusVectorStoreIT.java @@ -290,7 +290,7 @@ public class MilvusVectorStoreIT { @Bean public MilvusServiceClient milvusClient() { return new MilvusServiceClient(ConnectParam.newBuilder() - .withHost("localhost") + .withHost(milvusContainer.getServiceHost("standalone", 19530)) .withPort(milvusContainer.getServicePort("standalone", 19530)) .build()); } diff --git a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreIT.java b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreIT.java index 60ec87a9e..d6d154f09 100644 --- a/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreIT.java +++ b/vector-stores/spring-ai-pgvector-store/src/test/java/org/springframework/ai/vectorstore/PgVectorStoreIT.java @@ -70,7 +70,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class PgVectorStoreIT { @Container - static GenericContainer postgresContainer = new GenericContainer<>("ankane/pgvector") + static GenericContainer postgresContainer = new GenericContainer<>("ankane/pgvector:v0.5.1") .withEnv("POSTGRES_USER", "postgres") .withEnv("POSTGRES_PASSWORD", "postgres") .withExposedPorts(5432); @@ -95,7 +95,7 @@ public class PgVectorStoreIT { .withPropertyValues("test.spring.ai.vectorstore.pgvector.distanceType=CosineDistance", // JdbcTemplate configuration - String.format("app.datasource.url=jdbc:postgresql://localhost:%d/%s", + String.format("app.datasource.url=jdbc:postgresql://%s:%d/%s", postgresContainer.getHost(), postgresContainer.getMappedPort(5432), "postgres"), "app.datasource.username=postgres", "app.datasource.password=postgres", "app.datasource.type=com.zaxxer.hikari.HikariDataSource");