2020-12-02 23:45:25 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
2024-04-05 12:54:36 +00:00
|
|
|
"bytes"
|
2020-12-02 23:45:25 +00:00
|
|
|
"context"
|
2023-04-21 15:21:46 +00:00
|
|
|
"crypto/ecdsa"
|
2020-12-02 23:45:25 +00:00
|
|
|
"crypto/rand"
|
2021-05-18 08:12:51 +00:00
|
|
|
"errors"
|
2020-12-02 23:45:25 +00:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/client"
|
2024-07-15 15:03:43 +00:00
|
|
|
containerCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
2023-03-07 13:38:26 +00:00
|
|
|
netmapcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/netmap"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/network"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object/util"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object_manager/placement"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
2023-08-04 11:14:07 +00:00
|
|
|
clientSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
|
|
cid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap"
|
|
|
|
netmaptest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/netmap/test"
|
|
|
|
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"
|
2024-04-05 12:54:36 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/version"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2020-12-02 23:45:25 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
type testStorage struct {
|
|
|
|
inhumed map[string]struct{}
|
|
|
|
|
|
|
|
virtual map[string]*objectSDK.SplitInfo
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
phy map[string]*objectSDK.Object
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type testTraverserGenerator struct {
|
2022-06-28 07:01:05 +00:00
|
|
|
c container.Container
|
2021-01-12 14:55:02 +00:00
|
|
|
b map[uint64]placement.Builder
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type testPlacementBuilder struct {
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors map[string][][]netmap.NodeInfo
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type testClientCache struct {
|
|
|
|
clients map[string]*testClient
|
|
|
|
}
|
|
|
|
|
|
|
|
type testClient struct {
|
|
|
|
results map[string]struct {
|
2022-03-03 14:19:05 +00:00
|
|
|
obj *objectSDK.Object
|
2020-12-02 23:45:25 +00:00
|
|
|
err error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
type testEpochReceiver uint64
|
|
|
|
|
2023-04-20 10:57:45 +00:00
|
|
|
func (e testEpochReceiver) Epoch() (uint64, error) {
|
2021-01-12 14:55:02 +00:00
|
|
|
return uint64(e), nil
|
|
|
|
}
|
2024-05-07 09:44:50 +00:00
|
|
|
|
2024-04-05 12:54:36 +00:00
|
|
|
func (e testEpochReceiver) CurrentEpoch() uint64 {
|
|
|
|
return uint64(e)
|
|
|
|
}
|
2021-01-12 14:55:02 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func newTestStorage() *testStorage {
|
|
|
|
return &testStorage{
|
|
|
|
inhumed: make(map[string]struct{}),
|
|
|
|
virtual: make(map[string]*objectSDK.SplitInfo),
|
2022-03-03 14:19:05 +00:00
|
|
|
phy: make(map[string]*objectSDK.Object),
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-15 15:03:43 +00:00
|
|
|
func (g *testTraverserGenerator) GenerateTraverser(cnr cid.ID, obj *oid.ID, e uint64) (*placement.Traverser, *containerCore.Container, error) {
|
2022-06-28 07:01:05 +00:00
|
|
|
opts := make([]placement.Option, 0, 4)
|
2022-05-31 17:00:41 +00:00
|
|
|
opts = append(opts,
|
2020-12-02 23:45:25 +00:00
|
|
|
placement.ForContainer(g.c),
|
2021-01-12 14:55:02 +00:00
|
|
|
placement.UseBuilder(g.b[e]),
|
2020-12-02 23:45:25 +00:00
|
|
|
placement.SuccessAfter(1),
|
|
|
|
)
|
2022-05-31 17:00:41 +00:00
|
|
|
|
|
|
|
if obj != nil {
|
|
|
|
opts = append(opts, placement.ForObject(*obj))
|
|
|
|
}
|
|
|
|
|
2024-07-15 15:03:43 +00:00
|
|
|
t, err := placement.NewTraverser(opts...)
|
|
|
|
return t, &containerCore.Container{
|
|
|
|
Value: g.c,
|
|
|
|
}, err
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
func (p *testPlacementBuilder) BuildPlacement(cnr cid.ID, obj *oid.ID, _ netmap.PlacementPolicy) ([][]netmap.NodeInfo, error) {
|
2022-05-31 17:00:41 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cnr)
|
|
|
|
|
|
|
|
if obj != nil {
|
|
|
|
addr.SetObject(*obj)
|
|
|
|
}
|
|
|
|
|
|
|
|
vs, ok := p.vectors[addr.EncodeToString()]
|
2020-12-02 23:45:25 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("vectors for address not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
return vs, nil
|
|
|
|
}
|
|
|
|
|
2023-04-20 10:57:45 +00:00
|
|
|
func (c *testClientCache) Get(info client.NodeInfo) (remoteStorage, error) {
|
2021-09-28 04:46:10 +00:00
|
|
|
v, ok := c.clients[network.StringifyGroup(info.AddressGroup())]
|
2020-12-02 23:45:25 +00:00
|
|
|
if !ok {
|
|
|
|
return nil, errors.New("could not construct client")
|
|
|
|
}
|
|
|
|
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func newTestClient() *testClient {
|
|
|
|
return &testClient{
|
|
|
|
results: map[string]struct {
|
2022-03-03 14:19:05 +00:00
|
|
|
obj *objectSDK.Object
|
2020-12-02 23:45:25 +00:00
|
|
|
err error
|
|
|
|
}{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 15:21:46 +00:00
|
|
|
func (c *testClient) addResult(addr oid.Address, obj *objectSDK.Object, err error) {
|
|
|
|
c.results[addr.EncodeToString()] = struct {
|
|
|
|
obj *objectSDK.Object
|
|
|
|
err error
|
|
|
|
}{obj: obj, err: err}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *testClient) Get(ctx context.Context, address oid.Address, requestParams RemoteRequestParams) (*objectSDK.Object, error) {
|
|
|
|
v, ok := c.results[address.EncodeToString()]
|
2020-12-02 23:45:25 +00:00
|
|
|
if !ok {
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.ObjectNotFound)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
if v.err != nil {
|
|
|
|
return nil, v.err
|
|
|
|
}
|
|
|
|
|
2023-04-21 15:21:46 +00:00
|
|
|
return v.obj, nil
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-21 15:21:46 +00:00
|
|
|
func (c *testClient) Head(ctx context.Context, address oid.Address, requestParams RemoteRequestParams) (*objectSDK.Object, error) {
|
|
|
|
return c.Get(ctx, address, requestParams)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *testClient) Range(ctx context.Context, address oid.Address, rng *objectSDK.Range, requestParams RemoteRequestParams) (*objectSDK.Object, error) {
|
|
|
|
obj, err := c.Get(ctx, address, requestParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return cutToRange(obj, rng), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *testClient) ForwardRequest(ctx context.Context, info client.NodeInfo, forwarder RequestForwarder) (*objectSDK.Object, error) {
|
|
|
|
return nil, fmt.Errorf("not implemented")
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-04-20 10:57:45 +00:00
|
|
|
func (s *testStorage) Get(ctx context.Context, address oid.Address) (*objectSDK.Object, error) {
|
|
|
|
return s.Range(ctx, address, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *testStorage) Head(ctx context.Context, address oid.Address, isRaw bool) (*objectSDK.Object, error) {
|
|
|
|
return s.Range(ctx, address, nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *testStorage) Range(_ context.Context, address oid.Address, rng *objectSDK.Range) (*objectSDK.Object, error) {
|
2020-12-02 23:45:25 +00:00
|
|
|
var (
|
|
|
|
ok bool
|
2022-03-03 14:19:05 +00:00
|
|
|
obj *objectSDK.Object
|
2023-04-20 10:57:45 +00:00
|
|
|
sAddr = address.EncodeToString()
|
2020-12-02 23:45:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if _, ok = s.inhumed[sAddr]; ok {
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.ObjectAlreadyRemoved)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if info, ok := s.virtual[sAddr]; ok {
|
|
|
|
return nil, objectSDK.NewSplitInfoError(info)
|
|
|
|
}
|
|
|
|
|
|
|
|
if obj, ok = s.phy[sAddr]; ok {
|
2023-04-20 10:57:45 +00:00
|
|
|
return cutToRange(obj, rng), nil
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2023-08-04 11:14:07 +00:00
|
|
|
return nil, new(apistatus.ObjectNotFound)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
func cutToRange(o *objectSDK.Object, rng *objectSDK.Range) *objectSDK.Object {
|
2020-12-07 17:49:47 +00:00
|
|
|
if rng == nil {
|
2022-03-03 14:19:05 +00:00
|
|
|
return o
|
2020-12-07 17:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
from := rng.GetOffset()
|
|
|
|
to := from + rng.GetLength()
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
payload := o.Payload()
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
o = o.CutPayload()
|
|
|
|
o.SetPayload(payload[from:to])
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
return o
|
2020-12-07 17:49:47 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (s *testStorage) addPhy(addr oid.Address, obj *objectSDK.Object) {
|
|
|
|
s.phy[addr.EncodeToString()] = obj
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (s *testStorage) addVirtual(addr oid.Address, info *objectSDK.SplitInfo) {
|
|
|
|
s.virtual[addr.EncodeToString()] = info
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (s *testStorage) inhume(addr oid.Address) {
|
|
|
|
s.inhumed[addr.EncodeToString()] = struct{}{}
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func generateObject(addr oid.Address, prev *oid.ID, payload []byte, children ...oid.ID) *objectSDK.Object {
|
2022-03-03 14:19:05 +00:00
|
|
|
obj := objectSDK.New()
|
2022-05-31 17:00:41 +00:00
|
|
|
obj.SetContainerID(addr.Container())
|
|
|
|
obj.SetID(addr.Object())
|
2020-12-02 23:45:25 +00:00
|
|
|
obj.SetPayload(payload)
|
2020-12-09 10:32:33 +00:00
|
|
|
obj.SetPayloadSize(uint64(len(payload)))
|
2022-05-12 16:37:46 +00:00
|
|
|
if prev != nil {
|
|
|
|
obj.SetPreviousID(*prev)
|
|
|
|
}
|
2020-12-02 23:45:25 +00:00
|
|
|
obj.SetChildren(children...)
|
|
|
|
|
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2023-03-08 09:56:34 +00:00
|
|
|
type writeHeaderError struct{}
|
|
|
|
|
|
|
|
func (whe *writeHeaderError) Error() string {
|
|
|
|
return "write header error"
|
|
|
|
}
|
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
type writeHeaderErrorObjectWriter struct{}
|
2023-03-08 09:56:34 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (w *writeHeaderErrorObjectWriter) WriteHeader(_ context.Context, _ *objectSDK.Object) error {
|
2023-03-08 09:56:34 +00:00
|
|
|
return &writeHeaderError{}
|
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (w *writeHeaderErrorObjectWriter) WriteChunk(_ context.Context, _ []byte) error {
|
2023-03-08 09:56:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type writePayloadError struct{}
|
|
|
|
|
|
|
|
func (whe *writePayloadError) Error() string {
|
|
|
|
return "write payload error"
|
|
|
|
}
|
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
type writePayloadErrorObjectWriter struct{}
|
2023-03-08 09:56:34 +00:00
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (w *writePayloadErrorObjectWriter) WriteHeader(_ context.Context, _ *objectSDK.Object) error {
|
2023-03-08 09:56:34 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-09 08:02:27 +00:00
|
|
|
func (w *writePayloadErrorObjectWriter) WriteChunk(_ context.Context, _ []byte) error {
|
2023-03-08 09:56:34 +00:00
|
|
|
return &writePayloadError{}
|
|
|
|
}
|
|
|
|
|
2023-10-31 11:56:55 +00:00
|
|
|
type testKeyStorage struct{}
|
2023-04-21 15:21:46 +00:00
|
|
|
|
|
|
|
func (ks *testKeyStorage) GetKey(_ *util.SessionInfo) (*ecdsa.PrivateKey, error) {
|
|
|
|
return &ecdsa.PrivateKey{}, nil
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func TestGetLocalOnly(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
newSvc := func(storage *testStorage) *Service {
|
2023-04-20 10:57:45 +00:00
|
|
|
return &Service{
|
2024-01-09 08:37:41 +00:00
|
|
|
log: test.NewLogger(t),
|
2023-04-20 10:57:45 +00:00
|
|
|
localStorage: storage,
|
|
|
|
}
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
newPrm := func(raw bool, w ObjectWriter) Prm {
|
2020-12-07 17:49:47 +00:00
|
|
|
p := Prm{}
|
|
|
|
p.SetObjectWriter(w)
|
|
|
|
p.WithRawFlag(raw)
|
|
|
|
p.common = new(util.CommonPrm).WithLocalOnly(true)
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
newRngPrm := func(raw bool, w ChunkWriter, off, ln uint64) RangePrm {
|
|
|
|
p := RangePrm{}
|
|
|
|
p.SetChunkWriter(w)
|
|
|
|
p.WithRawFlag(raw)
|
|
|
|
p.common = new(util.CommonPrm).WithLocalOnly(true)
|
|
|
|
|
|
|
|
r := objectSDK.NewRange()
|
|
|
|
r.SetOffset(off)
|
|
|
|
r.SetLength(ln)
|
|
|
|
|
|
|
|
p.SetRange(r)
|
|
|
|
|
|
|
|
return p
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
newHeadPrm := func(raw bool, w ObjectWriter) HeadPrm {
|
|
|
|
p := HeadPrm{}
|
|
|
|
p.SetHeaderWriter(w)
|
|
|
|
p.WithRawFlag(raw)
|
|
|
|
p.common = new(util.CommonPrm).WithLocalOnly(true)
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
t.Run("OK", func(t *testing.T) {
|
|
|
|
storage := newTestStorage()
|
|
|
|
svc := newSvc(storage)
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
w := NewSimpleObjectWriter()
|
2020-12-02 23:45:25 +00:00
|
|
|
p := newPrm(false, w)
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
payloadSz := uint64(10)
|
|
|
|
payload := make([]byte, payloadSz)
|
|
|
|
rand.Read(payload)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
2020-12-07 17:49:47 +00:00
|
|
|
obj := generateObject(addr, nil, payload)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
storage.addPhy(addr, obj)
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
storage.addPhy(addr, obj)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, obj, w.Object())
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
w = NewSimpleObjectWriter()
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, w, payloadSz/3, payloadSz/3)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
|
|
|
require.NoError(t, err)
|
2020-12-09 10:32:33 +00:00
|
|
|
require.Equal(t, payload[payloadSz/3:2*payloadSz/3], w.Object().Payload())
|
|
|
|
|
|
|
|
w = NewSimpleObjectWriter()
|
|
|
|
headPrm := newHeadPrm(false, w)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
|
|
|
require.NoError(t, err)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, obj.CutPayload(), w.Object())
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("INHUMED", func(t *testing.T) {
|
|
|
|
storage := newTestStorage()
|
|
|
|
svc := newSvc(storage)
|
|
|
|
|
|
|
|
p := newPrm(false, nil)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
storage.inhume(addr)
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err))
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("404", func(t *testing.T) {
|
|
|
|
storage := newTestStorage()
|
|
|
|
svc := newSvc(storage)
|
|
|
|
|
|
|
|
p := newPrm(false, nil)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
|
|
|
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("VIRTUAL", func(t *testing.T) {
|
|
|
|
storage := newTestStorage()
|
|
|
|
svc := newSvc(storage)
|
|
|
|
|
|
|
|
p := newPrm(true, nil)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
|
|
|
splitInfo.SetSplitID(objectSDK.NewSplitID())
|
2022-05-12 16:37:46 +00:00
|
|
|
splitInfo.SetLink(oidtest.ID())
|
|
|
|
splitInfo.SetLastPart(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
storage.addVirtual(addr, splitInfo)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
|
|
|
|
errSplit := objectSDK.NewSplitInfoError(objectSDK.NewSplitInfo())
|
|
|
|
|
|
|
|
require.True(t, errors.As(err, &errSplit))
|
|
|
|
|
|
|
|
require.Equal(t, splitInfo, errSplit.SplitInfo())
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(true, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Get(ctx, p)
|
|
|
|
|
|
|
|
require.True(t, errors.As(err, &errSplit))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(true, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
|
|
|
require.True(t, errors.As(err, &errSplit))
|
|
|
|
require.Equal(t, splitInfo, errSplit.SplitInfo())
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
func testNodeMatrix(t testing.TB, dim []int) ([][]netmap.NodeInfo, [][]string) {
|
|
|
|
mNodes := make([][]netmap.NodeInfo, len(dim))
|
2020-12-02 23:45:25 +00:00
|
|
|
mAddr := make([][]string, len(dim))
|
|
|
|
|
|
|
|
for i := range dim {
|
|
|
|
ns := make([]netmap.NodeInfo, dim[i])
|
|
|
|
as := make([]string, dim[i])
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for j := range dim[i] {
|
2020-12-02 23:45:25 +00:00
|
|
|
a := fmt.Sprintf("/ip4/192.168.0.%s/tcp/%s",
|
|
|
|
strconv.Itoa(i),
|
|
|
|
strconv.Itoa(60000+j),
|
|
|
|
)
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
var ni netmap.NodeInfo
|
|
|
|
ni.SetNetworkEndpoints(a)
|
2024-07-15 15:03:43 +00:00
|
|
|
ni.SetPublicKey([]byte(a))
|
2021-06-18 06:00:21 +00:00
|
|
|
|
2021-06-22 12:08:17 +00:00
|
|
|
var na network.AddressGroup
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
err := na.FromIterator(netmapcore.Node(ni))
|
2021-06-22 12:08:17 +00:00
|
|
|
require.NoError(t, err)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2021-06-22 12:08:17 +00:00
|
|
|
as[j] = network.StringifyGroup(na)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
ns[j] = ni
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-06-08 23:18:26 +00:00
|
|
|
mNodes[i] = ns
|
2020-12-02 23:45:25 +00:00
|
|
|
mAddr[i] = as
|
|
|
|
}
|
|
|
|
|
|
|
|
return mNodes, mAddr
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func generateChain(ln int, cnr cid.ID) ([]*objectSDK.Object, []oid.ID, []byte) {
|
2022-05-12 16:37:46 +00:00
|
|
|
curID := oidtest.ID()
|
2022-05-31 17:00:41 +00:00
|
|
|
var prevID *oid.ID
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(cnr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
res := make([]*objectSDK.Object, 0, ln)
|
2022-05-31 17:00:41 +00:00
|
|
|
ids := make([]oid.ID, 0, ln)
|
2020-12-02 23:45:25 +00:00
|
|
|
payload := make([]byte, 0, ln*10)
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for i := range ln {
|
2022-05-12 16:37:46 +00:00
|
|
|
ids = append(ids, curID)
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.SetObject(curID)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
payloadPart := make([]byte, 10)
|
|
|
|
rand.Read(payloadPart)
|
|
|
|
|
|
|
|
o := generateObject(addr, prevID, []byte{byte(i)})
|
|
|
|
o.SetPayload(payloadPart)
|
2020-12-07 17:49:47 +00:00
|
|
|
o.SetPayloadSize(uint64(len(payloadPart)))
|
2020-12-02 23:45:25 +00:00
|
|
|
o.SetID(curID)
|
|
|
|
|
|
|
|
payload = append(payload, payloadPart...)
|
|
|
|
|
|
|
|
res = append(res, o)
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
cpCurID := curID
|
|
|
|
prevID = &cpCurID
|
|
|
|
curID = oidtest.ID()
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return res, ids, payload
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetRemoteSmall(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2022-06-28 07:01:05 +00:00
|
|
|
var cnr container.Container
|
|
|
|
cnr.SetPlacementPolicy(netmaptest.PlacementPolicy())
|
|
|
|
|
|
|
|
var idCnr cid.ID
|
|
|
|
container.CalculateID(&idCnr, cnr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service {
|
2021-01-12 14:55:02 +00:00
|
|
|
const curEpoch = 13
|
|
|
|
|
2023-04-20 10:57:45 +00:00
|
|
|
return &Service{
|
2024-01-09 08:37:41 +00:00
|
|
|
log: test.NewLogger(t),
|
2023-04-20 10:57:45 +00:00
|
|
|
localStorage: newTestStorage(),
|
|
|
|
traverserGenerator: &testTraverserGenerator{
|
|
|
|
c: cnr,
|
|
|
|
b: map[uint64]placement.Builder{
|
|
|
|
curEpoch: b,
|
|
|
|
},
|
2021-01-12 14:55:02 +00:00
|
|
|
},
|
2023-04-20 10:57:45 +00:00
|
|
|
epochSource: testEpochReceiver(curEpoch),
|
|
|
|
remoteStorageConstructor: c,
|
2023-04-21 15:21:46 +00:00
|
|
|
keyStore: &testKeyStorage{},
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newPrm := func(raw bool, w ObjectWriter) Prm {
|
2020-12-07 17:49:47 +00:00
|
|
|
p := Prm{}
|
|
|
|
p.SetObjectWriter(w)
|
|
|
|
p.WithRawFlag(raw)
|
|
|
|
p.common = new(util.CommonPrm).WithLocalOnly(false)
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
newHeadPrm := func(raw bool, w ObjectWriter) HeadPrm {
|
|
|
|
p := HeadPrm{}
|
|
|
|
p.SetHeaderWriter(w)
|
|
|
|
p.WithRawFlag(raw)
|
|
|
|
p.common = new(util.CommonPrm).WithLocalOnly(false)
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
t.Run("OK", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.EncodeToString(): ns,
|
2020-12-02 23:45:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
payloadSz := uint64(10)
|
|
|
|
payload := make([]byte, payloadSz)
|
|
|
|
rand.Read(payload)
|
|
|
|
|
|
|
|
obj := generateObject(addr, nil, payload)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, obj, nil)
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
w := NewSimpleObjectWriter()
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
p := newPrm(false, w)
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
require.NoError(t, err)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, obj, w.Object())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
*c1, *c2 = *c2, *c1
|
|
|
|
|
|
|
|
err = svc.Get(ctx, p)
|
|
|
|
require.NoError(t, err)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, obj, w.Object())
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
w = NewSimpleObjectWriter()
|
2020-12-07 17:49:47 +00:00
|
|
|
rngPrm := newRngPrm(false, w, payloadSz/3, payloadSz/3)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
|
|
|
require.NoError(t, err)
|
2020-12-09 10:32:33 +00:00
|
|
|
require.Equal(t, payload[payloadSz/3:2*payloadSz/3], w.Object().Payload())
|
|
|
|
|
|
|
|
w = NewSimpleObjectWriter()
|
|
|
|
headPrm := newHeadPrm(false, w)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
|
|
|
require.NoError(t, err)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, obj.CutPayload(), w.Object())
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("INHUMED", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.EncodeToString(): ns,
|
2020-12-02 23:45:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
2022-03-17 08:03:58 +00:00
|
|
|
c2.addResult(addr, nil, new(apistatus.ObjectAlreadyRemoved))
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
p := newPrm(false, nil)
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectAlreadyRemoved(err))
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("404", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.EncodeToString(): ns,
|
2020-12-02 23:45:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
p := newPrm(false, nil)
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("VIRTUAL", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
testHeadVirtual := func(svc *Service, addr oid.Address, i *objectSDK.SplitInfo) {
|
2024-08-06 06:32:40 +00:00
|
|
|
headPrm := newHeadPrm(true, nil)
|
2020-12-09 10:32:33 +00:00
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
errSplit := objectSDK.NewSplitInfoError(objectSDK.NewSplitInfo())
|
|
|
|
|
|
|
|
err := svc.Head(ctx, headPrm)
|
|
|
|
require.True(t, errors.As(err, &errSplit))
|
|
|
|
require.Equal(t, i, errSplit.SplitInfo())
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
t.Run("linking", func(t *testing.T) {
|
|
|
|
t.Run("get linking failure", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
2022-05-12 16:37:46 +00:00
|
|
|
splitInfo.SetLink(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var splitAddr oid.Address
|
|
|
|
splitAddr.SetContainer(idCnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
idLink, _ := splitInfo.Link()
|
2022-05-31 17:00:41 +00:00
|
|
|
splitAddr.SetObject(idLink)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
2023-08-04 11:14:07 +00:00
|
|
|
c1.addResult(splitAddr, nil, new(apistatus.ObjectNotFound))
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
2023-08-04 11:14:07 +00:00
|
|
|
c2.addResult(splitAddr, nil, new(apistatus.ObjectNotFound))
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
splitAddr.EncodeToString(): ns,
|
2020-12-02 23:45:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
p := newPrm(false, nil)
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get chain element failure", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
2020-12-07 17:49:47 +00:00
|
|
|
srcObj.SetPayloadSize(10)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
2022-05-12 16:37:46 +00:00
|
|
|
splitInfo.SetLink(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
children, childIDs, _ := generateChain(2, idCnr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var linkAddr oid.Address
|
|
|
|
linkAddr.SetContainer(idCnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
idLink, _ := splitInfo.Link()
|
2022-05-31 17:00:41 +00:00
|
|
|
linkAddr.SetObject(idLink)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
2022-05-31 17:00:41 +00:00
|
|
|
linkingObj.SetParentID(addr.Object())
|
2022-03-03 14:19:05 +00:00
|
|
|
linkingObj.SetParent(srcObj)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var child1Addr oid.Address
|
|
|
|
child1Addr.SetContainer(idCnr)
|
|
|
|
child1Addr.SetObject(childIDs[0])
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var child2Addr oid.Address
|
|
|
|
child2Addr.SetContainer(idCnr)
|
|
|
|
child2Addr.SetObject(childIDs[1])
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(linkAddr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child1Addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child2Addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
c2.addResult(linkAddr, linkingObj, nil)
|
|
|
|
c2.addResult(child1Addr, children[0], nil)
|
2023-08-04 11:14:07 +00:00
|
|
|
c2.addResult(child2Addr, nil, new(apistatus.ObjectNotFound))
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
linkAddr.EncodeToString(): ns,
|
|
|
|
child1Addr.EncodeToString(): ns,
|
|
|
|
child2Addr.EncodeToString(): ns,
|
2020-12-02 23:45:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
|
|
|
p := newPrm(false, NewSimpleObjectWriter())
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
rngPrm := newRngPrm(false, NewSimpleObjectWriter(), 0, 1)
|
2020-12-07 17:49:47 +00:00
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("OK", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
2022-05-12 16:37:46 +00:00
|
|
|
splitInfo.SetLink(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
children, childIDs, payload := generateChain(2, idCnr)
|
2020-12-02 23:45:25 +00:00
|
|
|
srcObj.SetPayload(payload)
|
2020-12-07 17:49:47 +00:00
|
|
|
srcObj.SetPayloadSize(uint64(len(payload)))
|
2022-03-03 14:19:05 +00:00
|
|
|
children[len(children)-1].SetParent(srcObj)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var linkAddr oid.Address
|
|
|
|
linkAddr.SetContainer(idCnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
idLink, _ := splitInfo.Link()
|
2022-05-31 17:00:41 +00:00
|
|
|
linkAddr.SetObject(idLink)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
2022-05-31 17:00:41 +00:00
|
|
|
linkingObj.SetParentID(addr.Object())
|
2022-03-03 14:19:05 +00:00
|
|
|
linkingObj.SetParent(srcObj)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var child1Addr oid.Address
|
|
|
|
child1Addr.SetContainer(idCnr)
|
|
|
|
child1Addr.SetObject(childIDs[0])
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var child2Addr oid.Address
|
|
|
|
child2Addr.SetContainer(idCnr)
|
|
|
|
child2Addr.SetObject(childIDs[1])
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(linkAddr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child1Addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child2Addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
c2.addResult(linkAddr, linkingObj, nil)
|
|
|
|
c2.addResult(child1Addr, children[0], nil)
|
|
|
|
c2.addResult(child2Addr, children[1], nil)
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
linkAddr.EncodeToString(): ns,
|
|
|
|
child1Addr.EncodeToString(): ns,
|
|
|
|
child2Addr.EncodeToString(): ns,
|
2020-12-02 23:45:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
|
|
|
w := NewSimpleObjectWriter()
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
p := newPrm(false, w)
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
require.NoError(t, err)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, srcObj, w.Object())
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
w = NewSimpleObjectWriter()
|
2020-12-07 17:49:47 +00:00
|
|
|
payloadSz := srcObj.PayloadSize()
|
|
|
|
|
|
|
|
off := payloadSz / 3
|
|
|
|
ln := payloadSz / 3
|
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, w, off, ln)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
|
|
|
require.NoError(t, err)
|
2020-12-09 10:32:33 +00:00
|
|
|
require.Equal(t, payload[off:off+ln], w.Object().Payload())
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
2023-03-08 09:56:34 +00:00
|
|
|
|
|
|
|
t.Run("write header/payload failure", func(t *testing.T) {
|
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
|
|
|
splitInfo.SetLink(oidtest.ID())
|
|
|
|
|
|
|
|
children, childIDs, payload := generateChain(2, idCnr)
|
|
|
|
srcObj.SetPayload(payload)
|
|
|
|
srcObj.SetPayloadSize(uint64(len(payload)))
|
|
|
|
children[len(children)-1].SetParent(srcObj)
|
|
|
|
|
|
|
|
var linkAddr oid.Address
|
|
|
|
linkAddr.SetContainer(idCnr)
|
|
|
|
idLink, _ := splitInfo.Link()
|
|
|
|
linkAddr.SetObject(idLink)
|
|
|
|
|
|
|
|
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
|
|
|
linkingObj.SetParentID(addr.Object())
|
|
|
|
linkingObj.SetParent(srcObj)
|
|
|
|
|
|
|
|
var child1Addr oid.Address
|
|
|
|
child1Addr.SetContainer(idCnr)
|
|
|
|
child1Addr.SetObject(childIDs[0])
|
|
|
|
|
|
|
|
var child2Addr oid.Address
|
|
|
|
child2Addr.SetContainer(idCnr)
|
|
|
|
child2Addr.SetObject(childIDs[1])
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(linkAddr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child1Addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child2Addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
c2.addResult(linkAddr, linkingObj, nil)
|
|
|
|
c2.addResult(child1Addr, children[0], nil)
|
|
|
|
c2.addResult(child2Addr, children[1], nil)
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
linkAddr.EncodeToString(): ns,
|
|
|
|
child1Addr.EncodeToString(): ns,
|
|
|
|
child2Addr.EncodeToString(): ns,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
|
|
|
wh := &writeHeaderErrorObjectWriter{}
|
|
|
|
|
|
|
|
p := newPrm(false, wh)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
require.ErrorAs(t, err, new(*writeHeaderError))
|
|
|
|
|
|
|
|
wp := &writePayloadErrorObjectWriter{}
|
|
|
|
|
|
|
|
p = newPrm(false, wp)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Get(ctx, p)
|
|
|
|
require.ErrorAs(t, err, new(*writePayloadError))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("linked object not a child of parent", func(t *testing.T) {
|
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
|
|
|
splitInfo.SetLink(oidtest.ID())
|
|
|
|
|
|
|
|
children, childIDs, payload := generateChain(2, idCnr)
|
|
|
|
srcObj.SetPayload(payload)
|
|
|
|
srcObj.SetPayloadSize(uint64(len(payload)))
|
|
|
|
children[len(children)-1].SetParent(srcObj)
|
|
|
|
|
|
|
|
var linkAddr oid.Address
|
|
|
|
linkAddr.SetContainer(idCnr)
|
|
|
|
idLink, _ := splitInfo.Link()
|
|
|
|
linkAddr.SetObject(idLink)
|
|
|
|
|
|
|
|
wrongParentAddr := oidtest.Address()
|
|
|
|
wrongParentID := oidtest.ID()
|
|
|
|
wrongParentAddr.SetObject(wrongParentID)
|
|
|
|
wrongParentAddr.SetContainer(idCnr)
|
|
|
|
wrongParent := generateObject(wrongParentAddr, nil, nil)
|
|
|
|
|
|
|
|
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
|
|
|
linkingObj.SetParentID(wrongParentID)
|
|
|
|
linkingObj.SetParent(wrongParent)
|
|
|
|
|
|
|
|
var child1Addr oid.Address
|
|
|
|
child1Addr.SetContainer(idCnr)
|
|
|
|
child1Addr.SetObject(childIDs[0])
|
|
|
|
|
|
|
|
var child2Addr oid.Address
|
|
|
|
child2Addr.SetContainer(idCnr)
|
|
|
|
child2Addr.SetObject(childIDs[1])
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(linkAddr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child1Addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child2Addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
c2.addResult(linkAddr, linkingObj, nil)
|
|
|
|
c2.addResult(child1Addr, children[0], nil)
|
|
|
|
c2.addResult(child2Addr, children[1], nil)
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
linkAddr.EncodeToString(): ns,
|
|
|
|
child1Addr.EncodeToString(): ns,
|
|
|
|
child2Addr.EncodeToString(): ns,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
p := newPrm(false, w)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-03-09 08:02:27 +00:00
|
|
|
require.ErrorIs(t, err, errParentAddressDiffers)
|
2023-03-08 09:56:34 +00:00
|
|
|
|
|
|
|
w = NewSimpleObjectWriter()
|
|
|
|
payloadSz := srcObj.PayloadSize()
|
|
|
|
|
|
|
|
off := payloadSz / 3
|
|
|
|
ln := payloadSz / 3
|
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, w, off, ln)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-03-09 08:02:27 +00:00
|
|
|
require.ErrorIs(t, err, errParentAddressDiffers)
|
2023-03-08 09:56:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("linked object with parent udefined", func(t *testing.T) {
|
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
|
|
|
splitInfo.SetLink(oidtest.ID())
|
|
|
|
|
|
|
|
children, childIDs, payload := generateChain(2, idCnr)
|
|
|
|
srcObj.SetPayload(payload)
|
|
|
|
srcObj.SetPayloadSize(uint64(len(payload)))
|
|
|
|
children[len(children)-1].SetParent(srcObj)
|
|
|
|
|
|
|
|
var linkAddr oid.Address
|
|
|
|
linkAddr.SetContainer(idCnr)
|
|
|
|
idLink, _ := splitInfo.Link()
|
|
|
|
linkAddr.SetObject(idLink)
|
|
|
|
|
|
|
|
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
|
|
|
|
|
|
|
var child1Addr oid.Address
|
|
|
|
child1Addr.SetContainer(idCnr)
|
|
|
|
child1Addr.SetObject(childIDs[0])
|
|
|
|
|
|
|
|
var child2Addr oid.Address
|
|
|
|
child2Addr.SetContainer(idCnr)
|
|
|
|
child2Addr.SetObject(childIDs[1])
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(linkAddr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child1Addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child2Addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
c2.addResult(linkAddr, linkingObj, nil)
|
|
|
|
c2.addResult(child1Addr, children[0], nil)
|
|
|
|
c2.addResult(child2Addr, children[1], nil)
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
linkAddr.EncodeToString(): ns,
|
|
|
|
child1Addr.EncodeToString(): ns,
|
|
|
|
child2Addr.EncodeToString(): ns,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
p := newPrm(false, w)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-03-09 06:54:12 +00:00
|
|
|
require.Error(t, err)
|
2023-04-24 09:09:43 +00:00
|
|
|
require.ErrorIs(t, err, errChildWithEmptyParent)
|
2023-03-08 09:56:34 +00:00
|
|
|
|
|
|
|
w = NewSimpleObjectWriter()
|
|
|
|
payloadSz := srcObj.PayloadSize()
|
|
|
|
|
|
|
|
off := payloadSz / 3
|
|
|
|
ln := payloadSz / 3
|
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, w, off, ln)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-03-09 06:54:12 +00:00
|
|
|
require.Error(t, err)
|
2023-04-24 09:09:43 +00:00
|
|
|
require.ErrorIs(t, err, errChildWithEmptyParent)
|
2023-03-08 09:56:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("out of range", func(t *testing.T) {
|
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
|
|
|
splitInfo.SetLink(oidtest.ID())
|
|
|
|
|
|
|
|
children, childIDs, payload := generateChain(2, idCnr)
|
|
|
|
srcObj.SetPayload(payload)
|
|
|
|
srcObj.SetPayloadSize(uint64(len(payload)))
|
|
|
|
children[len(children)-1].SetParent(srcObj)
|
|
|
|
|
|
|
|
var linkAddr oid.Address
|
|
|
|
linkAddr.SetContainer(idCnr)
|
|
|
|
idLink, _ := splitInfo.Link()
|
|
|
|
linkAddr.SetObject(idLink)
|
|
|
|
|
|
|
|
linkingObj := generateObject(linkAddr, nil, nil, childIDs...)
|
|
|
|
linkingObj.SetParentID(addr.Object())
|
|
|
|
linkingObj.SetParent(srcObj)
|
|
|
|
|
|
|
|
var child1Addr oid.Address
|
|
|
|
child1Addr.SetContainer(idCnr)
|
|
|
|
child1Addr.SetObject(childIDs[0])
|
|
|
|
|
|
|
|
var child2Addr oid.Address
|
|
|
|
child2Addr.SetContainer(idCnr)
|
|
|
|
child2Addr.SetObject(childIDs[1])
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(linkAddr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child1Addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(child2Addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
c2.addResult(linkAddr, linkingObj, nil)
|
|
|
|
c2.addResult(child1Addr, children[0], nil)
|
|
|
|
c2.addResult(child2Addr, children[1], nil)
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
linkAddr.EncodeToString(): ns,
|
|
|
|
child1Addr.EncodeToString(): ns,
|
|
|
|
child2Addr.EncodeToString(): ns,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
p := newRngPrm(false, w, uint64(len(payload)), uint64(len(payload)))
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.GetRange(ctx, p)
|
|
|
|
require.ErrorAs(t, err, new(*apistatus.ObjectOutOfRange))
|
|
|
|
})
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("right child", func(t *testing.T) {
|
|
|
|
t.Run("get right child failure", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
2022-05-12 16:37:46 +00:00
|
|
|
splitInfo.SetLastPart(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var splitAddr oid.Address
|
|
|
|
splitAddr.SetContainer(idCnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
idLast, _ := splitInfo.LastPart()
|
2022-05-31 17:00:41 +00:00
|
|
|
splitAddr.SetObject(idLast)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
2023-08-04 11:14:07 +00:00
|
|
|
c1.addResult(splitAddr, nil, new(apistatus.ObjectNotFound))
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
2023-08-04 11:14:07 +00:00
|
|
|
c2.addResult(splitAddr, nil, new(apistatus.ObjectNotFound))
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
splitAddr.EncodeToString(): ns,
|
2020-12-02 23:45:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
p := newPrm(false, nil)
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get chain element failure", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
2022-11-24 15:27:00 +00:00
|
|
|
srcObj.SetPayloadSize(11)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
2022-05-12 16:37:46 +00:00
|
|
|
splitInfo.SetLastPart(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
children, _, _ := generateChain(2, idCnr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var rightAddr oid.Address
|
|
|
|
rightAddr.SetContainer(idCnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
idLast, _ := splitInfo.LastPart()
|
2022-05-31 17:00:41 +00:00
|
|
|
rightAddr.SetObject(idLast)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
rightObj := children[len(children)-1]
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
rightObj.SetParentID(addr.Object())
|
2022-03-03 14:19:05 +00:00
|
|
|
rightObj.SetParent(srcObj)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
preRightAddr := object.AddressOf(children[len(children)-2])
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
c1.addResult(rightAddr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
c2.addResult(rightAddr, rightObj, nil)
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
2022-05-31 17:00:41 +00:00
|
|
|
addr.EncodeToString(): ns,
|
|
|
|
rightAddr.EncodeToString(): ns,
|
|
|
|
preRightAddr.EncodeToString(): ns,
|
2020-12-02 23:45:25 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
headSvc := newTestClient()
|
2023-08-04 11:14:07 +00:00
|
|
|
headSvc.addResult(preRightAddr, nil, new(apistatus.ObjectNotFound))
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
p := newPrm(false, NewSimpleObjectWriter())
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 1)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
|
2023-03-08 09:56:34 +00:00
|
|
|
t.Run("child has different parent", func(t *testing.T) {
|
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
|
|
|
splitInfo.SetLastPart(oidtest.ID())
|
|
|
|
|
|
|
|
children, _, payload := generateChain(2, idCnr)
|
|
|
|
srcObj.SetPayloadSize(uint64(len(payload)))
|
|
|
|
srcObj.SetPayload(payload)
|
|
|
|
|
|
|
|
wrongParentAddr := oidtest.Address()
|
|
|
|
wrongParentID := oidtest.ID()
|
|
|
|
wrongParentAddr.SetObject(wrongParentID)
|
|
|
|
wrongParentAddr.SetContainer(idCnr)
|
|
|
|
wrongParent := generateObject(wrongParentAddr, nil, nil)
|
|
|
|
|
|
|
|
rightObj := children[len(children)-1]
|
|
|
|
|
|
|
|
idLast, _ := splitInfo.LastPart()
|
|
|
|
rightObj.SetID(idLast)
|
|
|
|
rightObj.SetParentID(addr.Object())
|
|
|
|
rightObj.SetParent(srcObj)
|
|
|
|
|
|
|
|
firstObj := children[0]
|
|
|
|
firstObj.SetParent(wrongParent)
|
|
|
|
firstObj.SetParentID(wrongParentID)
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
for i := range children {
|
|
|
|
c1.addResult(object.AddressOf(children[i]), nil, errors.New("any error"))
|
|
|
|
}
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
|
|
|
|
for i := range children {
|
|
|
|
c2.addResult(object.AddressOf(children[i]), children[i], nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
|
|
|
vectors: map[string][][]netmap.NodeInfo{},
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.vectors[addr.EncodeToString()] = ns
|
|
|
|
|
|
|
|
for i := range children {
|
|
|
|
builder.vectors[object.AddressOf(children[i]).EncodeToString()] = ns
|
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
p := newPrm(false, w)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-03-09 08:02:27 +00:00
|
|
|
require.ErrorIs(t, err, errParentAddressDiffers)
|
2023-03-08 09:56:34 +00:00
|
|
|
|
|
|
|
w = NewSimpleObjectWriter()
|
|
|
|
payloadSz := srcObj.PayloadSize()
|
|
|
|
|
|
|
|
off := payloadSz / 3
|
|
|
|
ln := payloadSz / 3
|
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, w, off, ln)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2023-03-09 08:02:27 +00:00
|
|
|
require.ErrorIs(t, err, errParentAddressDiffers)
|
2023-03-08 09:56:34 +00:00
|
|
|
})
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
t.Run("OK", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
srcObj := generateObject(addr, nil, nil)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
2022-05-12 16:37:46 +00:00
|
|
|
splitInfo.SetLastPart(oidtest.ID())
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
children, _, payload := generateChain(2, idCnr)
|
2020-12-07 17:49:47 +00:00
|
|
|
srcObj.SetPayloadSize(uint64(len(payload)))
|
2020-12-02 23:45:25 +00:00
|
|
|
srcObj.SetPayload(payload)
|
|
|
|
|
|
|
|
rightObj := children[len(children)-1]
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
idLast, _ := splitInfo.LastPart()
|
|
|
|
rightObj.SetID(idLast)
|
2022-05-31 17:00:41 +00:00
|
|
|
rightObj.SetParentID(addr.Object())
|
2022-03-03 14:19:05 +00:00
|
|
|
rightObj.SetParent(srcObj)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
for i := range children {
|
2022-03-03 14:19:05 +00:00
|
|
|
c1.addResult(object.AddressOf(children[i]), nil, errors.New("any error"))
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
|
|
|
|
for i := range children {
|
2022-03-03 14:19:05 +00:00
|
|
|
c2.addResult(object.AddressOf(children[i]), children[i], nil)
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
2022-06-08 23:18:26 +00:00
|
|
|
vectors: map[string][][]netmap.NodeInfo{},
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
builder.vectors[addr.EncodeToString()] = ns
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
for i := range children {
|
2022-05-31 17:00:41 +00:00
|
|
|
builder.vectors[object.AddressOf(children[i]).EncodeToString()] = ns
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
w := NewSimpleObjectWriter()
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
p := newPrm(false, w)
|
2020-12-07 17:49:47 +00:00
|
|
|
p.WithAddress(addr)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
require.NoError(t, err)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, srcObj, w.Object())
|
2020-12-07 17:49:47 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
w = NewSimpleObjectWriter()
|
2020-12-07 17:49:47 +00:00
|
|
|
payloadSz := srcObj.PayloadSize()
|
|
|
|
|
|
|
|
off := payloadSz / 3
|
|
|
|
ln := payloadSz / 3
|
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, w, off, ln)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
|
|
|
require.NoError(t, err)
|
2020-12-09 10:32:33 +00:00
|
|
|
require.Equal(t, payload[off:off+ln], w.Object().Payload())
|
2020-12-08 15:02:07 +00:00
|
|
|
|
2020-12-09 10:32:33 +00:00
|
|
|
w = NewSimpleObjectWriter()
|
2020-12-08 15:02:07 +00:00
|
|
|
off = payloadSz - 2
|
|
|
|
ln = 1
|
|
|
|
|
|
|
|
rngPrm = newRngPrm(false, w, off, ln)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
|
|
|
require.NoError(t, err)
|
2020-12-09 10:32:33 +00:00
|
|
|
require.Equal(t, payload[off:off+ln], w.Object().Payload())
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
})
|
2023-03-08 09:56:34 +00:00
|
|
|
|
|
|
|
t.Run("corrupted source object", func(t *testing.T) {
|
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(oidtest.ID())
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
splitInfo := objectSDK.NewSplitInfo()
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{
|
|
|
|
vectors: map[string][][]netmap.NodeInfo{},
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.vectors[addr.EncodeToString()] = ns
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c2,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
testHeadVirtual(svc, addr, splitInfo)
|
|
|
|
|
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
p := newPrm(false, w)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
|
|
|
require.ErrorAs(t, err, new(*objectSDK.SplitInfoError))
|
|
|
|
})
|
2020-12-02 23:45:25 +00:00
|
|
|
})
|
|
|
|
}
|
2021-01-12 14:55:02 +00:00
|
|
|
|
2024-04-05 12:54:36 +00:00
|
|
|
type testTarget struct {
|
|
|
|
objects []*objectSDK.Object
|
|
|
|
}
|
|
|
|
|
|
|
|
func (tt *testTarget) WriteObject(_ context.Context, obj *objectSDK.Object) error {
|
|
|
|
tt.objects = append(tt.objects, obj)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func objectChain(t *testing.T, cnr cid.ID, singleSize, totalSize uint64) (oid.ID, []*objectSDK.Object, *objectSDK.Object, []byte) {
|
|
|
|
pk, err := keys.NewPrivateKey()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
tt := new(testTarget)
|
|
|
|
p := transformer.NewPayloadSizeLimiter(transformer.Params{
|
|
|
|
Key: &pk.PrivateKey,
|
|
|
|
NextTargetInit: func() transformer.ObjectWriter { return tt },
|
|
|
|
NetworkState: testEpochReceiver(1),
|
|
|
|
MaxSize: singleSize,
|
|
|
|
})
|
|
|
|
|
|
|
|
payload := make([]byte, totalSize)
|
|
|
|
_, err = rand.Read(payload)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
ver := version.Current()
|
|
|
|
hdr := objectSDK.New()
|
|
|
|
hdr.SetContainerID(cnr)
|
|
|
|
hdr.SetType(objectSDK.TypeRegular)
|
|
|
|
hdr.SetVersion(&ver)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
require.NoError(t, p.WriteHeader(ctx, hdr))
|
|
|
|
|
|
|
|
_, err = p.Write(ctx, payload)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
res, err := p.Close(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
if totalSize <= singleSize {
|
|
|
|
// Small object, no linking.
|
|
|
|
require.Len(t, tt.objects, 1)
|
|
|
|
return res.SelfID, tt.objects, nil, payload
|
|
|
|
}
|
|
|
|
|
|
|
|
return *res.ParentID, tt.objects[:len(tt.objects)-1], tt.objects[len(tt.objects)-1], bytes.Clone(payload)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newRngPrm(raw bool, w ChunkWriter, off, ln uint64) RangePrm {
|
|
|
|
p := RangePrm{}
|
|
|
|
p.SetChunkWriter(w)
|
|
|
|
p.WithRawFlag(raw)
|
|
|
|
p.common = new(util.CommonPrm)
|
|
|
|
|
|
|
|
r := objectSDK.NewRange()
|
|
|
|
r.SetOffset(off)
|
|
|
|
r.SetLength(ln)
|
|
|
|
|
|
|
|
p.SetRange(r)
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetRange(t *testing.T) {
|
|
|
|
var cnr container.Container
|
|
|
|
cnr.SetPlacementPolicy(netmaptest.PlacementPolicy())
|
|
|
|
|
|
|
|
var idCnr cid.ID
|
|
|
|
container.CalculateID(&idCnr, cnr)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2})
|
|
|
|
|
|
|
|
testGetRange := func(t *testing.T, svc *Service, addr oid.Address, from, to uint64, payload []byte) {
|
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
rngPrm := newRngPrm(false, w, from, to-from)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.GetRange(context.Background(), rngPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
if from == to {
|
|
|
|
require.Nil(t, w.Object().Payload())
|
|
|
|
} else {
|
|
|
|
require.Equal(t, payload[from:to], w.Object().Payload())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newSvc := func(b *testPlacementBuilder, c *testClientCache) *Service {
|
|
|
|
const curEpoch = 13
|
|
|
|
|
|
|
|
return &Service{
|
|
|
|
log: test.NewLogger(t),
|
|
|
|
localStorage: newTestStorage(),
|
|
|
|
traverserGenerator: &testTraverserGenerator{
|
|
|
|
c: cnr,
|
|
|
|
b: map[uint64]placement.Builder{
|
|
|
|
curEpoch: b,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
epochSource: testEpochReceiver(curEpoch),
|
|
|
|
remoteStorageConstructor: c,
|
|
|
|
keyStore: &testKeyStorage{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("small", func(t *testing.T) {
|
|
|
|
const totalSize = 5
|
|
|
|
_, objs, _, payload := objectChain(t, idCnr, totalSize, totalSize)
|
|
|
|
require.Len(t, objs, 1)
|
|
|
|
require.Len(t, payload, totalSize)
|
|
|
|
|
|
|
|
obj := objs[0]
|
|
|
|
addr := object.AddressOf(obj)
|
|
|
|
builder := &testPlacementBuilder{vectors: map[string][][]netmap.NodeInfo{addr.EncodeToString(): ns}}
|
|
|
|
|
|
|
|
c1 := newTestClient()
|
|
|
|
c1.addResult(addr, obj, nil)
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for from := range totalSize - 1 {
|
2024-04-05 12:54:36 +00:00
|
|
|
for to := from; to < totalSize; to++ {
|
|
|
|
t.Run(fmt.Sprintf("from=%d,to=%d", from, to), func(t *testing.T) {
|
|
|
|
testGetRange(t, svc, addr, uint64(from), uint64(to), payload)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("big", func(t *testing.T) {
|
|
|
|
const totalSize = 9
|
|
|
|
id, objs, link, payload := objectChain(t, idCnr, 3, totalSize) // 3 parts
|
|
|
|
require.Equal(t, totalSize, len(payload))
|
|
|
|
|
|
|
|
builder := &testPlacementBuilder{vectors: map[string][][]netmap.NodeInfo{}}
|
|
|
|
builder.vectors[idCnr.EncodeToString()+"/"+id.EncodeToString()] = ns
|
|
|
|
builder.vectors[object.AddressOf(link).EncodeToString()] = ns
|
|
|
|
for i := range objs {
|
|
|
|
builder.vectors[object.AddressOf(objs[i]).EncodeToString()] = ns
|
|
|
|
}
|
|
|
|
|
|
|
|
var addr oid.Address
|
|
|
|
addr.SetContainer(idCnr)
|
|
|
|
addr.SetObject(id)
|
|
|
|
|
|
|
|
const (
|
|
|
|
linkingLast = "splitinfo=last"
|
|
|
|
linkingChildren = "splitinfo=children"
|
|
|
|
linkingBoth = "splitinfo=both"
|
|
|
|
)
|
|
|
|
|
|
|
|
lastID, _ := objs[len(objs)-1].ID()
|
|
|
|
linkID, _ := link.ID()
|
|
|
|
|
|
|
|
for _, kind := range []string{linkingLast, linkingChildren, linkingBoth} {
|
|
|
|
t.Run(kind, func(t *testing.T) {
|
|
|
|
c1 := newTestClient()
|
|
|
|
for i := range objs {
|
|
|
|
c1.addResult(object.AddressOf(objs[i]), objs[i], nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
c1.addResult(object.AddressOf(link), link, nil)
|
|
|
|
|
|
|
|
si := objectSDK.NewSplitInfo()
|
|
|
|
switch kind {
|
|
|
|
case linkingLast:
|
|
|
|
si.SetLastPart(lastID)
|
|
|
|
case linkingChildren:
|
|
|
|
si.SetLink(linkID)
|
|
|
|
case linkingBoth:
|
|
|
|
si.SetLastPart(lastID)
|
|
|
|
si.SetLink(linkID)
|
|
|
|
}
|
|
|
|
c1.addResult(addr, nil, objectSDK.NewSplitInfoError(si))
|
|
|
|
|
|
|
|
svc := newSvc(builder, &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c1,
|
|
|
|
as[0][1]: c1,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2024-08-30 16:20:55 +00:00
|
|
|
for from := range totalSize - 1 {
|
2024-04-05 12:54:36 +00:00
|
|
|
for to := from; to < totalSize; to++ {
|
|
|
|
t.Run(fmt.Sprintf("from=%d,to=%d", from, to), func(t *testing.T) {
|
|
|
|
testGetRange(t, svc, addr, uint64(from), uint64(to), payload)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-12 14:55:02 +00:00
|
|
|
func TestGetFromPastEpoch(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2022-06-28 07:01:05 +00:00
|
|
|
var cnr container.Container
|
|
|
|
cnr.SetPlacementPolicy(netmaptest.PlacementPolicy())
|
|
|
|
|
|
|
|
var idCnr cid.ID
|
|
|
|
container.CalculateID(&idCnr, cnr)
|
2021-01-12 14:55:02 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
addr := oidtest.Address()
|
|
|
|
addr.SetContainer(idCnr)
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
payloadSz := uint64(10)
|
|
|
|
payload := make([]byte, payloadSz)
|
|
|
|
_, _ = rand.Read(payload)
|
|
|
|
|
|
|
|
obj := generateObject(addr, nil, payload)
|
|
|
|
|
|
|
|
ns, as := testNodeMatrix(t, []int{2, 2})
|
|
|
|
|
|
|
|
c11 := newTestClient()
|
|
|
|
c11.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c12 := newTestClient()
|
|
|
|
c12.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c21 := newTestClient()
|
|
|
|
c21.addResult(addr, nil, errors.New("any error"))
|
|
|
|
|
|
|
|
c22 := newTestClient()
|
|
|
|
c22.addResult(addr, obj, nil)
|
|
|
|
|
|
|
|
const curEpoch = 13
|
|
|
|
|
2023-04-20 10:57:45 +00:00
|
|
|
svc := &Service{
|
2024-01-09 08:37:41 +00:00
|
|
|
log: test.NewLogger(t),
|
2023-04-20 10:57:45 +00:00
|
|
|
localStorage: newTestStorage(),
|
|
|
|
epochSource: testEpochReceiver(curEpoch),
|
|
|
|
traverserGenerator: &testTraverserGenerator{
|
|
|
|
c: cnr,
|
|
|
|
b: map[uint64]placement.Builder{
|
|
|
|
curEpoch: &testPlacementBuilder{
|
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
|
|
|
addr.EncodeToString(): ns[:1],
|
|
|
|
},
|
2021-01-12 14:55:02 +00:00
|
|
|
},
|
2023-04-20 10:57:45 +00:00
|
|
|
curEpoch - 1: &testPlacementBuilder{
|
|
|
|
vectors: map[string][][]netmap.NodeInfo{
|
|
|
|
addr.EncodeToString(): ns[1:],
|
|
|
|
},
|
2021-01-12 14:55:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-04-20 10:57:45 +00:00
|
|
|
remoteStorageConstructor: &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c11,
|
|
|
|
as[0][1]: c12,
|
|
|
|
as[1][0]: c21,
|
|
|
|
as[1][1]: c22,
|
|
|
|
},
|
2021-01-12 14:55:02 +00:00
|
|
|
},
|
2023-04-21 15:21:46 +00:00
|
|
|
keyStore: &testKeyStorage{},
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
commonPrm := new(util.CommonPrm)
|
|
|
|
|
|
|
|
p := Prm{}
|
|
|
|
p.SetObjectWriter(w)
|
|
|
|
p.SetCommonParameters(commonPrm)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
commonPrm.SetNetmapLookupDepth(1)
|
|
|
|
|
|
|
|
err = svc.Get(ctx, p)
|
|
|
|
require.NoError(t, err)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, obj, w.Object())
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
rp := RangePrm{}
|
|
|
|
rp.SetChunkWriter(w)
|
|
|
|
commonPrm.SetNetmapLookupDepth(0)
|
|
|
|
rp.SetCommonParameters(commonPrm)
|
|
|
|
rp.WithAddress(addr)
|
|
|
|
|
|
|
|
off, ln := payloadSz/3, payloadSz/3
|
|
|
|
|
|
|
|
r := objectSDK.NewRange()
|
|
|
|
r.SetOffset(off)
|
|
|
|
r.SetLength(ln)
|
|
|
|
|
|
|
|
rp.SetRange(r)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rp)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
w = NewSimpleObjectWriter()
|
|
|
|
rp.SetChunkWriter(w)
|
|
|
|
commonPrm.SetNetmapLookupDepth(1)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rp)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, payload[off:off+ln], w.Object().Payload())
|
|
|
|
|
|
|
|
hp := HeadPrm{}
|
|
|
|
hp.SetHeaderWriter(w)
|
|
|
|
commonPrm.SetNetmapLookupDepth(0)
|
|
|
|
hp.SetCommonParameters(commonPrm)
|
|
|
|
hp.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, hp)
|
2023-08-04 11:14:07 +00:00
|
|
|
require.True(t, clientSDK.IsErrObjectNotFound(err))
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
w = NewSimpleObjectWriter()
|
|
|
|
hp.SetHeaderWriter(w)
|
|
|
|
commonPrm.SetNetmapLookupDepth(1)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, hp)
|
|
|
|
require.NoError(t, err)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Equal(t, obj.CutPayload(), w.Object())
|
2021-01-12 14:55:02 +00:00
|
|
|
}
|