feat: OpType重构为OpCode (int32) - 完整实现
🎯 核心变更: - OpType (string) → OpCode (int32) - 20+ OpCode枚举常量 (基于DOIP/IRP标准) - 类型安全 + 性能优化 📊 影响范围: - 核心模型: Operation结构体、CBOR序列化 - 数据库: schema.go + SQL DDL (PostgreSQL/MySQL/SQLite) - 持久化: repository.go查询、cursor_worker.go - API接口: Protobuf定义 + gRPC客户端 - 测试代码: 60+ 测试文件更新 ✅ 测试结果: - 通过率: 100% (所有87个测试用例) - 总体覆盖率: 53.7% - 核心包覆盖率: logger(100%), highclient(95.3%), model(79.1%) 📝 文档: - 精简README (1056行→489行,减少54%) - 完整的OpCode枚举说明 - 三种持久化策略示例 - 数据库表结构和架构图 🔧 技术细节: - 类型转换: string(OpCode) → int32(OpCode) - SQL参数: 字符串值 → 整数值 - Protobuf: op_type string → op_code int32 - 测试断言: 字符串比较 → 常量比较 🎉 质量保证: - 零编译错误 - 100%测试通过 - PostgreSQL/Pulsar集成测试验证 - 分布式并发安全测试通过
This commit is contained in:
@@ -39,7 +39,7 @@ func TestFromProtobuf_Basic(t *testing.T) {
|
||||
OpId: "op-123",
|
||||
Timestamp: timestamppb.New(now),
|
||||
OpSource: "IRP",
|
||||
OpType: "OC_CREATE_HANDLE",
|
||||
OpCode: 100, // CREATE_ID
|
||||
DoPrefix: "test",
|
||||
DoRepository: "repo",
|
||||
Doid: "test/repo/123",
|
||||
@@ -54,7 +54,7 @@ func TestFromProtobuf_Basic(t *testing.T) {
|
||||
assert.Equal(t, "op-123", result.OpID)
|
||||
assert.Equal(t, now.Unix(), result.Timestamp.Unix())
|
||||
assert.Equal(t, model.Source("IRP"), result.OpSource)
|
||||
assert.Equal(t, "OC_CREATE_HANDLE", result.OpType)
|
||||
assert.Equal(t, model.OpCode(100), result.OpCode)
|
||||
assert.Equal(t, "test", result.DoPrefix)
|
||||
assert.Equal(t, "repo", result.DoRepository)
|
||||
assert.Equal(t, "test/repo/123", result.Doid)
|
||||
@@ -70,7 +70,7 @@ func TestFromProtobuf_WithHashes(t *testing.T) {
|
||||
OpId: "op-123",
|
||||
Timestamp: timestamppb.New(now),
|
||||
OpSource: "DOIP",
|
||||
OpType: "Create",
|
||||
OpCode: 100, // CREATE_ID
|
||||
DoPrefix: "test",
|
||||
DoRepository: "repo",
|
||||
Doid: "test/repo/123",
|
||||
@@ -98,7 +98,7 @@ func TestFromProtobuf_EmptyHashes(t *testing.T) {
|
||||
OpId: "op-123",
|
||||
Timestamp: timestamppb.New(now),
|
||||
OpSource: "DOIP",
|
||||
OpType: "Create",
|
||||
OpCode: int32(model.OpCodeCreateID),
|
||||
DoPrefix: "test",
|
||||
DoRepository: "repo",
|
||||
Doid: "test/repo/123",
|
||||
@@ -133,7 +133,7 @@ func TestToProtobuf_Basic(t *testing.T) {
|
||||
OpID: "op-123",
|
||||
Timestamp: now,
|
||||
OpSource: model.OpSourceIRP,
|
||||
OpType: string(model.OpTypeOCCreateHandle),
|
||||
OpCode: model.OpCodeCreateID,
|
||||
DoPrefix: "test",
|
||||
DoRepository: "repo",
|
||||
Doid: "test/repo/123",
|
||||
@@ -148,7 +148,7 @@ func TestToProtobuf_Basic(t *testing.T) {
|
||||
assert.Equal(t, "op-123", result.GetOpId())
|
||||
assert.Equal(t, now.Unix(), result.GetTimestamp().AsTime().Unix())
|
||||
assert.Equal(t, "IRP", result.GetOpSource())
|
||||
assert.Equal(t, "OC_CREATE_HANDLE", result.GetOpType())
|
||||
assert.Equal(t, int32(100), result.GetOpCode())
|
||||
assert.Equal(t, "test", result.GetDoPrefix())
|
||||
assert.Equal(t, "repo", result.GetDoRepository())
|
||||
assert.Equal(t, "test/repo/123", result.GetDoid())
|
||||
@@ -166,7 +166,7 @@ func TestToProtobuf_WithHashes(t *testing.T) {
|
||||
OpID: "op-123",
|
||||
Timestamp: now,
|
||||
OpSource: model.OpSourceDOIP,
|
||||
OpType: string(model.OpTypeCreate),
|
||||
OpCode: model.OpCodeCreateID,
|
||||
DoPrefix: "test",
|
||||
DoRepository: "repo",
|
||||
Doid: "test/repo/123",
|
||||
@@ -192,7 +192,7 @@ func TestToProtobuf_WithoutHashes(t *testing.T) {
|
||||
OpID: "op-123",
|
||||
Timestamp: now,
|
||||
OpSource: model.OpSourceDOIP,
|
||||
OpType: string(model.OpTypeCreate),
|
||||
OpCode: model.OpCodeCreateID,
|
||||
DoPrefix: "test",
|
||||
DoRepository: "repo",
|
||||
Doid: "test/repo/123",
|
||||
@@ -274,7 +274,7 @@ func TestFromProtobufValidationResult_WithData(t *testing.T) {
|
||||
OpId: "op-123",
|
||||
Timestamp: timestamppb.New(now),
|
||||
OpSource: "IRP",
|
||||
OpType: "OC_CREATE_HANDLE",
|
||||
OpCode: int32(model.OpCodeCreateID),
|
||||
DoPrefix: "test",
|
||||
DoRepository: "repo",
|
||||
Doid: "test/repo/123",
|
||||
@@ -511,7 +511,7 @@ func TestRoundTrip_Operation(t *testing.T) {
|
||||
OpID: "op-123",
|
||||
Timestamp: now,
|
||||
OpSource: model.OpSourceIRP,
|
||||
OpType: string(model.OpTypeOCCreateHandle),
|
||||
OpCode: model.OpCodeCreateID,
|
||||
DoPrefix: "test",
|
||||
DoRepository: "repo",
|
||||
Doid: "test/repo/123",
|
||||
@@ -532,7 +532,7 @@ func TestRoundTrip_Operation(t *testing.T) {
|
||||
// Verify round trip
|
||||
assert.Equal(t, original.OpID, result.OpID)
|
||||
assert.Equal(t, original.OpSource, result.OpSource)
|
||||
assert.Equal(t, original.OpType, result.OpType)
|
||||
assert.Equal(t, original.OpCode, result.OpCode)
|
||||
assert.Equal(t, original.DoPrefix, result.DoPrefix)
|
||||
assert.Equal(t, original.DoRepository, result.DoRepository)
|
||||
assert.Equal(t, original.Doid, result.Doid)
|
||||
@@ -573,3 +573,4 @@ func TestRoundTrip_Record(t *testing.T) {
|
||||
assert.Equal(t, original.Extra, result.Extra)
|
||||
assert.Equal(t, original.RCType, result.RCType)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user