frostfs-node/pkg/local_object_storage/metabase/iterators_test.go
Aleksey Savchuk 0b7860100f
[#1421] metabase: Use LockPrm to store Lock operation parameters
Refactor `Lock` method to use `LockPrm` and `LockRes` structures
to store operation parameters and results, respectively.

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
2024-12-12 01:36:25 +03:00

73 lines
2.1 KiB
Go

package meta_test
import (
"context"
"strconv"
"testing"
object2 "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"
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/object"
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
"github.com/stretchr/testify/require"
)
func TestDB_IterateExpired(t *testing.T) {
db := newDB(t)
defer func() { require.NoError(t, db.Close(context.Background())) }()
const epoch = 13
mAlive := map[objectSDK.Type]oid.Address{}
mExpired := map[objectSDK.Type]oid.Address{}
for _, typ := range []objectSDK.Type{
objectSDK.TypeRegular,
objectSDK.TypeTombstone,
objectSDK.TypeLock,
} {
mAlive[typ] = putWithExpiration(t, db, typ, epoch)
mExpired[typ] = putWithExpiration(t, db, typ, epoch-1)
}
expiredLocked := putWithExpiration(t, db, objectSDK.TypeRegular, epoch-1)
var lockPrm meta.LockPrm
lockPrm.SetContainer(expiredLocked.Container())
lockPrm.SetTarget(oidtest.ID(), expiredLocked.Object())
_, err := db.Lock(context.Background(), lockPrm)
require.NoError(t, err)
err = db.IterateExpired(context.Background(), epoch, func(exp *meta.ExpiredObject) error {
if addr, ok := mAlive[exp.Type()]; ok {
require.NotEqual(t, addr, exp.Address())
}
require.NotEqual(t, expiredLocked, exp.Address())
addr, ok := mExpired[exp.Type()]
require.True(t, ok)
require.Equal(t, addr, exp.Address())
delete(mExpired, exp.Type())
return nil
})
require.NoError(t, err)
require.Empty(t, mExpired)
}
func putWithExpiration(t *testing.T, db *meta.DB, typ objectSDK.Type, expiresAt uint64) oid.Address {
obj := testutil.GenerateObject()
obj.SetType(typ)
testutil.AddAttribute(obj, objectV2.SysAttributeExpEpoch, strconv.FormatUint(expiresAt, 10))
require.NoError(t, putBig(db, obj))
return object2.AddressOf(obj)
}