feat(go): add realtime kv projection
This commit is contained in:
@@ -42,8 +42,8 @@ func TestSnapshotWriterEnsuresSchemaAndUpsertsCoreSnapshot(t *testing.T) {
|
||||
t.Fatalf("Update() error = %v", err)
|
||||
}
|
||||
|
||||
if len(exec.calls) != 6 {
|
||||
t.Fatalf("exec calls = %d, want 6", len(exec.calls))
|
||||
if len(exec.calls) != 8 {
|
||||
t.Fatalf("exec calls = %d, want 8", len(exec.calls))
|
||||
}
|
||||
if !strings.Contains(exec.calls[0].query, "CREATE TABLE IF NOT EXISTS vehicle_realtime_snapshot") {
|
||||
t.Fatalf("schema query = %s", exec.calls[0].query)
|
||||
@@ -51,6 +51,9 @@ func TestSnapshotWriterEnsuresSchemaAndUpsertsCoreSnapshot(t *testing.T) {
|
||||
if !strings.Contains(exec.calls[4].query, "CREATE TABLE IF NOT EXISTS vehicle_realtime_location") {
|
||||
t.Fatalf("location schema query = %s", exec.calls[4].query)
|
||||
}
|
||||
if !strings.Contains(exec.calls[5].query, "CREATE TABLE IF NOT EXISTS vehicle_realtime_kv") {
|
||||
t.Fatalf("kv schema query = %s", exec.calls[5].query)
|
||||
}
|
||||
for _, call := range []snapshotExecCall{exec.calls[0], exec.calls[4]} {
|
||||
if strings.Contains(call.query, "fields_json") {
|
||||
t.Fatalf("realtime schema should not contain fields_json: %s", call.query)
|
||||
@@ -72,7 +75,7 @@ func TestSnapshotWriterEnsuresSchemaAndUpsertsCoreSnapshot(t *testing.T) {
|
||||
if strings.Contains(exec.calls[4].query, "idx_location") {
|
||||
t.Fatalf("realtime location table should not keep unused geo index: %s", exec.calls[4].query)
|
||||
}
|
||||
upsert := exec.calls[5]
|
||||
upsert := exec.calls[6]
|
||||
if !strings.Contains(upsert.query, "ON DUPLICATE KEY UPDATE") {
|
||||
t.Fatalf("upsert query = %s", upsert.query)
|
||||
}
|
||||
@@ -99,6 +102,10 @@ func TestSnapshotWriterEnsuresSchemaAndUpsertsCoreSnapshot(t *testing.T) {
|
||||
if len(upsert.args) != 9 {
|
||||
t.Fatalf("snapshot upsert args = %d, want 9", len(upsert.args))
|
||||
}
|
||||
kvUpsert := exec.calls[7]
|
||||
if !strings.Contains(kvUpsert.query, "INSERT INTO vehicle_realtime_kv") || !strings.Contains(kvUpsert.query, "ON DUPLICATE KEY UPDATE") {
|
||||
t.Fatalf("kv upsert query = %s", kvUpsert.query)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSnapshotWriterEnsureSchemaOnlyCreatesTargetTables(t *testing.T) {
|
||||
@@ -119,6 +126,8 @@ func TestSnapshotWriterEnsureSchemaOnlyCreatesTargetTables(t *testing.T) {
|
||||
WillReturnResult(sqlmock.NewResult(0, 0))
|
||||
mock.ExpectExec("CREATE TABLE IF NOT EXISTS vehicle_realtime_location").
|
||||
WillReturnResult(sqlmock.NewResult(0, 0))
|
||||
mock.ExpectExec("CREATE TABLE IF NOT EXISTS vehicle_realtime_kv").
|
||||
WillReturnResult(sqlmock.NewResult(0, 0))
|
||||
|
||||
if err := writer.EnsureSchema(context.Background()); err != nil {
|
||||
t.Fatalf("EnsureSchema() error = %v", err)
|
||||
@@ -160,10 +169,10 @@ func TestSnapshotWriterUpsertsRealtimeLocationWhenCoordinatesExist(t *testing.T)
|
||||
t.Fatalf("Update() error = %v", err)
|
||||
}
|
||||
|
||||
if len(exec.calls) != 2 {
|
||||
t.Fatalf("exec calls = %d, want 2", len(exec.calls))
|
||||
if len(exec.calls) != 3 {
|
||||
t.Fatalf("exec calls = %d, want 3", len(exec.calls))
|
||||
}
|
||||
locationUpsert := exec.calls[1]
|
||||
locationUpsert := exec.calls[2]
|
||||
if !strings.Contains(locationUpsert.query, "INSERT INTO vehicle_realtime_location") {
|
||||
t.Fatalf("location upsert query = %s", locationUpsert.query)
|
||||
}
|
||||
@@ -226,6 +235,8 @@ func TestSnapshotWriterMergesGB32960ParsedJSONAcrossSplitRealtimeFrames(t *testi
|
||||
sqlmock.AnyArg(),
|
||||
).
|
||||
WillReturnResult(sqlmock.NewResult(0, 1))
|
||||
mock.ExpectExec("INSERT INTO vehicle_realtime_kv").
|
||||
WillReturnResult(sqlmock.NewResult(0, 2))
|
||||
|
||||
err = writer.Update(context.Background(), envelope.FrameEnvelope{
|
||||
Protocol: envelope.ProtocolGB32960,
|
||||
@@ -272,6 +283,8 @@ func TestSnapshotWriterCollapsesGB32960StackFragmentsWhenMergingParsedJSON(t *te
|
||||
sqlmock.AnyArg(),
|
||||
).
|
||||
WillReturnResult(sqlmock.NewResult(0, 1))
|
||||
mock.ExpectExec("INSERT INTO vehicle_realtime_kv").
|
||||
WillReturnResult(sqlmock.NewResult(0, 3))
|
||||
|
||||
err = writer.Update(context.Background(), envelope.FrameEnvelope{
|
||||
Protocol: envelope.ProtocolGB32960,
|
||||
@@ -366,13 +379,13 @@ func TestSnapshotWriterBackfillsPlateFromBindingByVIN(t *testing.T) {
|
||||
if resolver.vin != "VIN001" {
|
||||
t.Fatalf("resolver vin = %q", resolver.vin)
|
||||
}
|
||||
if len(exec.calls) != 2 {
|
||||
t.Fatalf("exec calls = %d, want 2", len(exec.calls))
|
||||
if len(exec.calls) != 3 {
|
||||
t.Fatalf("exec calls = %d, want 3", len(exec.calls))
|
||||
}
|
||||
if got, want := exec.calls[0].args[2], "沪A12345"; got != want {
|
||||
t.Fatalf("snapshot plate arg = %#v, want %q", got, want)
|
||||
}
|
||||
if got, want := exec.calls[1].args[2], "沪A12345"; got != want {
|
||||
if got, want := exec.calls[2].args[2], "沪A12345"; got != want {
|
||||
t.Fatalf("location plate arg = %#v, want %q", got, want)
|
||||
}
|
||||
}
|
||||
@@ -428,10 +441,10 @@ func TestSnapshotWriterCachesBindingPlateByVIN(t *testing.T) {
|
||||
if resolver.calls != 1 {
|
||||
t.Fatalf("plate resolver calls = %d, want 1", resolver.calls)
|
||||
}
|
||||
if len(exec.calls) != 4 {
|
||||
t.Fatalf("exec calls = %d, want 4", len(exec.calls))
|
||||
if len(exec.calls) != 6 {
|
||||
t.Fatalf("exec calls = %d, want 6", len(exec.calls))
|
||||
}
|
||||
for _, index := range []int{0, 2} {
|
||||
for _, index := range []int{0, 3} {
|
||||
if got, want := exec.calls[index].args[2], "沪A12345"; got != want {
|
||||
t.Fatalf("snapshot %d plate arg = %#v, want %q", index, got, want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user