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

Function TestMultiPartListDeleteAndAdd

posting/list_test.go:1405–1511  ·  view source on GitHub ↗

Verify that the first part of a multi-part list is kept even when all its entries have been deleted. Do this by creating a list, deleting the first half, and ensuring iteration and mutation still work as expected.

(t *testing.T)

Source from the content-addressed store, hash-verified

1403// entries have been deleted. Do this by creating a list, deleting the first
1404// half, and ensuring iteration and mutation still work as expected.
1405func TestMultiPartListDeleteAndAdd(t *testing.T) {
1406 size := int(1e5)
1407 // For testing, set the max list size to a lower threshold.
1408 defer setMaxListSize(maxListSize)
1409 maxListSize = 5000
1410
1411 // Add entries to the maps.
1412 key := x.DataKey(x.AttrInRootNamespace(uuid.New().String()), 1331)
1413 ol, err := readPostingListFromDisk(key, ps, math.MaxUint64)
1414 require.NoError(t, err)
1415 for i := 1; i <= size; i++ {
1416 edge := &pb.DirectedEdge{
1417 ValueId: uint64(i),
1418 }
1419
1420 txn := Txn{StartTs: uint64(i)}
1421 addMutationHelper(t, ol, edge, Set, &txn)
1422 require.NoError(t, ol.commitMutation(uint64(i), uint64(i)+1))
1423 if i%2000 == 0 {
1424 kvs, err := ol.Rollup(nil, math.MaxUint64)
1425 require.NoError(t, err)
1426 require.NoError(t, writePostingListToDisk(kvs))
1427 ol, err = readPostingListFromDisk(key, ps, math.MaxUint64)
1428 require.NoError(t, err)
1429 }
1430 }
1431
1432 // Verify all entries are in the list.
1433 opt := ListOptions{ReadTs: math.MaxUint64}
1434 l, err := ol.Uids(opt)
1435 require.NoError(t, err)
1436 require.Equal(t, size, len(l.Uids), "List of Uids received: %+v", l.Uids)
1437 for i, uid := range l.Uids {
1438 require.Equal(t, uint64(i+1), uid)
1439 }
1440
1441 // Delete the first half of the previously inserted entries from the list.
1442 baseStartTs := uint64(size) + 1
1443 for i := 1; i <= size/2; i++ {
1444 edge := &pb.DirectedEdge{
1445 ValueId: uint64(i),
1446 }
1447 txn := Txn{StartTs: baseStartTs + uint64(i)}
1448 addMutationHelper(t, ol, edge, Del, &txn)
1449 require.NoError(t, ol.commitMutation(baseStartTs+uint64(i), baseStartTs+uint64(i)+1))
1450 if i%2000 == 0 {
1451 kvs, err := ol.Rollup(nil, math.MaxUint64)
1452 require.NoError(t, err)
1453 require.NoError(t, writePostingListToDisk(kvs))
1454 ol, err = readPostingListFromDisk(key, ps, math.MaxUint64)
1455 require.NoError(t, err)
1456 }
1457 }
1458
1459 // Rollup list at the end of all the deletions.
1460 kvs, err := ol.Rollup(nil, math.MaxUint64)
1461 require.NoError(t, err)
1462 require.NoError(t, writePostingListToDisk(kvs))

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
UidsMethod · 0.45

Tested by

no test coverage detected