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

Function TestScalarPredicateIntCount

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

Source from the content-addressed store, hash-verified

405}
406
407func TestScalarPredicateIntCount(t *testing.T) {
408 dir, err := os.MkdirTemp("", "storetest_")
409 x.Check(err)
410 defer os.RemoveAll(dir)
411
412 opt := badger.DefaultOptions(dir)
413 ps, err := badger.OpenManaged(opt)
414 x.Check(err)
415 pstore = ps
416 posting.Init(ps, 0, false)
417 Init(ps)
418 err = schema.ParseBytes([]byte("scalarPredicateCount1: string @count ."), 1)
419 require.NoError(t, err)
420
421 ctx := context.Background()
422 attr := x.AttrInRootNamespace("scalarPredicateCount1")
423
424 runM := func(startTs, commitTs uint64, edge *pb.DirectedEdge) {
425 txn := posting.Oracle().RegisterStartTs(startTs)
426 x.Check(runMutation(ctx, edge, txn))
427 txn.Update()
428 writer := posting.NewTxnWriter(pstore)
429 require.NoError(t, txn.CommitToDisk(writer, commitTs))
430 require.NoError(t, writer.Flush())
431 txn.UpdateCachedKeys(commitTs)
432 }
433
434 runM(5, 7, &pb.DirectedEdge{
435 Value: []byte("a"),
436 ValueType: pb.Posting_STRING,
437 Attr: attr,
438 Entity: 1,
439 Op: pb.DirectedEdge_SET,
440 })
441
442 key := x.CountKey(attr, 1, false)
443 rollup(t, key, ps, 8)
444
445 runM(9, 11, &pb.DirectedEdge{
446 Value: []byte("a"),
447 ValueType: pb.Posting_STRING,
448 Attr: attr,
449 Entity: 1,
450 Op: pb.DirectedEdge_DEL,
451 })
452
453 txn := posting.Oracle().RegisterStartTs(20)
454 l, err := txn.Get(key)
455 require.Nil(t, err)
456 l.RLock()
457 require.Equal(t, 0, l.GetLength(20))
458 l.RUnlock()
459}
460
461func TestScalarPredicateCount(t *testing.T) {
462 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