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

Function TestSingleWriter

executor/db_writer_test.go:86–498  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestSingleWriter(t *testing.T) {
87 // test single writer
88
89 _ = utils.InitialLogger("", "", "debug", true, 1)
90
91 var nr int
92
93 // simple test
94 {
95 fmt.Printf("TestSingleWriter case %d.\n", nr)
96 nr++
97
98 conn, err := utils.NewMongoCommunityConn(testMongoAddress, "primary", true,
99 utils.ReadWriteConcernDefault, utils.ReadWriteConcernDefault, "")
100 assert.Equal(t, nil, err, "should be equal")
101
102 // drop database
103 err = conn.Client.Database(testDb).Drop(nil)
104 assert.Equal(t, nil, err, "should be equal")
105
106 writer := NewDbWriter(conn, bson.E{}, false, 0)
107
108 inserts := []*OplogRecord{mockOplogRecord(1, 1, -1)}
109
110 // write 1
111 err = writer.doInsert(testDb, testCollection, bson.E{}, inserts, false)
112 assert.Equal(t, nil, err, "should be equal")
113
114 // update 1->2
115 err = writer.doUpdate(testDb, testCollection, bson.E{}, []*OplogRecord{
116 mockOplogRecord(1, 10, 1),
117 }, false)
118 assert.Equal(t, nil, err, "should be equal")
119
120 // query
121 result, err := unit_test_common.FetchAllDocumentBsonM(conn.Client, testDb, testCollection, nil)
122 assert.Equal(t, nil, err, "should be equal")
123 assert.Equal(t, 1, len(result), "should be equal")
124 assert.Equal(t, int32(10), result[0]["x"], "should be equal")
125 assert.Equal(t, int32(1), result[0]["_id"], "should be equal")
126
127 // delete 2
128 err = writer.doDelete(testDb, testCollection, bson.E{}, []*OplogRecord{
129 mockDeleteOplogRecord(1),
130 })
131 assert.Equal(t, nil, err, "should be equal")
132
133 // query
134 result, err = unit_test_common.FetchAllDocumentBsonM(conn.Client, testDb, testCollection, nil)
135 assert.Equal(t, nil, err, "should be equal")
136 assert.Equal(t, 0, len(result), "should be equal")
137 }
138
139 // simple upsert
140 {
141 fmt.Printf("TestSingleWriter case %d.\n", nr)
142 nr++
143

Callers

nothing calls this directly

Calls 12

FetchAllDocumentBsonMFunction · 0.92
NewDbWriterFunction · 0.85
mockOplogRecordFunction · 0.85
mockDeleteOplogRecordFunction · 0.85
objectIdFromIntFunction · 0.85
PrintfMethod · 0.80
PrintlnMethod · 0.80
ErrorMethod · 0.80
doInsertMethod · 0.65
doUpdateMethod · 0.65
doDeleteMethod · 0.65
doUpdateOnInsertMethod · 0.65

Tested by

no test coverage detected