From bdecfbc1be41935fa8faeee04fc60bb5909809fe Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Thu, 31 Aug 2023 15:47:06 +0300 Subject: [PATCH] [#668] shard/test: Move tests to the main package Semantic patch (also, duplicate definitions are removed): ``` @@ var e identifier @@ -import "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" -shard.e +e ``` Signed-off-by: Evgenii Stratonikov --- .../shard/control_test.go | 6 --- pkg/local_object_storage/shard/delete_test.go | 11 +++--- pkg/local_object_storage/shard/gc_test.go | 15 ++++---- pkg/local_object_storage/shard/get_test.go | 9 ++--- pkg/local_object_storage/shard/head_test.go | 9 ++--- pkg/local_object_storage/shard/inhume_test.go | 9 ++--- pkg/local_object_storage/shard/list_test.go | 7 ++-- pkg/local_object_storage/shard/lock_test.go | 33 ++++++++--------- .../shard/metrics_test.go | 28 ++++++-------- pkg/local_object_storage/shard/range_test.go | 7 ++-- pkg/local_object_storage/shard/shard_test.go | 37 +++++++++---------- .../shard/shutdown_test.go | 7 ++-- 12 files changed, 79 insertions(+), 99 deletions(-) diff --git a/pkg/local_object_storage/shard/control_test.go b/pkg/local_object_storage/shard/control_test.go index 73612d840..128e5cc0c 100644 --- a/pkg/local_object_storage/shard/control_test.go +++ b/pkg/local_object_storage/shard/control_test.go @@ -32,12 +32,6 @@ import ( "go.etcd.io/bbolt" ) -type epochState struct{} - -func (s epochState) CurrentEpoch() uint64 { - return 0 -} - type objAddr struct { obj *objectSDK.Object addr oid.Address diff --git a/pkg/local_object_storage/shard/delete_test.go b/pkg/local_object_storage/shard/delete_test.go index bfafcdc74..8ee613186 100644 --- a/pkg/local_object_storage/shard/delete_test.go +++ b/pkg/local_object_storage/shard/delete_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -7,7 +7,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" "github.com/stretchr/testify/require" @@ -36,8 +35,8 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { obj := testutil.GenerateObjectWithCID(cnr) testutil.AddAttribute(obj, "foo", "bar") - var putPrm shard.PutPrm - var getPrm shard.GetPrm + var putPrm PutPrm + var getPrm GetPrm t.Run("big object", func(t *testing.T) { testutil.AddPayload(obj, 1<<20) @@ -45,7 +44,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { putPrm.SetObject(obj) getPrm.SetAddress(object.AddressOf(obj)) - var delPrm shard.DeletePrm + var delPrm DeletePrm delPrm.SetAddresses(object.AddressOf(obj)) _, err := sh.Put(context.Background(), putPrm) @@ -71,7 +70,7 @@ func testShardDelete(t *testing.T, hasWriteCache bool) { putPrm.SetObject(obj) getPrm.SetAddress(object.AddressOf(obj)) - var delPrm shard.DeletePrm + var delPrm DeletePrm delPrm.SetAddresses(object.AddressOf(obj)) _, err := sh.Put(context.Background(), putPrm) diff --git a/pkg/local_object_storage/shard/gc_test.go b/pkg/local_object_storage/shard/gc_test.go index 9d2771ae4..24038f10b 100644 --- a/pkg/local_object_storage/shard/gc_test.go +++ b/pkg/local_object_storage/shard/gc_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -10,7 +10,6 @@ import ( objectCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" @@ -55,7 +54,7 @@ func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) { lock.SetAttributes(lockExpirationAttr) lockID, _ := lock.ID() - var putPrm shard.PutPrm + var putPrm PutPrm putPrm.SetObject(obj) _, err := sh.Put(context.Background(), putPrm) @@ -69,9 +68,9 @@ func Test_GCDropsLockedExpiredSimpleObject(t *testing.T) { require.NoError(t, err) epoch.Value = 105 - sh.NotificationChannel() <- shard.EventNewEpoch(epoch.Value) + sh.NotificationChannel() <- EventNewEpoch(epoch.Value) - var getPrm shard.GetPrm + var getPrm GetPrm getPrm.SetAddress(objectCore.AddressOf(obj)) require.Eventually(t, func() bool { _, err = sh.Get(context.Background(), getPrm) @@ -141,7 +140,7 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) { lock.SetAttributes(lockExpirationAttr) lockID, _ := lock.ID() - var putPrm shard.PutPrm + var putPrm PutPrm for _, child := range children { putPrm.SetObject(child) @@ -160,7 +159,7 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) { _, err = sh.Put(context.Background(), putPrm) require.NoError(t, err) - var getPrm shard.GetPrm + var getPrm GetPrm getPrm.SetAddress(objectCore.AddressOf(parent)) _, err = sh.Get(context.Background(), getPrm) @@ -168,7 +167,7 @@ func Test_GCDropsLockedExpiredComplexObject(t *testing.T) { require.True(t, errors.As(err, &splitInfoError), "split info must be provided") epoch.Value = 105 - sh.NotificationChannel() <- shard.EventNewEpoch(epoch.Value) + sh.NotificationChannel() <- EventNewEpoch(epoch.Value) require.Eventually(t, func() bool { _, err = sh.Get(context.Background(), getPrm) diff --git a/pkg/local_object_storage/shard/get_test.go b/pkg/local_object_storage/shard/get_test.go index 25639902d..d3aeb5339 100644 --- a/pkg/local_object_storage/shard/get_test.go +++ b/pkg/local_object_storage/shard/get_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "bytes" @@ -9,7 +9,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" @@ -35,8 +34,8 @@ func testShardGet(t *testing.T, hasWriteCache bool) { sh := newShard(t, hasWriteCache) defer releaseShard(sh, t) - var putPrm shard.PutPrm - var getPrm shard.GetPrm + var putPrm PutPrm + var getPrm GetPrm t.Run("small object", func(t *testing.T) { obj := testutil.GenerateObject() @@ -116,7 +115,7 @@ func testShardGet(t *testing.T, hasWriteCache bool) { }) } -func testGet(t *testing.T, sh *shard.Shard, getPrm shard.GetPrm, hasWriteCache bool) (shard.GetRes, error) { +func testGet(t *testing.T, sh *Shard, getPrm GetPrm, hasWriteCache bool) (GetRes, error) { res, err := sh.Get(context.Background(), getPrm) if hasWriteCache { require.Eventually(t, func() bool { diff --git a/pkg/local_object_storage/shard/head_test.go b/pkg/local_object_storage/shard/head_test.go index 3a7457ace..bf6ba990b 100644 --- a/pkg/local_object_storage/shard/head_test.go +++ b/pkg/local_object_storage/shard/head_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -8,7 +8,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" @@ -33,8 +32,8 @@ func testShardHead(t *testing.T, hasWriteCache bool) { sh := newShard(t, hasWriteCache) defer releaseShard(sh, t) - var putPrm shard.PutPrm - var headPrm shard.HeadPrm + var putPrm PutPrm + var headPrm HeadPrm t.Run("regular object", func(t *testing.T) { obj := testutil.GenerateObject() @@ -87,7 +86,7 @@ func testShardHead(t *testing.T, hasWriteCache bool) { }) } -func testHead(t *testing.T, sh *shard.Shard, headPrm shard.HeadPrm, hasWriteCache bool) (shard.HeadRes, error) { +func testHead(t *testing.T, sh *Shard, headPrm HeadPrm, hasWriteCache bool) (HeadRes, error) { res, err := sh.Head(context.Background(), headPrm) if hasWriteCache { require.Eventually(t, func() bool { diff --git a/pkg/local_object_storage/shard/inhume_test.go b/pkg/local_object_storage/shard/inhume_test.go index 3fa6bc0a3..33d483b5e 100644 --- a/pkg/local_object_storage/shard/inhume_test.go +++ b/pkg/local_object_storage/shard/inhume_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -6,7 +6,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" "github.com/stretchr/testify/require" @@ -37,13 +36,13 @@ func testShardInhume(t *testing.T, hasWriteCache bool) { ts := testutil.GenerateObjectWithCID(cnr) - var putPrm shard.PutPrm + var putPrm PutPrm putPrm.SetObject(obj) - var inhPrm shard.InhumePrm + var inhPrm InhumePrm inhPrm.SetTarget(object.AddressOf(ts), object.AddressOf(obj)) - var getPrm shard.GetPrm + var getPrm GetPrm getPrm.SetAddress(object.AddressOf(obj)) _, err := sh.Put(context.Background(), putPrm) diff --git a/pkg/local_object_storage/shard/list_test.go b/pkg/local_object_storage/shard/list_test.go index 63e7651c8..33b94ce06 100644 --- a/pkg/local_object_storage/shard/list_test.go +++ b/pkg/local_object_storage/shard/list_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -7,7 +7,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" @@ -31,7 +30,7 @@ func TestShard_List(t *testing.T) { }) } -func testShardList(t *testing.T, sh *shard.Shard) { +func testShardList(t *testing.T, sh *Shard) { const C = 10 const N = 5 @@ -59,7 +58,7 @@ func testShardList(t *testing.T, sh *shard.Shard) { objs[object.AddressOf(obj).EncodeToString()] = 0 mtx.Unlock() - var putPrm shard.PutPrm + var putPrm PutPrm putPrm.SetObject(obj) _, err := sh.Put(context.Background(), putPrm) diff --git a/pkg/local_object_storage/shard/lock_test.go b/pkg/local_object_storage/shard/lock_test.go index da71c4808..be9a0ba9a 100644 --- a/pkg/local_object_storage/shard/lock_test.go +++ b/pkg/local_object_storage/shard/lock_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -11,7 +11,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client" apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status" @@ -26,13 +25,13 @@ import ( func TestShard_Lock(t *testing.T) { t.Parallel() - var sh *shard.Shard + var sh *Shard rootPath := t.TempDir() - opts := []shard.Option{ - shard.WithID(shard.NewIDFromBytes([]byte{})), - shard.WithLogger(&logger.Logger{Logger: zap.NewNop()}), - shard.WithBlobStorOptions( + opts := []Option{ + WithID(NewIDFromBytes([]byte{})), + WithLogger(&logger.Logger{Logger: zap.NewNop()}), + WithBlobStorOptions( blobstor.WithStorages([]blobstor.SubStorage{ { Storage: blobovniczatree.NewBlobovniczaTree( @@ -49,16 +48,16 @@ func TestShard_Lock(t *testing.T) { }, }), ), - shard.WithMetaBaseOptions( + WithMetaBaseOptions( meta.WithPath(filepath.Join(rootPath, "meta")), meta.WithEpochState(epochState{}), ), - shard.WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) { + WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) { sh.HandleDeletedLocks(addresses) }), } - sh = shard.New(opts...) + sh = New(opts...) require.NoError(t, sh.Open()) require.NoError(t, sh.Init(context.Background())) @@ -76,7 +75,7 @@ func TestShard_Lock(t *testing.T) { // put the object - var putPrm shard.PutPrm + var putPrm PutPrm putPrm.SetObject(obj) _, err := sh.Put(context.Background(), putPrm) @@ -94,7 +93,7 @@ func TestShard_Lock(t *testing.T) { t.Run("inhuming locked objects", func(t *testing.T) { ts := testutil.GenerateObjectWithCID(cnr) - var inhumePrm shard.InhumePrm + var inhumePrm InhumePrm inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(obj)) var objLockedErr *apistatus.ObjectLocked @@ -110,7 +109,7 @@ func TestShard_Lock(t *testing.T) { t.Run("inhuming lock objects", func(t *testing.T) { ts := testutil.GenerateObjectWithCID(cnr) - var inhumePrm shard.InhumePrm + var inhumePrm InhumePrm inhumePrm.SetTarget(objectcore.AddressOf(ts), objectcore.AddressOf(lock)) _, err = sh.Inhume(context.Background(), inhumePrm) @@ -122,7 +121,7 @@ func TestShard_Lock(t *testing.T) { }) t.Run("force objects inhuming", func(t *testing.T) { - var inhumePrm shard.InhumePrm + var inhumePrm InhumePrm inhumePrm.MarkAsGarbage(objectcore.AddressOf(lock)) inhumePrm.ForceRemoval() @@ -132,7 +131,7 @@ func TestShard_Lock(t *testing.T) { // it should be possible to remove // lock object now - inhumePrm = shard.InhumePrm{} + inhumePrm = InhumePrm{} inhumePrm.MarkAsGarbage(objectcore.AddressOf(obj)) _, err = sh.Inhume(context.Background(), inhumePrm) @@ -140,7 +139,7 @@ func TestShard_Lock(t *testing.T) { // check that object has been removed - var getPrm shard.GetPrm + var getPrm GetPrm getPrm.SetAddress(objectcore.AddressOf(obj)) _, err = sh.Get(context.Background(), getPrm) @@ -160,7 +159,7 @@ func TestShard_IsLocked(t *testing.T) { // put the object - var putPrm shard.PutPrm + var putPrm PutPrm putPrm.SetObject(obj) _, err := sh.Put(context.Background(), putPrm) diff --git a/pkg/local_object_storage/shard/metrics_test.go b/pkg/local_object_storage/shard/metrics_test.go index 280741f7b..ae993c79c 100644 --- a/pkg/local_object_storage/shard/metrics_test.go +++ b/pkg/local_object_storage/shard/metrics_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -12,7 +12,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" @@ -126,9 +125,6 @@ func (m *metricsStore) DeleteShardMetrics() { m.errCounter = 0 } -const physical = "phy" -const logical = "logic" - func TestCounters(t *testing.T) { t.Parallel() @@ -163,7 +159,7 @@ func TestCounters(t *testing.T) { totalPayload += oSize } - var prm shard.PutPrm + var prm PutPrm for i := 0; i < objNumber; i++ { prm.SetObject(oo[i]) @@ -178,7 +174,7 @@ func TestCounters(t *testing.T) { require.Equal(t, totalPayload, mm.payloadSize()) t.Run("inhume_GC", func(t *testing.T) { - var prm shard.InhumePrm + var prm InhumePrm inhumedNumber := objNumber / 4 for i := 0; i < inhumedNumber; i++ { @@ -197,7 +193,7 @@ func TestCounters(t *testing.T) { }) t.Run("inhume_TS", func(t *testing.T) { - var prm shard.InhumePrm + var prm InhumePrm ts := objectcore.AddressOf(testutil.GenerateObject()) phy := mm.getObjectCounter(physical) @@ -218,7 +214,7 @@ func TestCounters(t *testing.T) { }) t.Run("Delete", func(t *testing.T) { - var prm shard.DeletePrm + var prm DeletePrm phy := mm.getObjectCounter(physical) logic := mm.getObjectCounter(logical) @@ -244,7 +240,7 @@ func TestCounters(t *testing.T) { }) } -func shardWithMetrics(t *testing.T, path string) (*shard.Shard, *metricsStore) { +func shardWithMetrics(t *testing.T, path string) (*Shard, *metricsStore) { blobOpts := []blobstor.Option{ blobstor.WithStorages([]blobstor.SubStorage{ { @@ -264,14 +260,14 @@ func shardWithMetrics(t *testing.T, path string) (*shard.Shard, *metricsStore) { cnrSize: make(map[string]int64), } - sh := shard.New( - shard.WithID(shard.NewIDFromBytes([]byte{})), - shard.WithBlobStorOptions(blobOpts...), - shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(path, "pilorama"))), - shard.WithMetaBaseOptions( + sh := New( + WithID(NewIDFromBytes([]byte{})), + WithBlobStorOptions(blobOpts...), + WithPiloramaOptions(pilorama.WithPath(filepath.Join(path, "pilorama"))), + WithMetaBaseOptions( meta.WithPath(filepath.Join(path, "meta")), meta.WithEpochState(epochState{})), - shard.WithMetricsWriter(mm), + WithMetricsWriter(mm), ) require.NoError(t, sh.Open()) require.NoError(t, sh.Init(context.Background())) diff --git a/pkg/local_object_storage/shard/range_test.go b/pkg/local_object_storage/shard/range_test.go index 68693f769..4741e5163 100644 --- a/pkg/local_object_storage/shard/range_test.go +++ b/pkg/local_object_storage/shard/range_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -11,7 +11,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/blobovniczatree" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test" @@ -106,13 +105,13 @@ func testShardGetRange(t *testing.T, hasWriteCache bool) { addr := object.AddressOf(obj) payload := slice.Copy(obj.Payload()) - var putPrm shard.PutPrm + var putPrm PutPrm putPrm.SetObject(obj) _, err := sh.Put(context.Background(), putPrm) require.NoError(t, err) - var rngPrm shard.RngPrm + var rngPrm RngPrm rngPrm.SetAddress(addr) rngPrm.SetRange(tc.rng.GetOffset(), tc.rng.GetLength()) diff --git a/pkg/local_object_storage/shard/shard_test.go b/pkg/local_object_storage/shard/shard_test.go index 6337b0b6e..d1bfc0880 100644 --- a/pkg/local_object_storage/shard/shard_test.go +++ b/pkg/local_object_storage/shard/shard_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -11,7 +11,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor/fstree" meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebadger" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt" @@ -31,15 +30,15 @@ func (s epochState) CurrentEpoch() uint64 { return s.Value } -func newShard(t testing.TB, enableWriteCache bool) *shard.Shard { +func newShard(t testing.TB, enableWriteCache bool) *Shard { return newCustomShard(t, t.TempDir(), enableWriteCache, writecacheconfig.Options{Type: writecacheconfig.TypeBBolt}, nil, nil) } -func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts writecacheconfig.Options, bsOpts []blobstor.Option, metaOptions []meta.Option) *shard.Shard { - var sh *shard.Shard +func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts writecacheconfig.Options, bsOpts []blobstor.Option, metaOptions []meta.Option) *Shard { + var sh *Shard if enableWriteCache { rootPath = filepath.Join(rootPath, "wc") switch wcOpts.Type { @@ -78,33 +77,33 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts } } - opts := []shard.Option{ - shard.WithID(shard.NewIDFromBytes([]byte{})), - shard.WithLogger(test.NewLogger(t, true)), - shard.WithBlobStorOptions(bsOpts...), - shard.WithMetaBaseOptions( + opts := []Option{ + WithID(NewIDFromBytes([]byte{})), + WithLogger(test.NewLogger(t, true)), + WithBlobStorOptions(bsOpts...), + WithMetaBaseOptions( append([]meta.Option{ meta.WithPath(filepath.Join(rootPath, "meta")), meta.WithEpochState(epochState{})}, metaOptions...)..., ), - shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))), - shard.WithWriteCache(enableWriteCache), - shard.WithWriteCacheOptions(wcOpts), - shard.WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) { + WithPiloramaOptions(pilorama.WithPath(filepath.Join(rootPath, "pilorama"))), + WithWriteCache(enableWriteCache), + WithWriteCacheOptions(wcOpts), + WithDeletedLockCallback(func(_ context.Context, addresses []oid.Address) { sh.HandleDeletedLocks(addresses) }), - shard.WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) { + WithExpiredLocksCallback(func(ctx context.Context, epoch uint64, a []oid.Address) { sh.HandleExpiredLocks(ctx, epoch, a) }), - shard.WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool { + WithGCWorkerPoolInitializer(func(sz int) util.WorkerPool { pool, err := ants.NewPool(sz) require.NoError(t, err) return pool }), - shard.WithGCRemoverSleepInterval(100 * time.Millisecond), + WithGCRemoverSleepInterval(100 * time.Millisecond), } - sh = shard.New(opts...) + sh = New(opts...) require.NoError(t, sh.Open()) require.NoError(t, sh.Init(context.Background())) @@ -112,6 +111,6 @@ func newCustomShard(t testing.TB, rootPath string, enableWriteCache bool, wcOpts return sh } -func releaseShard(s *shard.Shard, t testing.TB) { +func releaseShard(s *Shard, t testing.TB) { require.NoError(t, s.Close()) } diff --git a/pkg/local_object_storage/shard/shutdown_test.go b/pkg/local_object_storage/shard/shutdown_test.go index 68ef90963..304448b1b 100644 --- a/pkg/local_object_storage/shard/shutdown_test.go +++ b/pkg/local_object_storage/shard/shutdown_test.go @@ -1,4 +1,4 @@ -package shard_test +package shard import ( "context" @@ -7,7 +7,6 @@ import ( "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil" - "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard" writecacheconfig "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/config" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/writecache/writecachebbolt" cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test" @@ -50,7 +49,7 @@ func TestWriteCacheObjectLoss(t *testing.T) { for i := range objects { obj := objects[i] errG.Go(func() error { - var putPrm shard.PutPrm + var putPrm PutPrm putPrm.SetObject(obj) _, err := sh.Put(context.Background(), putPrm) return err @@ -62,7 +61,7 @@ func TestWriteCacheObjectLoss(t *testing.T) { sh = newCustomShard(t, dir, true, wcOpts, nil, nil) defer releaseShard(sh, t) - var getPrm shard.GetPrm + var getPrm GetPrm for i := range objects { getPrm.SetAddress(object.AddressOf(objects[i]))