2020-12-02 23:45:25 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"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"
|
|
|
|
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"
|
|
|
|
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"
|
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
|
|
|
|
|
|
|
|
func (e testEpochReceiver) currentEpoch() (uint64, error) {
|
|
|
|
return uint64(e), nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (g *testTraverserGenerator) GenerateTraverser(cnr cid.ID, obj *oid.ID, e uint64) (*placement.Traverser, 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))
|
|
|
|
}
|
|
|
|
|
|
|
|
return placement.NewTraverser(opts...)
|
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
|
|
|
|
}
|
|
|
|
|
2021-09-28 04:46:10 +00:00
|
|
|
func (c *testClientCache) get(info client.NodeInfo) (getClient, error) {
|
|
|
|
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
|
|
|
|
}{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-28 04:46:10 +00:00
|
|
|
func (c *testClient) getObject(exec *execCtx, _ client.NodeInfo) (*objectSDK.Object, error) {
|
2022-12-30 11:00:01 +00:00
|
|
|
v, ok := c.results[exec.prm.addr.EncodeToString()]
|
2020-12-02 23:45:25 +00:00
|
|
|
if !ok {
|
2022-03-17 08:03:58 +00:00
|
|
|
var errNotFound apistatus.ObjectNotFound
|
|
|
|
|
|
|
|
return nil, errNotFound
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 17:49:47 +00:00
|
|
|
if v.err != nil {
|
|
|
|
return nil, v.err
|
|
|
|
}
|
|
|
|
|
2022-12-30 11:00:01 +00:00
|
|
|
return cutToRange(v.obj, exec.prm.rng), nil
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
func (c *testClient) addResult(addr oid.Address, obj *objectSDK.Object, err error) {
|
|
|
|
c.results[addr.EncodeToString()] = struct {
|
2022-03-03 14:19:05 +00:00
|
|
|
obj *objectSDK.Object
|
2020-12-02 23:45:25 +00:00
|
|
|
err error
|
|
|
|
}{obj: obj, err: err}
|
|
|
|
}
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
func (s *testStorage) get(exec *execCtx) (*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
|
2022-12-30 11:00:01 +00:00
|
|
|
sAddr = exec.prm.addr.EncodeToString()
|
2020-12-02 23:45:25 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
if _, ok = s.inhumed[sAddr]; ok {
|
2022-03-17 08:03:58 +00:00
|
|
|
var errRemoved apistatus.ObjectAlreadyRemoved
|
|
|
|
|
|
|
|
return nil, errRemoved
|
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 {
|
2022-12-30 11:00:01 +00:00
|
|
|
return cutToRange(obj, exec.prm.rng), nil
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 08:03:58 +00:00
|
|
|
var errNotFound apistatus.ObjectNotFound
|
|
|
|
|
|
|
|
return nil, errNotFound
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
type writeHeaderErrorObjectWriter struct {
|
|
|
|
}
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
|
|
|
type writePayloadErrorObjectWriter struct {
|
|
|
|
}
|
|
|
|
|
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{}
|
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func TestGetLocalOnly(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
newSvc := func(storage *testStorage) *Service {
|
|
|
|
svc := &Service{cfg: new(cfg)}
|
|
|
|
svc.log = test.NewLogger(false)
|
|
|
|
svc.localStorage = storage
|
|
|
|
|
|
|
|
return svc
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectAlreadyRemoved))
|
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)
|
|
|
|
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
|
|
|
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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])
|
|
|
|
|
|
|
|
for j := 0; j < dim[i]; j++ {
|
|
|
|
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)
|
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)
|
|
|
|
|
|
|
|
for i := 0; i < ln; i++ {
|
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 {
|
|
|
|
svc := &Service{cfg: new(cfg)}
|
2020-12-09 10:32:33 +00:00
|
|
|
svc.log = test.NewLogger(false)
|
2020-12-02 23:45:25 +00:00
|
|
|
svc.localStorage = newTestStorage()
|
2021-01-12 14:55:02 +00:00
|
|
|
|
|
|
|
const curEpoch = 13
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
svc.traverserGenerator = &testTraverserGenerator{
|
|
|
|
c: cnr,
|
2021-01-12 14:55:02 +00:00
|
|
|
b: map[uint64]placement.Builder{
|
|
|
|
curEpoch: b,
|
|
|
|
},
|
2020-12-02 23:45:25 +00:00
|
|
|
}
|
|
|
|
svc.clientCache = c
|
2021-01-12 14:55:02 +00:00
|
|
|
svc.currentEpochReceiver = testEpochReceiver(curEpoch)
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
return svc
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
newRngPrm := func(raw bool, w ChunkWriter, off, ln uint64) RangePrm {
|
|
|
|
p := RangePrm{}
|
|
|
|
p.SetChunkWriter(w)
|
|
|
|
p.WithRawFlag(raw)
|
|
|
|
p.common = new(util.CommonPrm).WithLocalOnly(false)
|
|
|
|
|
|
|
|
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(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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(*apistatus.ObjectAlreadyRemoved))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(*apistatus.ObjectAlreadyRemoved))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(*apistatus.ObjectAlreadyRemoved))
|
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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-09 10:32:33 +00:00
|
|
|
|
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
headPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.Head(ctx, headPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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) {
|
2020-12-09 10:32:33 +00:00
|
|
|
headPrm := newHeadPrm(false, nil)
|
|
|
|
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"))
|
2022-03-17 08:03:58 +00:00
|
|
|
c1.addResult(splitAddr, nil, apistatus.ObjectNotFound{})
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
2022-03-17 08:03:58 +00:00
|
|
|
c2.addResult(splitAddr, nil, 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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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)
|
2022-03-17 08:03:58 +00:00
|
|
|
c2.addResult(child2Addr, nil, 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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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)
|
|
|
|
require.Equal(t, err.Error(), "received child with empty parent")
|
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)
|
|
|
|
require.Equal(t, err.Error(), "received child with empty parent")
|
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"))
|
2022-03-17 08:03:58 +00:00
|
|
|
c1.addResult(splitAddr, nil, apistatus.ObjectNotFound{})
|
2020-12-02 23:45:25 +00:00
|
|
|
|
|
|
|
c2 := newTestClient()
|
|
|
|
c2.addResult(addr, nil, objectSDK.NewSplitInfoError(splitInfo))
|
2022-03-17 08:03:58 +00:00
|
|
|
c2.addResult(splitAddr, nil, 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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 0)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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()
|
2022-03-17 08:03:58 +00:00
|
|
|
headSvc.addResult(preRightAddr, nil, 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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-07 17:49:47 +00:00
|
|
|
|
|
|
|
rngPrm := newRngPrm(false, nil, 0, 1)
|
|
|
|
rngPrm.WithAddress(addr)
|
|
|
|
|
|
|
|
err = svc.GetRange(ctx, rngPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
svc := &Service{cfg: new(cfg)}
|
|
|
|
svc.log = test.NewLogger(false)
|
|
|
|
svc.localStorage = newTestStorage()
|
|
|
|
|
|
|
|
const curEpoch = 13
|
|
|
|
|
|
|
|
svc.traverserGenerator = &testTraverserGenerator{
|
|
|
|
c: cnr,
|
|
|
|
b: map[uint64]placement.Builder{
|
|
|
|
curEpoch: &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[:1],
|
2021-01-12 14:55:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
curEpoch - 1: &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[1:],
|
2021-01-12 14:55:02 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc.clientCache = &testClientCache{
|
|
|
|
clients: map[string]*testClient{
|
|
|
|
as[0][0]: c11,
|
|
|
|
as[0][1]: c12,
|
|
|
|
as[1][0]: c21,
|
|
|
|
as[1][1]: c22,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
svc.currentEpochReceiver = testEpochReceiver(curEpoch)
|
|
|
|
|
|
|
|
w := NewSimpleObjectWriter()
|
|
|
|
|
|
|
|
commonPrm := new(util.CommonPrm)
|
|
|
|
|
|
|
|
p := Prm{}
|
|
|
|
p.SetObjectWriter(w)
|
|
|
|
p.SetCommonParameters(commonPrm)
|
|
|
|
p.WithAddress(addr)
|
|
|
|
|
|
|
|
err := svc.Get(ctx, p)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
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
|
|
|
}
|