Skip to content

Test containers test run #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions samples/spring-ai-agent/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,8 @@
## Examples HTTP requests
chat-requests.http

## Prerequisite for external memory: PostgreSQL, for application started locally without container
```
docker run --name my-postgres \ ✘ 125
-e POSTGRES_DB=ai-agent-db \
-e POSTGRES_USER=chatuser \
-e POSTGRES_PASSWORD=chatpass \
-p 5432:5432 \
-d pgvector/pgvector:pg16
```
## Run locally
Run with test run to connect a pg-vector test containers for local dev

## Build Docker Image with JIB plugin
- mvn compile jib:dockerBuild

## Run postgres and spring-ai-agent containers
docker-compose up
`mvn spring-boot:test-run`

18 changes: 18 additions & 0 deletions samples/spring-ai-agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,20 @@
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-bedrock-converse</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-model-bedrock</artifactId>
</dependency>

<!-- RAG Dependencies -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-starter-vector-store-pgvector</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-advisors-vector-store</artifactId>
</dependency>

<!-- JDBC Postgres -->
<dependency>
Expand Down Expand Up @@ -83,11 +91,21 @@
<version>${testcontainers.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

import com.aws.workshop.ai.agent.AiAgentApplication;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.devtools.restart.RestartScope;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import java.util.List;
import java.util.Map;

public class TestAiAgentApplication {


public static void main(String[] args) {
System.out.println("!!!!!Starting test application");
System.setProperty("spring.sql.init.mode", "always");
SpringApplication.from(AiAgentApplication::main)
.with(TestContainersConfiguration.class)
.run(args);
}
}


@Configuration
@Testcontainers
class TestContainersConfiguration {

@Bean
@ServiceConnection
@RestartScope
PostgreSQLContainer<?> postgreSQLContainer() {
System.out.println("Starting postgreSQL container");
var image = DockerImageName.parse("pgvector/pgvector:pg16")
.asCompatibleSubstituteFor("postgres");
return new PostgreSQLContainer<>(image);
}
}


14 changes: 14 additions & 0 deletions samples/spring-ai-agent/src/test/resources/application-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
spring:
sql:
init:
mode: always
jpa:
hibernate:
ddl-auto: none
datasource:
driver-class-name: org.postgresql.Driver
ai:
vectorstore:
pgvector:
dimensions: 1024
initialize-schema: true