From 18f5de98140d65de2e9026df616120ba4f779629 Mon Sep 17 00:00:00 2001 From: ykadowak Date: Thu, 30 Nov 2023 07:38:31 +0000 Subject: [PATCH] Revert "Add bbolt as internal/db/kvs (#2177)" This reverts commit a95676ac95aab33eb4a5aef74e61af47829f636d. --- go.mod | 2 - go.sum | 2 - hack/go.mod.default | 1 - internal/db/kvs/bbolt/bbolt.go | 133 ----- internal/db/kvs/bbolt/bbolt_test.go | 213 ------- internal/db/kvs/bbolt/option.go | 92 --- internal/db/kvs/bbolt/option_test.go | 863 --------------------------- 7 files changed, 1306 deletions(-) delete mode 100644 internal/db/kvs/bbolt/bbolt.go delete mode 100644 internal/db/kvs/bbolt/bbolt_test.go delete mode 100644 internal/db/kvs/bbolt/option.go delete mode 100644 internal/db/kvs/bbolt/option_test.go diff --git a/go.mod b/go.mod index a88d8c06c9..61f16ba25c 100755 --- a/go.mod +++ b/go.mod @@ -270,7 +270,6 @@ replace ( github.com/xlab/treeprint => github.com/xlab/treeprint v1.2.0 github.com/zeebo/assert => github.com/zeebo/assert v1.3.1 github.com/zeebo/xxh3 => github.com/zeebo/xxh3 v1.0.2 - go.etcd.io/bbolt => go.etcd.io/bbolt v1.3.7 go.opencensus.io => go.opencensus.io v0.24.0 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.37.0 go.opentelemetry.io/otel => go.opentelemetry.io/otel v1.11.1 @@ -374,7 +373,6 @@ require ( github.com/scylladb/gocqlx v0.0.0-00010101000000-000000000000 github.com/stretchr/testify v1.8.4 github.com/zeebo/xxh3 v1.0.2 - go.etcd.io/bbolt v1.3.6 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.35.0 go.opentelemetry.io/otel v1.11.2 go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.0.0-00010101000000-000000000000 diff --git a/go.sum b/go.sum index fde8f3fbc5..0d5a12b555 100644 --- a/go.sum +++ b/go.sum @@ -570,8 +570,6 @@ github.com/zeebo/assert v1.3.1 h1:vukIABvugfNMZMQO1ABsyQDJDTVQbn+LWSMy1ol1h6A= github.com/zeebo/assert v1.3.1/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0= github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0= github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA= -go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ= -go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.37.0 h1:+uFejS4DCfNH6d3xODVIGsdhzgzhh45p9gpbHQMbdZI= diff --git a/hack/go.mod.default b/hack/go.mod.default index 3fd1767d19..ee8282afa5 100755 --- a/hack/go.mod.default +++ b/hack/go.mod.default @@ -271,7 +271,6 @@ replace ( github.com/zeebo/assert => github.com/zeebo/assert latest github.com/zeebo/xxh3 => github.com/zeebo/xxh3 latest go.opencensus.io => go.opencensus.io latest - go.etcd.io/bbolt => go.etcd.io/bbolt latest go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.37.0 go.opentelemetry.io/otel => go.opentelemetry.io/otel v1.11.1 go.opentelemetry.io/otel/exporters/otlp/internal/retry => go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.11.1 diff --git a/internal/db/kvs/bbolt/bbolt.go b/internal/db/kvs/bbolt/bbolt.go deleted file mode 100644 index 1275a4b5c8..0000000000 --- a/internal/db/kvs/bbolt/bbolt.go +++ /dev/null @@ -1,133 +0,0 @@ -// Copyright (C) 2019-2023 vdaas.org vald team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// You may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package bbolt - -import ( - "fmt" - "io/fs" - "os" - "reflect" - - "github.com/vdaas/vald/internal/errors" - "github.com/vdaas/vald/internal/sync/errgroup" - bolt "go.etcd.io/bbolt" -) - -type Bbolt interface { - Set(key, val []byte) error - Get(key []byte) ([]byte, bool, error) - AsyncSet(eg errgroup.Group, key, val []byte) - Close(remove bool) error -} - -type bbolt struct { - db *bolt.DB - file string - bucket []byte -} - -const defaultBucket = "vald-bbolt-bucket" - -// New returns a new Bbolt instance. -// If file does not exist, it creates a new file. If bucket is empty, it uses default_bucket. -// If opts is nil, it uses default options. -func New(file, bucket string, mode fs.FileMode, opts ...Option) (Bbolt, error) { - bopts := new(bolt.Options) - for _, opt := range opts { - if err := opt(bopts); err != nil { - return nil, errors.ErrOptionFailed(err, reflect.ValueOf(opt)) - } - } - - db, err := bolt.Open(file, mode, bopts) - if err != nil { - return nil, err - } - - bk := []byte(defaultBucket) - if bucket != "" { - bk = []byte(bucket) - } - - if err := db.Update(func(tx *bolt.Tx) error { - _, err := tx.CreateBucketIfNotExists(bk) - if err != nil { - return fmt.Errorf("failed to create bucket: %w", err) - } - return nil - }); err != nil { - return nil, err - } - - return &bbolt{ - db: db, - file: file, - bucket: bk, - }, nil -} - -func (b *bbolt) Set(key, val []byte) error { - return b.db.Update(func(tx *bolt.Tx) error { - return tx.Bucket(b.bucket).Put(key, val) - }) -} - -func (b *bbolt) Get(key []byte) (val []byte, ok bool, err error) { - if err := b.db.View(func(tx *bolt.Tx) error { - ret := tx.Bucket(b.bucket).Get(key) - if ret == nil { - // key not found. just return without copying anything to val - return nil - } - - // key found. copy the value to val because ret is only valid in this scope - val = make([]byte, len(ret)) - copy(val, ret) - return nil - }); err != nil { - return nil, false, err - } - - if val == nil { - return nil, false, nil - } - - return val, true, nil -} - -// AsyncSet sets the key and value asynchronously for better write performance. -// It accumulates the keys and values until the batch size is reached or the timeout comes, then -// writes them all at once. Wait for the errgroup to make sure all the batches finished if required. -func (b *bbolt) AsyncSet(eg errgroup.Group, key, val []byte) { - eg.Go(func() error { - return b.db.Batch(func(tx *bolt.Tx) error { - return tx.Bucket(b.bucket).Put(key, val) - }) - }) -} - -// Close closes the database and removes the file if remove is true. -func (b *bbolt) Close(remove bool) (err error) { - if cerr := b.db.Close(); cerr != nil { - err = cerr - } - - if remove { - if rerr := os.RemoveAll(b.file); rerr != nil { - err = errors.Join(err, rerr) - } - } - - return err -} diff --git a/internal/db/kvs/bbolt/bbolt_test.go b/internal/db/kvs/bbolt/bbolt_test.go deleted file mode 100644 index cb94504d36..0000000000 --- a/internal/db/kvs/bbolt/bbolt_test.go +++ /dev/null @@ -1,213 +0,0 @@ -// Copyright (C) 2019-2023 vdaas.org vald team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// You may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package bbolt_test - -import ( - "context" - "os" - "path/filepath" - "testing" - - "github.com/stretchr/testify/require" - "github.com/vdaas/vald/internal/db/kvs/bbolt" - "github.com/vdaas/vald/internal/sync/errgroup" -) - -const mode = os.FileMode(0o600) - -func TestNew(t *testing.T) { - t.Parallel() - - type test struct { - name string - testfunc func(t *testing.T) - } - - tests := []test{ - { - name: "New returns bbolt instance with new file when file does not exist", - testfunc: func(t *testing.T) { - tempdir := t.TempDir() - tmpfile := filepath.Join(tempdir, "test.db") - - b, err := bbolt.New(tmpfile, "", mode) - require.NoError(t, err) - require.NotNil(t, b) - }, - }, - { - name: "New returns bbolt instance with existing file", - testfunc: func(t *testing.T) { - tempdir := t.TempDir() - tmpfile := filepath.Join(tempdir, "test.db") - - // create a file - f, err := os.Create(tmpfile) - require.NoError(t, err) - err = f.Close() - require.NoError(t, err) - - b, err := bbolt.New(f.Name(), "", mode) - require.NoError(t, err) - require.NotNil(t, b) - }, - }, - { - name: "New returns bbolt with custom bucket name", - testfunc: func(t *testing.T) { - tempdir := t.TempDir() - tmpfile := filepath.Join(tempdir, "test.db") - - b, err := bbolt.New(tmpfile, "my bucket name", mode) - require.NoError(t, err) - require.NotNil(t, b) - }, - }, - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - test.testfunc(tt) - }) - } -} - -func Test_bbolt_GetSetClose(t *testing.T) { - t.Parallel() - - type test struct { - name string - testfunc func(t *testing.T) - } - - setup := func(t *testing.T) (b bbolt.Bbolt, file string) { - tempdir := t.TempDir() - tmpfile := filepath.Join(tempdir, "test.db") - b, err := bbolt.New(tmpfile, "", mode) - require.NoError(t, err) - - return b, tmpfile - } - - tests := []test{ - { - name: "Succeed to set and get with the key returns the value", - testfunc: func(t *testing.T) { - b, _ := setup(t) - - k, v := []byte("key"), []byte("value") - err := b.Set(k, v) - require.NoError(t, err) - - val, ok, err := b.Get(k) - require.NoError(t, err) - require.True(t, ok) - require.Equal(t, v, val) - }, - }, - { - name: "Get with non-existing key returns false", - testfunc: func(t *testing.T) { - b, _ := setup(t) - val, ok, err := b.Get([]byte("no exist key")) - require.NoError(t, err) - require.False(t, ok) - require.Nil(t, val) - }, - }, - { - name: "Successfully close without removing and recover from the db file", - testfunc: func(t *testing.T) { - b, file := setup(t) - k, v := []byte("key"), []byte("value") - err := b.Set(k, v) - require.NoError(t, err) - - err = b.Close(false) - require.NoError(t, err) - - // recover from the file - b, err = bbolt.New(file, "", mode) - require.NoError(t, err) - - res, ok, err := b.Get(k) - require.NoError(t, err) - require.True(t, ok) - require.Equal(t, v, res) - }, - }, - { - name: "Successfully close with removing", - testfunc: func(t *testing.T) { - b, file := setup(t) - k, v := []byte("key"), []byte("value") - err := b.Set(k, v) - require.NoError(t, err) - - // set remove flag to true - err = b.Close(true) - require.NoError(t, err) - - require.NoFileExists(t, file) - }, - }, - } - - for _, tc := range tests { - test := tc - t.Run(test.name, func(tt *testing.T) { - tt.Parallel() - test.testfunc(tt) - }) - } -} - -func Test_bbolt_AsyncSet(t *testing.T) { - t.Parallel() - - tempdir := t.TempDir() - tmpfile := filepath.Join(tempdir, "test.db") - b, err := bbolt.New(tmpfile, "", mode) - require.NoError(t, err) - - kv := map[string]string{ - "key1": "val1", - "key2": "val2", - "key3": "val3", - "key4": "val4", - "key5": "val5", - } - - eg, _ := errgroup.New(context.Background()) - for k, v := range kv { - b.AsyncSet(eg, []byte(k), []byte(v)) - } - - // wait until all set is done - err = eg.Wait() - require.NoError(t, err) - - for k := range kv { - _, ok, err := b.Get([]byte(k)) - require.NoError(t, err) - require.True(t, ok) - } - - err = b.Close(true) - require.NoError(t, err) -} - -// NOT IMPLEMENTED BELOW diff --git a/internal/db/kvs/bbolt/option.go b/internal/db/kvs/bbolt/option.go deleted file mode 100644 index a9b5632354..0000000000 --- a/internal/db/kvs/bbolt/option.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (C) 2019-2023 vdaas.org vald team -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// You may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package bbolt - -import ( - "time" - - bolt "go.etcd.io/bbolt" -) - -type Option func(*bolt.Options) error - -func WithTimeout(dur time.Duration) Option { - return func(opts *bolt.Options) error { - opts.Timeout = dur - return nil - } -} - -func WithNoGrowSync(noGrowSync bool) Option { - return func(opts *bolt.Options) error { - opts.NoGrowSync = noGrowSync - return nil - } -} - -func WithNoFreeListSync(noFreeListSync bool) Option { - return func(opts *bolt.Options) error { - opts.NoFreelistSync = noFreeListSync - return nil - } -} - -func WithPreLoadFreelist(preloadFreelist bool) Option { - return func(opts *bolt.Options) error { - opts.NoFreelistSync = preloadFreelist - return nil - } -} - -func WithReadOnly(readOnly bool) Option { - return func(opts *bolt.Options) error { - opts.ReadOnly = readOnly - return nil - } -} - -func WithMmapFlags(flags int) Option { - return func(opts *bolt.Options) error { - opts.MmapFlags = flags - return nil - } -} - -func WithInitialMmapSize(initialMmapSize int) Option { - return func(opts *bolt.Options) error { - opts.InitialMmapSize = initialMmapSize - return nil - } -} - -func WithPageSize(pageSize int) Option { - return func(opts *bolt.Options) error { - opts.PageSize = pageSize - return nil - } -} - -func WithNoSync(noSync bool) Option { - return func(opts *bolt.Options) error { - opts.NoSync = noSync - return nil - } -} - -func WithMlock(mlock bool) Option { - return func(opts *bolt.Options) error { - opts.Mlock = mlock - return nil - } -} diff --git a/internal/db/kvs/bbolt/option_test.go b/internal/db/kvs/bbolt/option_test.go deleted file mode 100644 index 8383d66980..0000000000 --- a/internal/db/kvs/bbolt/option_test.go +++ /dev/null @@ -1,863 +0,0 @@ -package bbolt - -// NOT IMPLEMENTED BELOW -// -// func TestWithTimeout(t *testing.T) { -// type args struct { -// dur time.Duration -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// dur:nil, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// dur:nil, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithTimeout(test.args.dur) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithNoGrowSync(t *testing.T) { -// type args struct { -// noGrowSync bool -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// noGrowSync:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// noGrowSync:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithNoGrowSync(test.args.noGrowSync) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithNoFreeListSync(t *testing.T) { -// type args struct { -// noFreeListSync bool -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// noFreeListSync:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// noFreeListSync:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithNoFreeListSync(test.args.noFreeListSync) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithPreLoadFreelist(t *testing.T) { -// type args struct { -// preloadFreelist bool -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// preloadFreelist:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// preloadFreelist:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithPreLoadFreelist(test.args.preloadFreelist) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithReadOnly(t *testing.T) { -// type args struct { -// readOnly bool -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// readOnly:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// readOnly:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithReadOnly(test.args.readOnly) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithMmapFlags(t *testing.T) { -// type args struct { -// flags int -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// flags:0, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// flags:0, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithMmapFlags(test.args.flags) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithInitialMmapSize(t *testing.T) { -// type args struct { -// initialMmapSize int -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// initialMmapSize:0, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// initialMmapSize:0, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithInitialMmapSize(test.args.initialMmapSize) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithPageSize(t *testing.T) { -// type args struct { -// pageSize int -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// pageSize:0, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// pageSize:0, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithPageSize(test.args.pageSize) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithNoSync(t *testing.T) { -// type args struct { -// noSync bool -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// noSync:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// noSync:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithNoSync(test.args.noSync) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// } -// -// func TestWithMlock(t *testing.T) { -// type args struct { -// mlock bool -// } -// type want struct { -// want Option -// } -// type test struct { -// name string -// args args -// want want -// checkFunc func(want, Option) error -// beforeFunc func(*testing.T, args) -// afterFunc func(*testing.T, args) -// } -// defaultCheckFunc := func(w want, got Option) error { -// if !reflect.DeepEqual(got, w.want) { -// return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", got, w.want) -// } -// return nil -// } -// tests := []test{ -// // TODO test cases -// /* -// { -// name: "test_case_1", -// args: args { -// mlock:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// }, -// */ -// -// // TODO test cases -// /* -// func() test { -// return test { -// name: "test_case_2", -// args: args { -// mlock:false, -// }, -// want: want{}, -// checkFunc: defaultCheckFunc, -// beforeFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// afterFunc: func(t *testing.T, args args) { -// t.Helper() -// }, -// } -// }(), -// */ -// } -// -// for _, tc := range tests { -// test := tc -// t.Run(test.name, func(tt *testing.T) { -// tt.Parallel() -// defer goleak.VerifyNone(tt, goleak.IgnoreCurrent()) -// if test.beforeFunc != nil { -// test.beforeFunc(tt, test.args) -// } -// if test.afterFunc != nil { -// defer test.afterFunc(tt, test.args) -// } -// checkFunc := test.checkFunc -// if test.checkFunc == nil { -// checkFunc = defaultCheckFunc -// } -// -// got := WithMlock(test.args.mlock) -// if err := checkFunc(test.want, got); err != nil { -// tt.Errorf("error = %v", err) -// } -// -// }) -// } -// }