MCPcopy
hub / github.com/dgraph-io/dgraph / TestAddMutation

Function TestAddMutation

posting/list_test.go:166–215  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

164}
165
166func TestAddMutation(t *testing.T) {
167 key := x.DataKey(x.AttrInRootNamespace("name"), 2)
168
169 txn := NewTxn(1)
170 l, err := txn.Get(key)
171 require.NoError(t, err)
172
173 edge := &pb.DirectedEdge{
174 ValueId: 9,
175 Facets: []*api.Facet{{Key: "testing"}},
176 }
177 addMutationHelper(t, l, edge, Set, txn)
178
179 require.Equal(t, listToArray(t, 0, l, 1), []uint64{9})
180
181 p := getFirst(t, l, 1)
182 require.NotNil(t, p, "Unable to retrieve posting")
183 require.EqualValues(t, "testing", p.Facets[0].Key)
184
185 // Add another edge now.
186 edge.ValueId = 81
187 addMutationHelper(t, l, edge, Set, txn)
188 require.Equal(t, listToArray(t, 0, l, 1), []uint64{9, 81})
189
190 // Add another edge, in between the two above.
191 edge.ValueId = 49
192 addMutationHelper(t, l, edge, Set, txn)
193 require.Equal(t, listToArray(t, 0, l, 1), []uint64{9, 49, 81})
194
195 checkUids(t, l, []uint64{9, 49, 81}, 1)
196
197 // Delete an edge, add an edge, replace an edge
198 edge.ValueId = 49
199 addMutationHelper(t, l, edge, Del, txn)
200
201 edge.ValueId = 69
202 addMutationHelper(t, l, edge, Set, txn)
203
204 edge.ValueId = 9
205 edge.Facets = []*api.Facet{{Key: "anti-testing"}}
206 addMutationHelper(t, l, edge, Set, txn)
207 require.NoError(t, l.commitMutation(1, 2))
208
209 uids := []uint64{9, 69, 81}
210 checkUids(t, l, uids, 3)
211
212 p = getFirst(t, l, 3)
213 require.NotNil(t, p, "Unable to retrieve posting")
214 require.EqualValues(t, "anti-testing", p.Facets[0].Key)
215}
216
217func getFirst(t *testing.T, l *List, readTs uint64) (res pb.Posting) {
218 require.NoError(t, l.Iterate(readTs, 0, func(p *pb.Posting) error {

Callers

nothing calls this directly

Calls 9

GetMethod · 0.95
DataKeyFunction · 0.92
AttrInRootNamespaceFunction · 0.92
NewTxnFunction · 0.85
addMutationHelperFunction · 0.85
listToArrayFunction · 0.85
getFirstFunction · 0.85
checkUidsFunction · 0.85
commitMutationMethod · 0.80

Tested by

no test coverage detected