refactor(go): simplify redis realtime projections
This commit is contained in:
@@ -341,17 +341,34 @@ func TestRepositoryWritesRealtimeKVHashes(t *testing.T) {
|
||||
t.Fatalf("Update() error = %v", err)
|
||||
}
|
||||
|
||||
dataUnitsKV, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:GB32960:VIN001:data_units").Result()
|
||||
dataUnitsKV, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:GB32960:VIN001:values").Result()
|
||||
if err != nil {
|
||||
t.Fatalf("data_units kv HGetAll error = %v", err)
|
||||
t.Fatalf("values kv HGetAll error = %v", err)
|
||||
}
|
||||
if dataUnitsKV["0.value.soc_percent"] != "88" || dataUnitsKV["_event_id"] == "" || dataUnitsKV["_event_time_ms"] != "1000" {
|
||||
if dataUnitsKV["data_units.0.value.soc_percent"] != "88" {
|
||||
t.Fatalf("data_units kv = %#v", dataUnitsKV)
|
||||
}
|
||||
if dataUnitsKV["1.value.summaries.0.stack_water_outlet_temp_c"] != "63" {
|
||||
if dataUnitsKV["data_units.1.value.summaries.0.stack_water_outlet_temp_c"] != "63" {
|
||||
t.Fatalf("data_units stack kv = %#v", dataUnitsKV)
|
||||
}
|
||||
if ttl := repo.client.TTL(ctx, "vehicle:rt-kv:GB32960:VIN001:data_units").Val(); ttl != -1 {
|
||||
typeKV, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:GB32960:VIN001:types").Result()
|
||||
if err != nil {
|
||||
t.Fatalf("types kv HGetAll error = %v", err)
|
||||
}
|
||||
if typeKV["data_units.0.value.soc_percent"] != "number" || typeKV["data_units.1.name"] != "string" {
|
||||
t.Fatalf("types kv = %#v", typeKV)
|
||||
}
|
||||
metaKV, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:GB32960:VIN001:meta").Result()
|
||||
if err != nil {
|
||||
t.Fatalf("meta kv HGetAll error = %v", err)
|
||||
}
|
||||
if metaKV["event_id"] == "" || metaKV["event_time_ms"] != "1000" || metaKV["protocol"] != "GB32960" {
|
||||
t.Fatalf("meta kv = %#v", metaKV)
|
||||
}
|
||||
if repo.client.Exists(ctx, "vehicle:rt-kv:GB32960:VIN001:data_units").Val() != 0 {
|
||||
t.Fatal("old domain kv key should not be written")
|
||||
}
|
||||
if ttl := repo.client.TTL(ctx, "vehicle:rt-kv:GB32960:VIN001:values").Val(); ttl != -1 {
|
||||
t.Fatalf("kv ttl should not expire, got %v", ttl)
|
||||
}
|
||||
}
|
||||
@@ -375,19 +392,39 @@ func TestRepositoryFastUpdateOnlyWritesPermanentKVAndMinuteOnline(t *testing.T)
|
||||
t.Fatalf("FastUpdate() error = %v", err)
|
||||
}
|
||||
|
||||
dataUnitsKV, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:GB32960:VIN001:data_units").Result()
|
||||
dataUnitsKV, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:GB32960:VIN001:values").Result()
|
||||
if err != nil {
|
||||
t.Fatalf("data_units kv HGetAll error = %v", err)
|
||||
t.Fatalf("values kv HGetAll error = %v", err)
|
||||
}
|
||||
if dataUnitsKV["0.value.soc_percent"] != "88" || dataUnitsKV["_event_time_ms"] != "1000" {
|
||||
if dataUnitsKV["data_units.0.value.soc_percent"] != "88" {
|
||||
t.Fatalf("data_units kv = %#v", dataUnitsKV)
|
||||
}
|
||||
if ttl := repo.client.TTL(ctx, "vehicle:rt-kv:GB32960:VIN001:data_units").Val(); ttl != -1 {
|
||||
typeKV, err := repo.client.HGetAll(ctx, "vehicle:rt-kv:GB32960:VIN001:types").Result()
|
||||
if err != nil {
|
||||
t.Fatalf("types kv HGetAll error = %v", err)
|
||||
}
|
||||
if typeKV["data_units.0.value.soc_percent"] != "number" {
|
||||
t.Fatalf("types kv = %#v", typeKV)
|
||||
}
|
||||
if ttl := repo.client.TTL(ctx, "vehicle:rt-kv:GB32960:VIN001:values").Val(); ttl != -1 {
|
||||
t.Fatalf("kv ttl should not expire, got %v", ttl)
|
||||
}
|
||||
if ttl := repo.client.TTL(ctx, "vehicle:online:VIN001").Val(); ttl <= 0 || ttl > time.Minute {
|
||||
if ttl := repo.client.TTL(ctx, "vehicle:online:GB32960:VIN001").Val(); ttl <= 0 || ttl > time.Minute {
|
||||
t.Fatalf("online ttl = %v, want within 1 minute", ttl)
|
||||
}
|
||||
state, err := repo.client.HGetAll(ctx, "vehicle:online-state:GB32960:VIN001").Result()
|
||||
if err != nil {
|
||||
t.Fatalf("online state HGetAll error = %v", err)
|
||||
}
|
||||
if state["online"] != "true" || state["last_seen_ms"] != "1100" || state["offline_after_ms"] != "61100" {
|
||||
t.Fatalf("online state = %#v", state)
|
||||
}
|
||||
if repo.client.ZScore(ctx, "vehicle:last_seen", "GB32960:VIN001").Err() != nil {
|
||||
t.Fatal("last_seen should index protocol+vin")
|
||||
}
|
||||
if repo.client.SIsMember(ctx, "vehicle:rt-index:GB32960", "VIN001").Val() != true {
|
||||
t.Fatal("rt-index should contain vin by protocol")
|
||||
}
|
||||
if repo.client.Exists(ctx, "vehicle:latest:VIN001").Val() != 0 {
|
||||
t.Fatal("fast update should not write merged snapshot")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user