test: 修复测试并验证 Milvus 连接
- 修复 DocumentChunkServiceTest:getStartIndex/getEndIndex → getStartOffset/getEndOffset - 新增 SimpleMilvusTest:验证 Milvus 集群连接状态 - Milvus 状态:✓ 正常运行(Status Code: 0) 测试结果: - SimpleMilvusTest: 1/1 通过 - Milvus 集群可用,可以继续实施 Task 5.3-5.7 Host: in03-4a578da0f27ce9d.serverless.aws-eu-central-1.cloud.zilliz.com Port: 443 (Zilliz Cloud Serverless)
This commit is contained in:
@@ -218,10 +218,10 @@ class DocumentChunkServiceTest {
|
||||
List<DocumentChunk> chunks = service.chunkDocument(content, "/test/index.md");
|
||||
|
||||
for (DocumentChunk c : chunks) {
|
||||
assertTrue(c.getStartIndex() >= 0);
|
||||
assertTrue(c.getEndIndex() > c.getStartIndex(),
|
||||
"endIndex(" + c.getEndIndex() + ") 应 > startIndex(" + c.getStartIndex() + ")");
|
||||
assertTrue(c.getEndIndex() <= content.length());
|
||||
assertTrue(c.getStartOffset() >= 0);
|
||||
assertTrue(c.getEndOffset() > c.getStartOffset(),
|
||||
"endIndex(" + c.getEndOffset() + ") 应 > startIndex(" + c.getStartOffset() + ")");
|
||||
assertTrue(c.getEndOffset() <= content.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -326,7 +326,7 @@ class DocumentChunkServiceTest {
|
||||
System.out.println(" 长列表硬上限测试 — 实际分块数: " + chunks.size());
|
||||
for (DocumentChunk c : chunks) {
|
||||
System.out.println(" Chunk #" + c.getChunkIndex() + ": " + c.getContent().length() + "字符 "
|
||||
+ "| start=" + c.getStartIndex() + " end=" + c.getEndIndex()
|
||||
+ "| start=" + c.getStartOffset() + " end=" + c.getEndOffset()
|
||||
+ " | preview=" + c.getContent().substring(0, Math.min(60, c.getContent().length())).replace("\n", "\\n"));
|
||||
}
|
||||
|
||||
@@ -486,7 +486,7 @@ class DocumentChunkServiceTest {
|
||||
for (DocumentChunk c : chunks) {
|
||||
System.out.println("┌─ Chunk #" + c.getChunkIndex());
|
||||
System.out.println("│ Title: " + (c.getTitle() != null ? c.getTitle() : "(无)"));
|
||||
System.out.println("│ Range: [" + c.getStartIndex() + "→" + c.getEndIndex() + "] (" + c.getContent().length() + "字符)");
|
||||
System.out.println("│ Range: [" + c.getStartOffset() + "→" + c.getEndOffset() + "] (" + c.getContent().length() + "字符)");
|
||||
// 显示前150字符
|
||||
String preview = c.getContent().length() > 120
|
||||
? c.getContent().substring(0, 120).replace("\n", "\\n") + "..."
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.superbiz.agent.service;
|
||||
|
||||
import io.milvus.client.MilvusServiceClient;
|
||||
import io.milvus.param.ConnectParam;
|
||||
import io.milvus.param.R;
|
||||
import io.milvus.param.collection.HasCollectionParam;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* 简单的 Milvus 连接测试
|
||||
*/
|
||||
public class SimpleMilvusTest {
|
||||
|
||||
@Test
|
||||
public void testConnection() {
|
||||
String host = "in03-4a578da0f27ce9d.serverless.aws-eu-central-1.cloud.zilliz.com";
|
||||
int port = 443;
|
||||
String token = "d246a77f43a109685596e3c68ecfd359e1cd8b29d35c41d708160f02b97ae623d2ab392738df740d0c77b58ca1bbadfa7c412140";
|
||||
|
||||
System.out.println("尝试连接 Milvus...");
|
||||
System.out.println("Host: " + host);
|
||||
System.out.println("Port: " + port);
|
||||
|
||||
try {
|
||||
MilvusServiceClient client = new MilvusServiceClient(
|
||||
ConnectParam.newBuilder()
|
||||
.withHost(host)
|
||||
.withPort(port)
|
||||
.withToken(token)
|
||||
.withSecure(true)
|
||||
.withConnectTimeout(10L, java.util.concurrent.TimeUnit.SECONDS)
|
||||
.build()
|
||||
);
|
||||
|
||||
System.out.println("✓ 客户端创建成功");
|
||||
|
||||
// 测试连接:查询是否存在某个 collection
|
||||
R<Boolean> response = client.hasCollection(
|
||||
HasCollectionParam.newBuilder()
|
||||
.withCollectionName("test_collection")
|
||||
.build()
|
||||
);
|
||||
|
||||
System.out.println("✓ 连接成功!");
|
||||
System.out.println("Status Code: " + response.getStatus());
|
||||
|
||||
if (response.getStatus() == 0 || response.getStatus() == io.milvus.param.R.Status.Success.getCode()) {
|
||||
System.out.println("✓ Milvus 集群状态:正常运行");
|
||||
} else {
|
||||
System.out.println("✗ 响应状态异常: " + response.getStatus());
|
||||
}
|
||||
|
||||
client.close();
|
||||
System.out.println("✓ 连接已关闭");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("✗ 连接失败:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Milvus 连接失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user