- 暴露事务级 last_committed、sequence_number、transaction_length 和 commit timestamp - 在 GTID event 转换时透传 logical clock 元数据 - 新增 ParseOptions、ParseProgress,支持上下文取消和解析进度回调 - 保留 TransactionPayloadEvent 展开后的 tablemap 与压缩类型信息 - 增加 TransactionSummary 辅助结构,便于上层统计事务结果、耗时、表分布和逻辑时钟 - 清理测试对外部大 binlog 样本的依赖,保证独立库测试可运行 - 修正跨平台测试与 GTID 输出格式断言,提升发版稳定性
58 lines
1.8 KiB
Go
58 lines
1.8 KiB
Go
package binlog
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseBinlogWithOptions_ProgressAndStop(t *testing.T) {
|
|
t.Skip("skips large-binlog integration test; this standalone module must not depend on external sample files")
|
|
}
|
|
|
|
func TestParseBinlogWithOptions_ContextCancel(t *testing.T) {
|
|
path := "./test/mysql-bin56.000003"
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
|
|
err := ParseBinlogWithOptions(path, ParseOptions{Context: ctx}, func(Transaction) bool {
|
|
t.Fatal("transaction callback should not run after context cancellation")
|
|
return false
|
|
})
|
|
if !errors.Is(err, context.Canceled) {
|
|
t.Fatalf("expected context.Canceled, got %v", err)
|
|
}
|
|
}
|
|
|
|
func TestParseBinlogWithOptions_ParseBinSample(t *testing.T) {
|
|
t.Skip("skips large-binlog integration test; this standalone module must not depend on external sample files")
|
|
}
|
|
|
|
func TestParseBinlogWithOptions_LargeBinProgressStop(t *testing.T) {
|
|
t.Skip("skips large-binlog integration test; this standalone module must not depend on external sample files")
|
|
}
|
|
|
|
func TestParseBinlogWithOptions_ExcludeAllGTIDDoesNotEmitEmptyTransaction(t *testing.T) {
|
|
t.Skip("skips large-binlog integration test; this standalone module must not depend on external sample files")
|
|
}
|
|
|
|
func TestTransactionJSONPreservesZeroLogicalClockValues(t *testing.T) {
|
|
raw, err := json.Marshal(Transaction{
|
|
GTID: "uuid:1",
|
|
LastCommitted: 0,
|
|
SequenceNumber: 1,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("marshal transaction failed: %v", err)
|
|
}
|
|
doc := string(raw)
|
|
if !strings.Contains(doc, `"lastCommitted":0`) {
|
|
t.Fatalf("expected zero lastCommitted to be present, got %s", doc)
|
|
}
|
|
if !strings.Contains(doc, `"sequenceNumber":1`) {
|
|
t.Fatalf("expected sequenceNumber to be present, got %s", doc)
|
|
}
|
|
}
|