MCPcopy
hub / github.com/alibaba/MongoShake / TestDiffUpdateOplogToNormal_TimeSeries

Function TestDiffUpdateOplogToNormal_TimeSeries

oplog/oplog_test.go:730–781  ·  view source on GitHub ↗

TestDiffUpdateOplogToNormal_TimeSeries tests that time-series bucket updates with column-store binary diff (sdata.b) correctly return an error, triggering the applyOps fallback path in the executor.

(t *testing.T)

Source from the content-addressed store, hash-verified

728// with column-store binary diff (sdata.b) correctly return an error,
729// triggering the applyOps fallback path in the executor.
730func TestDiffUpdateOplogToNormal_TimeSeries(t *testing.T) {
731 nr := 0
732 // Case: sdata.b column-store binary diff should return error
733 {
734 fmt.Printf("TestDiffUpdateOplogToNormal_TimeSeries case %d. sdata.b returns error\n", nr)
735 nr++
736 // Simulate a time-series bucket update oplog with $v:2 diff containing
737 // sdata -> b (binary column-store diff) which cannot be parsed
738 updateObj := bson.D{
739 {Key: "$v", Value: int32(2)},
740 {Key: "diff", Value: bson.D{
741 {Key: "sdata", Value: bson.D{
742 {Key: "b", Value: bson.D{
743 {Key: "temperature", Value: bson.D{
744 {Key: "o", Value: int32(10)},
745 {Key: "d", Value: primitive.Binary{Subtype: 0, Data: []byte{0x01, 0x02, 0x03}}},
746 }},
747 }},
748 }},
749 }},
750 }
751 _, err := DiffUpdateOplogToNormal(updateObj)
752 assert.NotNil(t, err, "sdata.b column-store diff should return error")
753 assert.Contains(t, err.Error(), "parse diffOplog failed", "error should indicate diff parse failure")
754 }
755 // Case: scontrol with normal u/s keys should parse successfully
756 {
757 fmt.Printf("TestDiffUpdateOplogToNormal_TimeSeries case %d. scontrol normal diff parses OK\n", nr)
758 nr++
759 // Simulate a time-series bucket update oplog with scontrol containing
760 // normal update keys (u for set field)
761 updateObj := bson.D{
762 {Key: "$v", Value: int32(2)},
763 {Key: "diff", Value: bson.D{
764 {Key: "scontrol", Value: bson.D{
765 {Key: "u", Value: bson.D{
766 {Key: "count", Value: int32(5)},
767 }},
768 {Key: "smin", Value: bson.D{
769 {Key: "u", Value: bson.D{{Key: "humidity", Value: 50}}},
770 }},
771 {Key: "smax", Value: bson.D{
772 {Key: "u", Value: bson.D{{Key: "temperature", Value: 30}}},
773 }},
774 }},
775 }},
776 }
777 result, err := DiffUpdateOplogToNormal(updateObj)
778 assert.Nil(t, err, "scontrol with normal u/s keys should parse without error")
779 assert.NotNil(t, result, "result should not be nil")
780 }
781}

Callers

nothing calls this directly

Calls 3

DiffUpdateOplogToNormalFunction · 0.85
PrintfMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected