forked from TrueCloudLab/frostfs-sdk-go
client: Accept rng object.Range into PrmObjectRange
Signed-off-by: Evgenii Baidakov <evgenii@nspcc.io>
This commit is contained in:
parent
626532d7dd
commit
04ea0e8f6a
4 changed files with 87 additions and 8 deletions
|
@ -485,17 +485,23 @@ type PrmObjectRange struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOffset sets offset of the payload range to be read.
|
// SetOffset sets offset of the payload range to be read.
|
||||||
// Zero by default.
|
// Zero by default. It is an alternative to [PrmObjectRange.SetRange].
|
||||||
func (x *PrmObjectRange) SetOffset(off uint64) {
|
func (x *PrmObjectRange) SetOffset(off uint64) {
|
||||||
x.rng.SetOffset(off)
|
x.rng.SetOffset(off)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLength sets length of the payload range to be read.
|
// SetLength sets length of the payload range to be read.
|
||||||
// Must be positive.
|
// Must be positive. It is an alternative to [PrmObjectRange.SetRange].
|
||||||
func (x *PrmObjectRange) SetLength(ln uint64) {
|
func (x *PrmObjectRange) SetLength(ln uint64) {
|
||||||
x.rng.SetLength(ln)
|
x.rng.SetLength(ln)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetRange sets range of the payload to be read.
|
||||||
|
// It is an alternative to [PrmObjectRange.SetOffset], [PrmObjectRange.SetLength].
|
||||||
|
func (x *PrmObjectRange) SetRange(rng object.Range) {
|
||||||
|
x.rng = *rng.ToV2()
|
||||||
|
}
|
||||||
|
|
||||||
// UseSigner specifies private signer to sign the requests.
|
// UseSigner specifies private signer to sign the requests.
|
||||||
// If signer is not provided, then Client default signer is used.
|
// If signer is not provided, then Client default signer is used.
|
||||||
func (x *PrmObjectRange) UseSigner(signer neofscrypto.Signer) {
|
func (x *PrmObjectRange) UseSigner(signer neofscrypto.Signer) {
|
||||||
|
|
|
@ -2,10 +2,12 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
v2refs "github.com/nspcc-dev/neofs-api-go/v2/refs"
|
||||||
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
||||||
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
@ -48,3 +50,37 @@ func TestPrmObjectRead_ByAddress(t *testing.T) {
|
||||||
require.True(t, bytes.Equal(cidV2.GetValue(), prm.addr.GetContainerID().GetValue()))
|
require.True(t, bytes.Equal(cidV2.GetValue(), prm.addr.GetContainerID().GetValue()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrmObjectRange_SetRange(t *testing.T) {
|
||||||
|
var prm PrmObjectRange
|
||||||
|
|
||||||
|
var (
|
||||||
|
ln = rand.Uint64()
|
||||||
|
off = rand.Uint64()
|
||||||
|
rng *object.Range
|
||||||
|
)
|
||||||
|
|
||||||
|
t.Run("SetLength", func(t *testing.T) {
|
||||||
|
prm.SetLength(ln)
|
||||||
|
rng = object.NewRangeFromV2(&prm.rng)
|
||||||
|
|
||||||
|
require.Equal(t, ln, rng.GetLength())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetOffset", func(t *testing.T) {
|
||||||
|
prm.SetOffset(off)
|
||||||
|
rng = object.NewRangeFromV2(&prm.rng)
|
||||||
|
|
||||||
|
require.Equal(t, off, rng.GetOffset())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetRange", func(t *testing.T) {
|
||||||
|
var tmp object.Range
|
||||||
|
tmp.SetLength(ln)
|
||||||
|
tmp.SetOffset(off)
|
||||||
|
|
||||||
|
prm.SetRange(tmp)
|
||||||
|
require.Equal(t, ln, tmp.ToV2().GetLength())
|
||||||
|
require.Equal(t, off, tmp.ToV2().GetOffset())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
17
pool/pool.go
17
pool/pool.go
|
@ -829,8 +829,7 @@ func (c *clientWrapper) objectRange(ctx context.Context, prm PrmObjectRange) (Re
|
||||||
|
|
||||||
var cliPrm sdkClient.PrmObjectRange
|
var cliPrm sdkClient.PrmObjectRange
|
||||||
cliPrm.ByAddress(prm.addr)
|
cliPrm.ByAddress(prm.addr)
|
||||||
cliPrm.SetOffset(prm.off)
|
cliPrm.SetRange(prm.rng)
|
||||||
cliPrm.SetLength(prm.ln)
|
|
||||||
|
|
||||||
if prm.stoken != nil {
|
if prm.stoken != nil {
|
||||||
cliPrm.WithinSession(*prm.stoken)
|
cliPrm.WithinSession(*prm.stoken)
|
||||||
|
@ -1299,7 +1298,7 @@ type PrmObjectRange struct {
|
||||||
prmCommon
|
prmCommon
|
||||||
|
|
||||||
addr oid.Address
|
addr oid.Address
|
||||||
off, ln uint64
|
rng object.Range
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAddress specifies NeoFS address of the object.
|
// SetAddress specifies NeoFS address of the object.
|
||||||
|
@ -1308,13 +1307,21 @@ func (x *PrmObjectRange) SetAddress(addr oid.Address) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOffset sets offset of the payload range to be read.
|
// SetOffset sets offset of the payload range to be read.
|
||||||
|
// Zero by default. It is an alternative to [PrmObjectRange.SetRange].
|
||||||
func (x *PrmObjectRange) SetOffset(offset uint64) {
|
func (x *PrmObjectRange) SetOffset(offset uint64) {
|
||||||
x.off = offset
|
x.rng.SetOffset(offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLength sets length of the payload range to be read.
|
// SetLength sets length of the payload range to be read.
|
||||||
|
// Must be positive. It is an alternative to [PrmObjectRange.SetRange].
|
||||||
func (x *PrmObjectRange) SetLength(length uint64) {
|
func (x *PrmObjectRange) SetLength(length uint64) {
|
||||||
x.ln = length
|
x.rng.SetLength(length)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetRange sets range of the payload to be read.
|
||||||
|
// It is an alternative to [PrmObjectRange.SetOffset], [PrmObjectRange.SetLength].
|
||||||
|
func (x *PrmObjectRange) SetRange(rng object.Range) {
|
||||||
|
x.rng = rng
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrmObjectSearch groups parameters of SearchObjects operation.
|
// PrmObjectSearch groups parameters of SearchObjects operation.
|
||||||
|
|
|
@ -3,6 +3,7 @@ package pool
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"math/rand"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -655,3 +656,32 @@ func TestSwitchAfterErrorThreshold(t *testing.T) {
|
||||||
_, err = conn.objectGet(ctx, PrmObjectGet{})
|
_, err = conn.objectGet(ctx, PrmObjectGet{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrmObjectRange_SetRange(t *testing.T) {
|
||||||
|
var prm PrmObjectRange
|
||||||
|
|
||||||
|
ln := rand.Uint64()
|
||||||
|
off := rand.Uint64()
|
||||||
|
|
||||||
|
t.Run("SetLength", func(t *testing.T) {
|
||||||
|
prm.SetLength(ln)
|
||||||
|
|
||||||
|
require.Equal(t, ln, prm.rng.ToV2().GetLength())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetOffset", func(t *testing.T) {
|
||||||
|
prm.SetOffset(off)
|
||||||
|
|
||||||
|
require.Equal(t, off, prm.rng.ToV2().GetOffset())
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("SetRange", func(t *testing.T) {
|
||||||
|
var tmp object.Range
|
||||||
|
tmp.SetLength(ln)
|
||||||
|
tmp.SetOffset(off)
|
||||||
|
|
||||||
|
prm.SetRange(tmp)
|
||||||
|
require.Equal(t, ln, tmp.ToV2().GetLength())
|
||||||
|
require.Equal(t, off, tmp.ToV2().GetOffset())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue