MCPcopy
hub / github.com/dgraph-io/badger / TestLoad

Function TestLoad

db_test.go:735–817  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

733}
734
735func TestLoad(t *testing.T) {
736 testLoad := func(t *testing.T, opt Options) {
737 dir, err := ioutil.TempDir("", "badger-test")
738 require.NoError(t, err)
739 defer removeDir(dir)
740 opt.Dir = dir
741 opt.ValueDir = dir
742 n := 10000
743 {
744 kv, err := Open(opt)
745 require.NoError(t, err)
746 for i := 0; i < n; i++ {
747 if (i % 10000) == 0 {
748 fmt.Printf("Putting i=%d\n", i)
749 }
750 k := []byte(fmt.Sprintf("%09d", i))
751 txnSet(t, kv, k, k, 0x00)
752 }
753 kv.Close()
754 }
755 kv, err := Open(opt)
756 require.NoError(t, err)
757 require.Equal(t, uint64(10001), kv.orc.readTs())
758
759 for i := 0; i < n; i++ {
760 if (i % 10000) == 0 {
761 fmt.Printf("Testing i=%d\n", i)
762 }
763 k := fmt.Sprintf("%09d", i)
764 require.NoError(t, kv.View(func(txn *Txn) error {
765 item, err := txn.Get([]byte(k))
766 require.NoError(t, err)
767 require.EqualValues(t, k, string(getItemValue(t, item)))
768 return nil
769 }))
770 }
771 kv.Close()
772 summary := kv.lc.getSummary()
773
774 // Check that files are garbage collected.
775 idMap := getIDMap(dir)
776 for fileID := range idMap {
777 // Check that name is in summary.filenames.
778 require.True(t, summary.fileIDs[fileID], "%d", fileID)
779 }
780 require.EqualValues(t, len(idMap), len(summary.fileIDs))
781
782 var fileIDs []uint64
783 for k := range summary.fileIDs { // Map to array.
784 fileIDs = append(fileIDs, k)
785 }
786 sort.Slice(fileIDs, func(i, j int) bool { return fileIDs[i] < fileIDs[j] })
787 fmt.Printf("FileIDs: %v\n", fileIDs)
788 }
789 t.Run("TestLoad Without Encryption/Compression", func(t *testing.T) {
790 opt := getTestOptions("")
791 opt.Compression = options.None
792 testLoad(t, opt)

Callers

nothing calls this directly

Calls 13

removeDirFunction · 0.85
OpenFunction · 0.85
txnSetFunction · 0.85
getItemValueFunction · 0.85
getIDMapFunction · 0.85
getTestOptionsFunction · 0.85
PrintfMethod · 0.80
readTsMethod · 0.80
ViewMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.45
getSummaryMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…