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

Function TestScalarPredicateCount

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

Source from the content-addressed store, hash-verified

459}
460
461func TestScalarPredicateCount(t *testing.T) {
462 dir, err := os.MkdirTemp("", "storetest_")
463 x.Check(err)
464 defer os.RemoveAll(dir)
465
466 opt := badger.DefaultOptions(dir)
467 ps, err := badger.OpenManaged(opt)
468 x.Check(err)
469 pstore = ps
470 posting.Init(ps, 0, false)
471 Init(ps)
472 err = schema.ParseBytes([]byte("scalarPredicateCount: uid @count ."), 1)
473 require.NoError(t, err)
474
475 ctx := context.Background()
476 attr := x.AttrInRootNamespace("scalarPredicateCount")
477
478 runM := func(startTs, commitTs uint64, edge *pb.DirectedEdge) {
479 txn := posting.Oracle().RegisterStartTs(startTs)
480 x.Check(runMutation(ctx, edge, txn))
481 txn.Update()
482 writer := posting.NewTxnWriter(pstore)
483 require.NoError(t, txn.CommitToDisk(writer, commitTs))
484 require.NoError(t, writer.Flush())
485 txn.UpdateCachedKeys(commitTs)
486 }
487
488 runM(5, 7, &pb.DirectedEdge{
489 ValueId: 2,
490 ValueType: pb.Posting_UID,
491 Attr: attr,
492 Entity: 1,
493 Op: pb.DirectedEdge_SET,
494 })
495
496 key := x.CountKey(attr, 1, false)
497 rollup(t, key, ps, 8)
498
499 runM(9, 11, &pb.DirectedEdge{
500 ValueId: 3,
501 ValueType: pb.Posting_UID,
502 Attr: attr,
503 Entity: 1,
504 Op: pb.DirectedEdge_SET,
505 })
506
507 txn := posting.Oracle().RegisterStartTs(15)
508 l, err := txn.Get(key)
509 require.Nil(t, err)
510 l.RLock()
511 require.Equal(t, 1, l.GetLength(15))
512 l.RUnlock()
513}
514
515func TestSingleUidReplacement(t *testing.T) {
516 dir, err := os.MkdirTemp("", "storetest_")

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
CountKeyFunction · 0.92
rollupFunction · 0.85
RemoveAllMethod · 0.80
RegisterStartTsMethod · 0.80
CommitToDiskMethod · 0.80

Tested by

no test coverage detected