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

Function TestScalarPredicateRevCount

worker/sort_test.go:325–405  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

323}
324
325func TestScalarPredicateRevCount(t *testing.T) {
326 dir, err := os.MkdirTemp("", "storetest_")
327 x.Check(err)
328 defer os.RemoveAll(dir)
329
330 opt := badger.DefaultOptions(dir)
331 ps, err := badger.OpenManaged(opt)
332 x.Check(err)
333 pstore = ps
334 posting.Init(ps, 0, false)
335 Init(ps)
336 err = schema.ParseBytes([]byte("scalarPredicateCount2: uid @reverse @count ."), 1)
337 require.NoError(t, err)
338
339 ctx := context.Background()
340 attr := x.AttrInRootNamespace("scalarPredicateCount2")
341
342 runM := func(startTs, commitTs uint64, edges []*pb.DirectedEdge) {
343 txn := posting.Oracle().RegisterStartTs(startTs)
344 for _, edge := range edges {
345 x.Check(runMutation(ctx, edge, txn))
346 }
347 txn.Update()
348 writer := posting.NewTxnWriter(pstore)
349 require.NoError(t, txn.CommitToDisk(writer, commitTs))
350 require.NoError(t, writer.Flush())
351 txn.UpdateCachedKeys(commitTs)
352 }
353
354 runM(9, 11, []*pb.DirectedEdge{{
355 ValueId: 3,
356 ValueType: pb.Posting_UID,
357 Attr: attr,
358 Entity: 1,
359 Op: pb.DirectedEdge_SET,
360 }, {
361 ValueId: 3,
362 ValueType: pb.Posting_UID,
363 Attr: attr,
364 Entity: 1,
365 Op: pb.DirectedEdge_DEL,
366 }})
367
368 txn := posting.Oracle().RegisterStartTs(13)
369 key := x.DataKey(attr, 1)
370 l, err := txn.Get(key)
371 require.Nil(t, err)
372 l.RLock()
373 require.Equal(t, 0, l.GetLength(13))
374 l.RUnlock()
375
376 runM(15, 17, []*pb.DirectedEdge{{
377 ValueId: 3,
378 ValueType: pb.Posting_UID,
379 Attr: attr,
380 Entity: 1,
381 Op: pb.DirectedEdge_SET,
382 }})

Callers

nothing calls this directly

Calls 15

FlushMethod · 0.95
CheckFunction · 0.92
InitFunction · 0.92
ParseBytesFunction · 0.92
AttrInRootNamespaceFunction · 0.92
OracleFunction · 0.92
NewTxnWriterFunction · 0.92
DataKeyFunction · 0.92
RemoveAllMethod · 0.80
RegisterStartTsMethod · 0.80
CommitToDiskMethod · 0.80
UpdateCachedKeysMethod · 0.80

Tested by

no test coverage detected