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

Function TestLangExact

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

Source from the content-addressed store, hash-verified

667}
668
669func TestLangExact(t *testing.T) {
670 dir, err := os.MkdirTemp("", "storetest_")
671 x.Check(err)
672 defer os.RemoveAll(dir)
673
674 opt := badger.DefaultOptions(dir)
675 ps, err := badger.OpenManaged(opt)
676 x.Check(err)
677 pstore = ps
678 // Not using posting list cache
679 posting.Init(ps, 0, false)
680 Init(ps)
681 err = schema.ParseBytes([]byte("testLang: string @index(term) @lang ."), 1)
682 require.NoError(t, err)
683
684 ctx := context.Background()
685 txn := posting.Oracle().RegisterStartTs(5)
686 attr := x.AttrInRootNamespace("testLang")
687
688 edge := &pb.DirectedEdge{
689 Value: []byte("english"),
690 Attr: attr,
691 Entity: 1,
692 Op: pb.DirectedEdge_SET,
693 Lang: "en",
694 }
695
696 x.Check(runMutation(ctx, edge, txn))
697
698 edge = &pb.DirectedEdge{
699 Value: []byte("hindi"),
700 Attr: attr,
701 Entity: 1,
702 Op: pb.DirectedEdge_SET,
703 Lang: "hi",
704 }
705
706 x.Check(runMutation(ctx, edge, txn))
707
708 txn.Update()
709 writer := posting.NewTxnWriter(pstore)
710 require.NoError(t, txn.CommitToDisk(writer, 2))
711 require.NoError(t, writer.Flush())
712 txn.UpdateCachedKeys(2)
713
714 key := x.DataKey(attr, 1)
715 rollup(t, key, pstore, 4)
716
717 pl, err := readPostingListFromDisk(key, pstore, 6)
718 require.NoError(t, err)
719
720 val, err := pl.ValueForTag(6, "hi")
721 require.NoError(t, err)
722 require.Equal(t, val.Value, []byte("hindi"))
723}
724
725const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
726

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

Tested by

no test coverage detected