|
16 | 16 |
|
17 | 17 | package org.springframework.ai.chat.memory.repository.jdbc;
|
18 | 18 |
|
19 |
| -import java.util.List; |
20 |
| -import java.util.UUID; |
21 |
| - |
22 |
| -import javax.sql.DataSource; |
23 |
| - |
24 |
| -import org.junit.jupiter.api.Test; |
25 |
| - |
26 |
| -import org.springframework.ai.chat.memory.ChatMemoryRepository; |
27 |
| -import org.springframework.ai.chat.messages.AssistantMessage; |
28 |
| -import org.springframework.ai.chat.messages.Message; |
29 |
| -import org.springframework.ai.chat.messages.SystemMessage; |
30 |
| -import org.springframework.ai.chat.messages.UserMessage; |
31 |
| -import org.springframework.boot.SpringBootConfiguration; |
32 | 19 | import org.springframework.boot.test.context.SpringBootTest;
|
33 |
| -import org.springframework.context.annotation.Bean; |
34 |
| -import org.springframework.jdbc.core.JdbcTemplate; |
35 |
| -import org.springframework.jdbc.datasource.DataSourceTransactionManager; |
36 | 20 | import org.springframework.test.context.TestPropertySource;
|
37 | 21 | import org.springframework.test.context.jdbc.Sql;
|
38 | 22 |
|
39 |
| -import static org.assertj.core.api.Assertions.assertThat; |
40 |
| - |
41 | 23 | /**
|
42 | 24 | * Integration tests for {@link JdbcChatMemoryRepository} with PostgreSQL.
|
43 | 25 | *
|
44 | 26 | * @author Jonathan Leijendekker
|
45 | 27 | * @author Thomas Vitale
|
46 | 28 | * @author Mark Pollack
|
| 29 | + * @author Yanming Zhou |
47 | 30 | */
|
48 |
| -@SpringBootTest(classes = JdbcChatMemoryRepositoryPostgresqlIT.TestConfiguration.class) |
49 |
| -@TestPropertySource(properties = { "spring.datasource.url=jdbc:tc:postgresql:17:///", |
50 |
| - "spring.datasource.hikari.maximum-pool-size=20", "spring.datasource.hikari.minimum-idle=5" }) |
| 31 | +@SpringBootTest |
| 32 | +@TestPropertySource(properties = "spring.datasource.url=jdbc:tc:postgresql:17:///") |
51 | 33 | @Sql(scripts = "classpath:org/springframework/ai/chat/memory/repository/jdbc/schema-postgresql.sql")
|
52 | 34 | class JdbcChatMemoryRepositoryPostgresqlIT extends AbstractJdbcChatMemoryRepositoryIT {
|
53 | 35 |
|
54 |
| - @Test |
55 |
| - void repositoryWithExplicitTransactionManager() { |
56 |
| - // Get the repository with explicit transaction manager |
57 |
| - ChatMemoryRepository repositoryWithTxManager = TestConfiguration |
58 |
| - .chatMemoryRepositoryWithTransactionManager(this.jdbcTemplate, this.jdbcTemplate.getDataSource()); |
59 |
| - |
60 |
| - var conversationId = UUID.randomUUID().toString(); |
61 |
| - var messages = List.<Message>of(new AssistantMessage("Message with transaction manager - " + conversationId), |
62 |
| - new UserMessage("User message with transaction manager - " + conversationId)); |
63 |
| - |
64 |
| - // Save messages using the repository with explicit transaction manager |
65 |
| - repositoryWithTxManager.saveAll(conversationId, messages); |
66 |
| - |
67 |
| - // Verify messages were saved correctly |
68 |
| - var savedMessages = repositoryWithTxManager.findByConversationId(conversationId); |
69 |
| - assertThat(savedMessages).hasSize(2); |
70 |
| - assertThat(savedMessages).isEqualTo(messages); |
71 |
| - |
72 |
| - // Verify transaction works by updating and checking atomicity |
73 |
| - var newMessages = List.<Message>of(new SystemMessage("New system message - " + conversationId)); |
74 |
| - repositoryWithTxManager.saveAll(conversationId, newMessages); |
75 |
| - |
76 |
| - // The old messages should be deleted and only the new one should exist |
77 |
| - var updatedMessages = repositoryWithTxManager.findByConversationId(conversationId); |
78 |
| - assertThat(updatedMessages).hasSize(1); |
79 |
| - assertThat(updatedMessages).isEqualTo(newMessages); |
80 |
| - } |
81 |
| - |
82 |
| - @SpringBootConfiguration |
83 |
| - static class TestConfiguration extends BaseTestConfiguration { |
84 |
| - |
85 |
| - @Bean |
86 |
| - ChatMemoryRepository chatMemoryRepositoryWithTxManager(JdbcTemplate jdbcTemplate, DataSource dataSource) { |
87 |
| - return chatMemoryRepositoryWithTransactionManager(jdbcTemplate, dataSource); |
88 |
| - } |
89 |
| - |
90 |
| - static ChatMemoryRepository chatMemoryRepositoryWithTransactionManager(JdbcTemplate jdbcTemplate, |
91 |
| - DataSource dataSource) { |
92 |
| - return JdbcChatMemoryRepository.builder() |
93 |
| - .jdbcTemplate(jdbcTemplate) |
94 |
| - .dialect(JdbcChatMemoryRepositoryDialect.from(dataSource)) |
95 |
| - .transactionManager(new DataSourceTransactionManager(dataSource)) |
96 |
| - .build(); |
97 |
| - } |
98 |
| - |
99 |
| - } |
100 |
| - |
101 | 36 | }
|
0 commit comments