(t *testing.T)
| 1744 | } |
| 1745 | |
| 1746 | func 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 | |
| 1795 | var ps *badger.DB |
| 1796 |
nothing calls this directly
no test coverage detected