feat(phase1): 完成 Repository 测试和 Redis 会话管理
Task 2: 完成 Repository 层测试 - 实现 CaseLibraryRepositoryTest (6 个测试) - 实现 ApiDocumentRepositoryTest (7 个测试) - 所有 Repository 测试通过 (19/19) Task 3: 完成 Redis 会话管理 - 创建 SessionContext 和 ToolCall 数据类 - 创建 SessionManager 接口 - 实现 RedisSessionManager (基于 Redis 的会话管理) - 创建 SessionConfiguration (Redis 序列化配置) - 实现 RedisSessionManagerTest (8 个测试全部通过) 测试结果: - ApiDocumentRepositoryTest: 7/7 通过 - CaseLibraryRepositoryTest: 6/6 通过 - DiagnosisRecordRepositoryTest: 6/6 通过 - RedisSessionManagerTest: 8/8 通过 - 总计: 27/27 测试通过 功能特性: - 会话创建、查询、更新、删除 - 会话过期时间管理 - 工具调用记录追踪 - 会话状态管理 - 基于 Redis 的分布式会话存储 Progress: 20/33 tasks completed (61%)
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package org.example.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* 单独测试 Redis 连接
|
||||
* 禁用 Milvus 以避免启动失败
|
||||
*/
|
||||
@SpringBootTest
|
||||
@TestPropertySource(properties = {
|
||||
"spring.autoconfigure.exclude=org.example.config.MilvusConfig"
|
||||
})
|
||||
class RedisConnectionTest {
|
||||
|
||||
@Autowired(required = false)
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
||||
@Test
|
||||
void testRedisConnection() {
|
||||
assertNotNull(redisTemplate, "RedisTemplate should be configured");
|
||||
|
||||
try {
|
||||
String testKey = "test:connection:" + System.currentTimeMillis();
|
||||
String testValue = "test-value";
|
||||
|
||||
// 测试写入
|
||||
redisTemplate.opsForValue().set(testKey, testValue);
|
||||
System.out.println("✓ Redis 写入成功");
|
||||
|
||||
// 测试读取
|
||||
Object result = redisTemplate.opsForValue().get(testKey);
|
||||
assertEquals(testValue, result, "Redis read should return the written value");
|
||||
System.out.println("✓ Redis 读取成功");
|
||||
|
||||
// 测试删除
|
||||
redisTemplate.delete(testKey);
|
||||
Object deleted = redisTemplate.opsForValue().get(testKey);
|
||||
assertNull(deleted, "Deleted key should return null");
|
||||
System.out.println("✓ Redis 删除成功");
|
||||
|
||||
System.out.println("\n✓ Redis 连接测试通过!");
|
||||
System.out.println(" 服务器: 119.29.78.52:6379");
|
||||
System.out.println(" 读写删操作正常");
|
||||
|
||||
} catch (Exception e) {
|
||||
fail("Redis 连接失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user