-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MongoDB] Return error instead of logging a warning on primary key pr…
…esence in `retData` (#936)
- Loading branch information
Showing
3 changed files
with
40 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,21 +154,21 @@ func (m *MongoTestSuite) TestMongoDBEventCustomer() { | |
|
||
evt, err := m.Debezium.GetEventFromBytes([]byte(payload)) | ||
assert.NoError(m.T(), err) | ||
evtData, err := evt.GetData(map[string]any{"_id": 1003}, kafkalib.TopicConfig{}) | ||
evtData, err := evt.GetData(map[string]any{"_id": int64(1003)}, kafkalib.TopicConfig{}) | ||
assert.NoError(m.T(), err) | ||
_, isOk := evtData[constants.UpdateColumnMarker] | ||
assert.False(m.T(), isOk) | ||
assert.Equal(m.T(), evtData["_id"], 1003) | ||
assert.Equal(m.T(), evtData["_id"], int64(1003)) | ||
assert.Equal(m.T(), evtData["first_name"], "Robin") | ||
assert.Equal(m.T(), evtData["last_name"], "Tang") | ||
assert.Equal(m.T(), evtData["email"], "[email protected]") | ||
|
||
evtDataWithIncludedAt, err := evt.GetData(map[string]any{"_id": 1003}, kafkalib.TopicConfig{}) | ||
evtDataWithIncludedAt, err := evt.GetData(map[string]any{"_id": int64(1003)}, kafkalib.TopicConfig{}) | ||
assert.NoError(m.T(), err) | ||
_, isOk = evtDataWithIncludedAt[constants.UpdateColumnMarker] | ||
assert.False(m.T(), isOk) | ||
|
||
evtDataWithIncludedAt, err = evt.GetData(map[string]any{"_id": 1003}, kafkalib.TopicConfig{IncludeDatabaseUpdatedAt: true, IncludeArtieUpdatedAt: true}) | ||
evtDataWithIncludedAt, err = evt.GetData(map[string]any{"_id": int64(1003)}, kafkalib.TopicConfig{IncludeDatabaseUpdatedAt: true, IncludeArtieUpdatedAt: true}) | ||
assert.NoError(m.T(), err) | ||
|
||
assert.Equal(m.T(), ext.NewExtendedTime(time.Date(2022, time.November, 18, 6, 35, 21, 0, time.UTC), ext.TimestampTzKindType, ext.ISO8601), evtDataWithIncludedAt[constants.DatabaseUpdatedColumnMarker]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,8 +104,7 @@ func TestProcessMessageFailures(t *testing.T) { | |
Format: &mgo, | ||
}) | ||
|
||
vals := []string{ | ||
`{ | ||
val := `{ | ||
"schema": { | ||
"type": "struct", | ||
"fields": [{ | ||
|
@@ -135,7 +134,7 @@ func TestProcessMessageFailures(t *testing.T) { | |
}, | ||
"payload": { | ||
"before": null, | ||
"after": "{\"_id\": {\"$numberLong\": \"1004\"},\"first_name\": \"Anne\",\"last_name\": \"Kretchmar\",\"email\": \"[email protected]\"}", | ||
"after": "{\"_id\": \"1004\"},\"first_name\": \"Anne\",\"last_name\": \"Kretchmar\",\"email\": \"[email protected]\"}", | ||
"patch": null, | ||
"filter": null, | ||
"updateDescription": null, | ||
|
@@ -157,57 +156,49 @@ func TestProcessMessageFailures(t *testing.T) { | |
"ts_ms": 1668753329387, | ||
"transaction": null | ||
} | ||
}`, | ||
} | ||
}` | ||
|
||
idx := 0 | ||
memoryDB := memDB | ||
for _, val := range vals { | ||
idx += 1 | ||
msg.KafkaMsg.Key = []byte(fmt.Sprintf("Struct{id=%v}", idx)) | ||
if val != "" { | ||
msg.KafkaMsg.Value = []byte(val) | ||
} | ||
|
||
args = processArgs{ | ||
Msg: msg, | ||
GroupID: "foo", | ||
TopicToConfigFormatMap: tcFmtMap, | ||
} | ||
|
||
tableName, err = args.process(ctx, cfg, memDB, &mocks.FakeBaseline{}, metrics.NullMetricsProvider{}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, table, tableName) | ||
|
||
td := memoryDB.GetOrCreateTableData(table) | ||
// Check that there are corresponding row(s) in the memory DB | ||
assert.Len(t, td.Rows(), idx) | ||
msg.KafkaMsg.Key = []byte(fmt.Sprintf("Struct{id=%v}", 1004)) | ||
msg.KafkaMsg.Value = []byte(val) | ||
args = processArgs{ | ||
Msg: msg, | ||
GroupID: "foo", | ||
TopicToConfigFormatMap: tcFmtMap, | ||
} | ||
|
||
tableName, err = args.process(ctx, cfg, memDB, &mocks.FakeBaseline{}, metrics.NullMetricsProvider{}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, table, tableName) | ||
|
||
td := memoryDB.GetOrCreateTableData(table) | ||
// Check that there are corresponding row(s) in the memory DB | ||
assert.Len(t, td.Rows(), 1) | ||
|
||
var rowData map[string]any | ||
for _, row := range td.Rows() { | ||
if row["_id"] == "1" { | ||
if row["_id"] == "1004" { | ||
rowData = row | ||
} | ||
} | ||
|
||
val, isOk := rowData[constants.DeleteColumnMarker] | ||
assert.True(t, isOk) | ||
assert.False(t, val.(bool)) | ||
|
||
msg.KafkaMsg.Value = []byte("not a json object") | ||
args = processArgs{ | ||
Msg: msg, | ||
GroupID: "foo", | ||
TopicToConfigFormatMap: tcFmtMap, | ||
{ | ||
rowValue, isOk := rowData[constants.DeleteColumnMarker] | ||
assert.True(t, isOk) | ||
assert.False(t, rowValue.(bool)) | ||
} | ||
{ | ||
msg.KafkaMsg.Value = []byte("not a json object") | ||
args = processArgs{ | ||
Msg: msg, | ||
GroupID: "foo", | ||
TopicToConfigFormatMap: tcFmtMap, | ||
} | ||
|
||
tableName, err = args.process(ctx, cfg, memDB, &mocks.FakeBaseline{}, metrics.NullMetricsProvider{}) | ||
assert.ErrorContains(t, err, "cannot unmarshall event: failed to unmarshal json: invalid character 'o' in literal") | ||
assert.Empty(t, tableName) | ||
assert.True(t, td.NumberOfRows() > 0) | ||
tableName, err = args.process(ctx, cfg, memDB, &mocks.FakeBaseline{}, metrics.NullMetricsProvider{}) | ||
assert.ErrorContains(t, err, "cannot unmarshall event: failed to unmarshal json: invalid character 'o' in literal") | ||
assert.Empty(t, tableName) | ||
assert.True(t, td.NumberOfRows() > 0) | ||
} | ||
} | ||
|
||
func TestProcessMessageSkip(t *testing.T) { | ||
|