2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
2020-12-03 09:31:51 +00:00
|
|
|
"errors"
|
2020-11-23 13:30:56 +00:00
|
|
|
"testing"
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2021-11-10 07:08:33 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_Exists(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("no object", func(t *testing.T) {
|
2022-03-03 14:19:05 +00:00
|
|
|
nonExist := generateObject(t)
|
|
|
|
exists, err := meta.Exists(db, object.AddressOf(nonExist))
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, exists)
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("regular object", func(t *testing.T) {
|
2022-03-03 14:19:05 +00:00
|
|
|
regular := generateObject(t)
|
|
|
|
err := putBig(db, regular)
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
exists, err := meta.Exists(db, object.AddressOf(regular))
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("tombstone object", func(t *testing.T) {
|
2022-03-03 14:19:05 +00:00
|
|
|
ts := generateObject(t)
|
2020-11-27 07:59:47 +00:00
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, ts)
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
exists, err := meta.Exists(db, object.AddressOf(ts))
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("storage group object", func(t *testing.T) {
|
2022-03-03 14:19:05 +00:00
|
|
|
sg := generateObject(t)
|
2020-11-27 07:59:47 +00:00
|
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, sg)
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
exists, err := meta.Exists(db, object.AddressOf(sg))
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
2022-02-15 12:51:56 +00:00
|
|
|
t.Run("lock object", func(t *testing.T) {
|
|
|
|
lock := generateObject(t)
|
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
|
|
|
|
err := putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
exists, err := meta.Exists(db, object.AddressOf(lock))
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
|
|
|
})
|
|
|
|
|
2020-11-27 07:59:47 +00:00
|
|
|
t.Run("virtual object", func(t *testing.T) {
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2022-03-03 14:19:05 +00:00
|
|
|
parent := generateObjectWithCID(t, cid)
|
2020-11-27 07:59:47 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
child := generateObjectWithCID(t, cid)
|
|
|
|
child.SetParent(parent)
|
2020-11-27 09:03:35 +00:00
|
|
|
child.SetParentID(parent.ID())
|
2020-11-27 07:59:47 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, child)
|
2020-11-27 07:59:47 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
_, err = meta.Exists(db, object.AddressOf(parent))
|
2020-12-03 09:31:51 +00:00
|
|
|
|
|
|
|
var expectedErr *objectSDK.SplitInfoError
|
|
|
|
require.True(t, errors.As(err, &expectedErr))
|
2020-11-27 07:59:47 +00:00
|
|
|
})
|
2020-12-04 09:01:41 +00:00
|
|
|
|
|
|
|
t.Run("merge split info", func(t *testing.T) {
|
2021-12-01 13:56:48 +00:00
|
|
|
cid := cidtest.ID()
|
2020-12-04 09:01:41 +00:00
|
|
|
splitID := objectSDK.NewSplitID()
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
parent := generateObjectWithCID(t, cid)
|
2020-12-04 09:01:41 +00:00
|
|
|
addAttribute(parent, "foo", "bar")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
child := generateObjectWithCID(t, cid)
|
|
|
|
child.SetParent(parent)
|
2020-12-04 09:01:41 +00:00
|
|
|
child.SetParentID(parent.ID())
|
|
|
|
child.SetSplitID(splitID)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
link := generateObjectWithCID(t, cid)
|
|
|
|
link.SetParent(parent)
|
2020-12-04 09:01:41 +00:00
|
|
|
link.SetParentID(parent.ID())
|
|
|
|
link.SetChildren(child.ID())
|
|
|
|
link.SetSplitID(splitID)
|
|
|
|
|
|
|
|
t.Run("direct order", func(t *testing.T) {
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, child)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, link)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
_, err = meta.Exists(db, object.AddressOf(parent))
|
2020-12-04 09:01:41 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
si, ok := err.(*objectSDK.SplitInfoError)
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
|
|
|
require.Equal(t, child.ID(), si.SplitInfo().LastPart())
|
|
|
|
require.Equal(t, link.ID(), si.SplitInfo().Link())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("reverse order", func(t *testing.T) {
|
2022-03-03 14:19:05 +00:00
|
|
|
err := meta.Put(db, link, nil)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, child)
|
2020-12-04 09:01:41 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
_, err = meta.Exists(db, object.AddressOf(parent))
|
2020-12-04 09:01:41 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
si, ok := err.(*objectSDK.SplitInfoError)
|
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
|
|
|
require.Equal(t, child.ID(), si.SplitInfo().LastPart())
|
|
|
|
require.Equal(t, link.ID(), si.SplitInfo().Link())
|
|
|
|
})
|
|
|
|
})
|
2020-11-23 13:30:56 +00:00
|
|
|
}
|