TestLogGrow writes data of sufficient size to grow the log file.
(t *testing.T)
| 108 | |
| 109 | // TestLogGrow writes data of sufficient size to grow the log file. |
| 110 | func TestLogGrow(t *testing.T) { |
| 111 | test := func(t *testing.T, key []byte) { |
| 112 | dir := t.TempDir() |
| 113 | ds, err := InitEncrypted(dir, key) |
| 114 | require.NoError(t, err) |
| 115 | |
| 116 | const numEntries = (maxNumEntries * 3) / 2 |
| 117 | |
| 118 | // 5KB * 30000 is ~ 150MB, this will cause the log file to grow. |
| 119 | var entries []raftpb.Entry |
| 120 | for i := range numEntries { |
| 121 | data := make([]byte, 5<<10) |
| 122 | rand.Read(data) |
| 123 | entry := raftpb.Entry{Index: uint64(i + 1), Term: 1, Data: data} |
| 124 | entries = append(entries, entry) |
| 125 | } |
| 126 | require.NoError(t, ds.wal.AddEntries(entries)) |
| 127 | |
| 128 | // Reopen the file and retrieve all entries. |
| 129 | ds, err = InitEncrypted(dir, key) |
| 130 | require.NoError(t, err) |
| 131 | readEntries := ds.wal.allEntries(0, math.MaxInt64, math.MaxInt64) |
| 132 | require.Equal(t, numEntries, len(readEntries)) |
| 133 | |
| 134 | for i, gotEntry := range readEntries { |
| 135 | expEntry := entries[i] |
| 136 | require.Equal(t, expEntry.Data, gotEntry.Data) |
| 137 | require.Equal(t, expEntry.Index, gotEntry.Index) |
| 138 | require.Equal(t, expEntry.Term, gotEntry.Term) |
| 139 | require.Equal(t, expEntry.Type, gotEntry.Type) |
| 140 | } |
| 141 | } |
| 142 | t.Run("without encryption", func(t *testing.T) { test(t, nil) }) |
| 143 | t.Run("with encryption", func(t *testing.T) { test(t, []byte("badger16byteskey")) }) |
| 144 | } |
nothing calls this directly
no test coverage detected