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

Function TestRecursiveSplits

posting/list_test.go:1746–1793  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1744}
1745
1746func TestRecursiveSplits(t *testing.T) {
1747 // For testing, set the max list size to a lower threshold.
1748 defer setMaxListSize(maxListSize)
1749 maxListSize = mb / 2
1750
1751 // Create a list that should be split recursively.
1752 size := int(1e5)
1753 key := x.DataKey(x.AttrInRootNamespace(uuid.New().String()), 1331)
1754 ol, err := readPostingListFromDisk(key, ps, math.MaxUint64)
1755 require.NoError(t, err)
1756 commits := 0
1757 for i := 1; i <= size; i++ {
1758 commits++
1759 edge := &pb.DirectedEdge{
1760 ValueId: uint64(i),
1761 }
1762 edge.Facets = []*api.Facet{{Key: strconv.Itoa(i)}}
1763
1764 txn := Txn{StartTs: uint64(i)}
1765 addMutationHelper(t, ol, edge, Set, &txn)
1766 require.NoError(t, ol.commitMutation(uint64(i), uint64(i)+1))
1767
1768 // Do not roll-up the list here to ensure the final list should
1769 // be split more than once.
1770 }
1771
1772 // Rollup the list. The final output should have more than two parts.
1773 kvs, err := ol.Rollup(nil, math.MaxUint64)
1774 require.NoError(t, err)
1775 require.NoError(t, writePostingListToDisk(kvs))
1776 ol, err = readPostingListFromDisk(key, ps, math.MaxUint64)
1777 require.NoError(t, err)
1778 require.True(t, len(ol.plist.Splits) > 2)
1779
1780 // Read back the list and verify the data is correct.
1781 var facets []string
1782 err = ol.Iterate(uint64(size)+1, 0, func(p *pb.Posting) error {
1783 if len(p.Facets) > 0 {
1784 facets = append(facets, p.Facets[0].Key)
1785 }
1786 return nil
1787 })
1788 require.NoError(t, err)
1789 require.Equal(t, commits, len(facets))
1790 for i, facet := range facets {
1791 require.Equal(t, facet, strconv.Itoa(i+1))
1792 }
1793}
1794
1795var ps *badger.DB
1796

Callers

nothing calls this directly

Calls 10

DataKeyFunction · 0.92
AttrInRootNamespaceFunction · 0.92
setMaxListSizeFunction · 0.85
addMutationHelperFunction · 0.85
commitMutationMethod · 0.80
RollupMethod · 0.80
readPostingListFromDiskFunction · 0.70
writePostingListToDiskFunction · 0.70
StringMethod · 0.45
IterateMethod · 0.45

Tested by

no test coverage detected