github.com/cockroachdb/pebble@v0.0.0-20231214172447-ab4952c5f87b/cmd/pebble/replay_test.go (about) 1 // Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use 2 // of this source code is governed by a BSD-style license that can be found in 3 // the LICENSE file. 4 5 package main 6 7 import ( 8 "fmt" 9 "testing" 10 11 "github.com/cockroachdb/pebble" 12 "github.com/cockroachdb/pebble/internal/cache" 13 "github.com/stretchr/testify/require" 14 ) 15 16 func TestParseOptionsStr(t *testing.T) { 17 type testCase struct { 18 c replayConfig 19 options *pebble.Options 20 } 21 22 testCases := []testCase{ 23 { 24 c: replayConfig{optionsString: `[Options] max_concurrent_compactions=9`}, 25 options: &pebble.Options{MaxConcurrentCompactions: func() int { return 9 }}, 26 }, 27 { 28 c: replayConfig{optionsString: `[Options] bytes_per_sync=90000`}, 29 options: &pebble.Options{BytesPerSync: 90000}, 30 }, 31 { 32 c: replayConfig{optionsString: fmt.Sprintf(`[Options] cache_size=%d`, 16<<20 /* 16MB */)}, 33 options: &pebble.Options{Cache: cache.New(16 << 20 /* 16 MB */)}, 34 }, 35 { 36 c: replayConfig{ 37 maxCacheSize: 16 << 20, /* 16 MB */ 38 optionsString: fmt.Sprintf(`[Options] cache_size=%d`, int64(10<<30 /* 10 GB */)), 39 }, 40 options: &pebble.Options{Cache: cache.New(16 << 20 /* 16 MB */)}, 41 }, 42 { 43 c: replayConfig{optionsString: `[Options] [Level "0"] target_file_size=222`}, 44 options: &pebble.Options{Levels: []pebble.LevelOptions{ 45 {TargetFileSize: 222}, 46 }}, 47 }, 48 { 49 c: replayConfig{optionsString: `[Options] lbase_max_bytes=10 max_open_files=20 [Level "0"] target_file_size=30 [Level "1"] index_block_size=40`}, 50 options: &pebble.Options{ 51 LBaseMaxBytes: 10, 52 MaxOpenFiles: 20, 53 Levels: []pebble.LevelOptions{ 54 {TargetFileSize: 30}, 55 {IndexBlockSize: 40}, 56 }, 57 }, 58 }, 59 } 60 61 for _, tc := range testCases { 62 o := new(pebble.Options) 63 require.NoError(t, tc.c.parseCustomOptions(tc.c.optionsString, o)) 64 o.EnsureDefaults() 65 got := o.String() 66 67 tc.options.EnsureDefaults() 68 want := tc.options.String() 69 require.Equal(t, want, got) 70 if o.Cache != nil { 71 o.Cache.Unref() 72 } 73 if tc.options.Cache != nil { 74 tc.options.Cache.Unref() 75 } 76 } 77 }