forked from TrueCloudLab/frostfs-sdk-go
[#19] transformer/test: Add helper functions
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
7e3810d654
commit
eba6831125
1 changed files with 21 additions and 14 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
cid "github.com/TrueCloudLab/frostfs-sdk-go/container/id"
|
||||||
cidtest "github.com/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "github.com/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object"
|
objectSDK "github.com/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
"github.com/TrueCloudLab/frostfs-sdk-go/version"
|
"github.com/TrueCloudLab/frostfs-sdk-go/version"
|
||||||
|
@ -18,23 +19,13 @@ func TestTransformer(t *testing.T) {
|
||||||
|
|
||||||
target, _ := newPayloadSizeLimiter(maxSize, tt)
|
target, _ := newPayloadSizeLimiter(maxSize, tt)
|
||||||
|
|
||||||
ver := version.Current()
|
|
||||||
cnr := cidtest.ID()
|
cnr := cidtest.ID()
|
||||||
hdr := objectSDK.New()
|
hdr := newObject(cnr)
|
||||||
hdr.SetContainerID(cnr)
|
|
||||||
hdr.SetType(objectSDK.TypeRegular)
|
|
||||||
hdr.SetVersion(&ver)
|
|
||||||
require.NoError(t, target.WriteHeader(hdr))
|
|
||||||
|
|
||||||
expectedPayload := make([]byte, maxSize*2+maxSize/2)
|
expectedPayload := make([]byte, maxSize*2+maxSize/2)
|
||||||
_, _ = rand.Read(expectedPayload)
|
_, _ = rand.Read(expectedPayload)
|
||||||
|
|
||||||
_, err := target.Write(expectedPayload)
|
ids := writeObject(t, target, hdr, expectedPayload)
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
ids, err := target.Close()
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
require.Equal(t, 4, len(tt.objects)) // 3 parts + linking object
|
require.Equal(t, 4, len(tt.objects)) // 3 parts + linking object
|
||||||
|
|
||||||
var actualPayload []byte
|
var actualPayload []byte
|
||||||
|
@ -62,13 +53,29 @@ func TestTransformer(t *testing.T) {
|
||||||
require.Equal(t, expectedPayload, actualPayload)
|
require.Equal(t, expectedPayload, actualPayload)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkTransformer(b *testing.B) {
|
func newObject(cnr cid.ID) *objectSDK.Object {
|
||||||
ver := version.Current()
|
ver := version.Current()
|
||||||
cnr := cidtest.ID()
|
|
||||||
hdr := objectSDK.New()
|
hdr := objectSDK.New()
|
||||||
hdr.SetContainerID(cnr)
|
hdr.SetContainerID(cnr)
|
||||||
hdr.SetType(objectSDK.TypeRegular)
|
hdr.SetType(objectSDK.TypeRegular)
|
||||||
hdr.SetVersion(&ver)
|
hdr.SetVersion(&ver)
|
||||||
|
return hdr
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeObject(t *testing.T, target ObjectTarget, header *objectSDK.Object, payload []byte) *AccessIdentifiers {
|
||||||
|
require.NoError(t, target.WriteHeader(header))
|
||||||
|
|
||||||
|
_, err := target.Write(payload)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
ids, err := target.Close()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
return ids
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkTransformer(b *testing.B) {
|
||||||
|
hdr := newObject(cidtest.ID())
|
||||||
|
|
||||||
b.Run("small", func(b *testing.B) {
|
b.Run("small", func(b *testing.B) {
|
||||||
benchmarkTransformer(b, hdr, 8*1024)
|
benchmarkTransformer(b, hdr, 8*1024)
|
||||||
|
|
Loading…
Reference in a new issue