feat(go): batch redis fast writer projections

This commit is contained in:
lingniu
2026-07-03 19:45:00 +08:00
parent 81e050ec1c
commit 3a0d9bd840
7 changed files with 173 additions and 10 deletions

View File

@@ -430,6 +430,57 @@ func TestRepositoryFastUpdateOnlyWritesPermanentKVAndMinuteOnline(t *testing.T)
}
}
func TestRepositoryFastUpdateBatchWritesMultipleRealtimeProjections(t *testing.T) {
repo, closeFn := newTestRepository(t)
defer closeFn()
ctx := context.Background()
err := repo.FastUpdateBatch(ctx, []envelope.FrameEnvelope{
{
Protocol: envelope.ProtocolGB32960,
VIN: "VIN001",
EventTimeMS: 1000,
ReceivedAtMS: 1100,
Parsed: map[string]any{
"data_units": []any{map[string]any{"type": "0x01", "name": "vehicle", "value": map[string]any{"soc_percent": 88.0}}},
},
},
{
Protocol: envelope.ProtocolJT808,
VIN: "VIN002",
EventTimeMS: 2000,
ReceivedAtMS: 2200,
MessageID: "0x0200",
Parsed: map[string]any{"location": map[string]any{"longitude": 121.1, "latitude": 30.2}},
Fields: map[string]any{envelope.FieldLongitude: 121.1, envelope.FieldLatitude: 30.2},
},
})
if err != nil {
t.Fatalf("FastUpdateBatch() error = %v", err)
}
gbValues, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:GB32960:VIN001:values").Result()
if err != nil {
t.Fatalf("gb values HGetAll error = %v", err)
}
if gbValues["gb32960.vehicle.soc_percent"] != "88" {
t.Fatalf("gb values = %#v", gbValues)
}
jtValues, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:JT808:VIN002:values").Result()
if err != nil {
t.Fatalf("jt values HGetAll error = %v", err)
}
if jtValues["jt808.location.longitude"] != "121.1" || jtValues["jt808.location.latitude"] != "30.2" {
t.Fatalf("jt values = %#v", jtValues)
}
if repo.client.ZScore(ctx, "vehicle:last_seen", "GB32960:VIN001").Err() != nil {
t.Fatal("last_seen should contain GB32960 VIN001")
}
if repo.client.ZScore(ctx, "vehicle:last_seen", "JT808:VIN002").Err() != nil {
t.Fatal("last_seen should contain JT808 VIN002")
}
}
func TestRepositoryListsOnlineStatusesAndPipelineSummary(t *testing.T) {
repo, closeFn := newTestRepository(t)
defer closeFn()