MCPcopy
hub / github.com/etcd-io/bbolt / TestFreelist_E2E_Reload

Function TestFreelist_E2E_Reload

internal/freelist/freelist_test.go:451–484  ·  view source on GitHub ↗

tests the reloading from another physical page

(t *testing.T)

Source from the content-addressed store, hash-verified

449
450// tests the reloading from another physical page
451func TestFreelist_E2E_Reload(t *testing.T) {
452 freelist := newTestFreelist()
453 freelist.Init([]common.Pgid{})
454 freelist.Free(common.Txid(2), common.NewPage(5, common.LeafPageFlag, 0, 1))
455 freelist.Free(common.Txid(2), common.NewPage(8, common.LeafPageFlag, 0, 0))
456 freelist.ReleasePendingPages()
457 requirePages(t, freelist, common.Pgids{5, 6, 8}, common.Pgids{})
458 buf := make([]byte, 4096)
459 p := common.LoadPage(buf)
460 freelist.Write(p)
461
462 freelist.Free(common.Txid(3), common.NewPage(3, common.LeafPageFlag, 0, 1))
463 freelist.Free(common.Txid(3), common.NewPage(10, common.LeafPageFlag, 0, 2))
464 requirePages(t, freelist, common.Pgids{5, 6, 8}, common.Pgids{3, 4, 10, 11, 12})
465
466 otherBuf := make([]byte, 4096)
467 px := common.LoadPage(otherBuf)
468 freelist.Write(px)
469
470 loadFreeList := newTestFreelist()
471 loadFreeList.Init([]common.Pgid{})
472 loadFreeList.Read(px)
473 requirePages(t, loadFreeList, common.Pgids{3, 4, 5, 6, 8, 10, 11, 12}, common.Pgids{})
474 // restore the original freelist again
475 loadFreeList.Reload(p)
476 requirePages(t, loadFreeList, common.Pgids{5, 6, 8}, common.Pgids{})
477
478 // reload another page with different free pages to test we are deduplicating the free pages with the pending ones correctly
479 freelist = newTestFreelist()
480 freelist.Init([]common.Pgid{})
481 freelist.Free(common.Txid(5), common.NewPage(5, common.LeafPageFlag, 0, 4))
482 freelist.Reload(p)
483 requirePages(t, freelist, common.Pgids{}, common.Pgids{5, 6, 7, 8, 9})
484}
485
486// tests the loading and reloading from physical pages
487func TestFreelist_E2E_SerDe_HappyPath(t *testing.T) {

Callers

nothing calls this directly

Calls 11

TxidTypeAlias · 0.92
NewPageFunction · 0.92
LoadPageFunction · 0.92
newTestFreelistFunction · 0.85
requirePagesFunction · 0.85
InitMethod · 0.65
FreeMethod · 0.65
ReleasePendingPagesMethod · 0.65
WriteMethod · 0.65
ReadMethod · 0.65
ReloadMethod · 0.65

Tested by

no test coverage detected