2021-09-13 08:23:58 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2021-09-13 08:23:58 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-03-07 13:38:26 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
2023-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2021-09-13 08:23:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestReset(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, db.Close()) }()
|
2021-09-13 08:23:58 +00:00
|
|
|
|
|
|
|
err := db.Reset()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
obj := testutil.GenerateObject()
|
2022-03-03 14:19:05 +00:00
|
|
|
addr := object.AddressOf(obj)
|
2021-09-13 08:23:58 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addrToInhume := oidtest.Address()
|
2021-09-13 08:23:58 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
assertExists := func(addr oid.Address, expExists bool, assertErr func(error) bool) {
|
2022-07-12 14:42:55 +00:00
|
|
|
exists, err := metaExists(db, addr)
|
2022-03-17 08:03:58 +00:00
|
|
|
if assertErr != nil {
|
|
|
|
require.True(t, assertErr(err))
|
|
|
|
} else {
|
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
2021-09-13 08:23:58 +00:00
|
|
|
require.Equal(t, expExists, exists)
|
|
|
|
}
|
|
|
|
|
|
|
|
assertExists(addr, false, nil)
|
|
|
|
assertExists(addrToInhume, false, nil)
|
|
|
|
|
|
|
|
err = putBig(db, obj)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaInhume(db, addrToInhume, oidtest.Address())
|
2021-09-13 08:23:58 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assertExists(addr, true, nil)
|
2023-08-04 11:14:07 +00:00
|
|
|
assertExists(addrToInhume, false, client.IsErrObjectAlreadyRemoved)
|
2021-09-13 08:23:58 +00:00
|
|
|
|
|
|
|
err = db.Reset()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
assertExists(addr, false, nil)
|
|
|
|
assertExists(addr, false, nil)
|
|
|
|
}
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
func metaExists(db *meta.DB, addr oid.Address) (bool, error) {
|
|
|
|
var existsPrm meta.ExistsPrm
|
2022-07-12 14:59:37 +00:00
|
|
|
existsPrm.SetAddress(addr)
|
2022-07-12 14:42:55 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
res, err := db.Exists(context.Background(), existsPrm)
|
2022-07-12 14:42:55 +00:00
|
|
|
return res.Exists(), err
|
|
|
|
}
|