2021-04-14 08:50:21 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/shard"
|
2021-11-10 07:08:33 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2021-04-14 08:50:21 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHeadRaw(t *testing.T) {
|
|
|
|
defer os.RemoveAll(t.Name())
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2022-03-03 14:19:05 +00:00
|
|
|
splitID := object.NewSplitID()
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
parent := generateObjectWithCID(t, cnr)
|
2021-04-14 08:50:21 +00:00
|
|
|
addAttribute(parent, "foo", "bar")
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var parentAddr oid.Address
|
|
|
|
parentAddr.SetContainer(cnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
|
|
|
|
idParent, _ := parent.ID()
|
2022-05-31 17:00:41 +00:00
|
|
|
parentAddr.SetObject(idParent)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
child := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
child.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
child.SetParentID(idParent)
|
2021-04-14 08:50:21 +00:00
|
|
|
child.SetSplitID(splitID)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
link := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
link.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
link.SetParentID(idParent)
|
|
|
|
|
|
|
|
idChild, _ := child.ID()
|
|
|
|
link.SetChildren(idChild)
|
2021-04-14 08:50:21 +00:00
|
|
|
link.SetSplitID(splitID)
|
|
|
|
|
|
|
|
t.Run("virtual object split in different shards", func(t *testing.T) {
|
|
|
|
s1 := testNewShard(t, 1)
|
|
|
|
s2 := testNewShard(t, 2)
|
|
|
|
|
|
|
|
e := testNewEngineWithShards(s1, s2)
|
|
|
|
defer e.Close()
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var putPrmLeft shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrmLeft.SetObject(child)
|
2022-05-20 18:08:59 +00:00
|
|
|
|
|
|
|
var putPrmLink shard.PutPrm
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrmLink.SetObject(link)
|
2021-04-14 08:50:21 +00:00
|
|
|
|
|
|
|
// put most left object in one shard
|
|
|
|
_, err := s1.Put(putPrmLeft)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// put link object in another shard
|
|
|
|
_, err = s2.Put(putPrmLink)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// head with raw flag should return SplitInfoError
|
2022-05-23 13:12:32 +00:00
|
|
|
var headPrm HeadPrm
|
|
|
|
headPrm.WithAddress(parentAddr)
|
|
|
|
headPrm.WithRaw(true)
|
|
|
|
|
2021-04-14 08:50:21 +00:00
|
|
|
_, err = e.Head(headPrm)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
si, ok := err.(*object.SplitInfoError)
|
2021-04-14 08:50:21 +00:00
|
|
|
require.True(t, ok)
|
|
|
|
|
|
|
|
// SplitInfoError should contain info from both shards
|
|
|
|
require.Equal(t, splitID, si.SplitInfo().SplitID())
|
2022-05-12 16:37:46 +00:00
|
|
|
|
|
|
|
id1, _ := child.ID()
|
|
|
|
id2, _ := si.SplitInfo().LastPart()
|
|
|
|
require.Equal(t, id1, id2)
|
|
|
|
|
|
|
|
id1, _ = link.ID()
|
|
|
|
id2, _ = si.SplitInfo().Link()
|
|
|
|
require.Equal(t, id1, id2)
|
2021-04-14 08:50:21 +00:00
|
|
|
})
|
|
|
|
}
|