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

Function TestSingleUidReplacement

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

Source from the content-addressed store, hash-verified

513}
514
515func TestSingleUidReplacement(t *testing.T) {
516 dir, err := os.MkdirTemp("", "storetest_")
517 x.Check(err)
518 defer os.RemoveAll(dir)
519
520 opt := badger.DefaultOptions(dir)
521 ps, err := badger.OpenManaged(opt)
522 x.Check(err)
523 pstore = ps
524 posting.Init(ps, 0, false)
525 Init(ps)
526 err = schema.ParseBytes([]byte("singleUidReplaceTest: uid ."), 1)
527 require.NoError(t, err)
528
529 ctx := context.Background()
530 txn := posting.Oracle().RegisterStartTs(5)
531 attr := x.AttrInRootNamespace("singleUidReplaceTest")
532
533 // Txn 1. Set 1 -> 2
534 x.Check(runMutation(ctx, &pb.DirectedEdge{
535 ValueId: 2,
536 Attr: attr,
537 Entity: 1,
538 Op: pb.DirectedEdge_SET,
539 }, txn))
540
541 txn.Update()
542 writer := posting.NewTxnWriter(pstore)
543 require.NoError(t, txn.CommitToDisk(writer, 7))
544 require.NoError(t, writer.Flush())
545 txn.UpdateCachedKeys(7)
546
547 // Txn 2. Set 1 -> 3
548 txn = posting.Oracle().RegisterStartTs(9)
549
550 x.Check(runMutation(ctx, &pb.DirectedEdge{
551 ValueId: 3,
552 Attr: attr,
553 Entity: 1,
554 Op: pb.DirectedEdge_SET,
555 }, txn))
556
557 txn.Update()
558 writer = posting.NewTxnWriter(pstore)
559 require.NoError(t, txn.CommitToDisk(writer, 11))
560 require.NoError(t, writer.Flush())
561 txn.UpdateCachedKeys(11)
562
563 key := x.DataKey(attr, 1)
564
565 // Reading the david index, we should see 2 inserted, 1 deleted
566 txn = posting.Oracle().RegisterStartTs(15)
567 l, err := txn.Get(key)
568 require.NoError(t, err)
569
570 uids, err := l.Uids(posting.ListOptions{ReadTs: 15})
571 require.NoError(t, err)
572 require.Equal(t, uids.Uids, []uint64{3})

Callers

nothing calls this directly

Calls 15

FlushMethod · 0.95
CheckFunction · 0.92
InitFunction · 0.92
ParseBytesFunction · 0.92
OracleFunction · 0.92
AttrInRootNamespaceFunction · 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