...

Source file src/go.etcd.io/bbolt/allocate_test.go

Documentation: go.etcd.io/bbolt

     1  package bbolt
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestTx_allocatePageStats(t *testing.T) {
     8  	f := newTestFreelist()
     9  	ids := []pgid{2, 3}
    10  	f.readIDs(ids)
    11  
    12  	tx := &Tx{
    13  		db: &DB{
    14  			freelist: f,
    15  			pageSize: defaultPageSize,
    16  		},
    17  		meta:  &meta{},
    18  		pages: make(map[pgid]*page),
    19  	}
    20  
    21  	txStats := tx.Stats()
    22  	prePageCnt := txStats.GetPageCount()
    23  	allocateCnt := f.free_count()
    24  
    25  	if _, err := tx.allocate(allocateCnt); err != nil {
    26  		t.Fatal(err)
    27  	}
    28  
    29  	txStats = tx.Stats()
    30  	if txStats.GetPageCount() != prePageCnt+int64(allocateCnt) {
    31  		t.Errorf("Allocated %d but got %d page in stats", allocateCnt, txStats.GetPageCount())
    32  	}
    33  }
    34  

View as plain text