2021-10-27 14:51:58 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
2023-04-12 14:01:29 +00:00
|
|
|
"context"
|
2023-04-16 14:03:42 +00:00
|
|
|
"path/filepath"
|
2021-10-27 14:51:58 +00:00
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
2023-04-16 14:03:42 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/blobstor"
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-04-16 14:03:42 +00:00
|
|
|
meta "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/metabase"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/pilorama"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
2023-08-23 07:53:42 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger/test"
|
2023-03-07 13:38:26 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
|
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
2021-10-27 14:51:58 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2022-11-12 13:48:44 +00:00
|
|
|
func sortAddresses(addrWithType []object.AddressWithType) []object.AddressWithType {
|
|
|
|
sort.Slice(addrWithType, func(i, j int) bool {
|
|
|
|
return addrWithType[i].Address.EncodeToString() < addrWithType[j].Address.EncodeToString()
|
2021-10-27 14:51:58 +00:00
|
|
|
})
|
2022-11-12 13:48:44 +00:00
|
|
|
return addrWithType
|
2021-10-27 14:51:58 +00:00
|
|
|
}
|
2023-04-16 14:03:42 +00:00
|
|
|
|
|
|
|
func TestListWithCursor(t *testing.T) {
|
2023-05-05 13:17:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2023-04-16 14:03:42 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
shardNum int
|
|
|
|
objectNum int
|
|
|
|
batchSize uint32
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "one shard, few objects, small batch size",
|
|
|
|
shardNum: 1,
|
|
|
|
objectNum: 2,
|
|
|
|
batchSize: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "one shard, many objects, big batch size",
|
|
|
|
shardNum: 1,
|
|
|
|
objectNum: 53,
|
|
|
|
batchSize: 100,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "many shards, many objects, small batch size",
|
|
|
|
shardNum: 6,
|
|
|
|
objectNum: 66,
|
|
|
|
batchSize: 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "many shards, many objects, big batch size",
|
|
|
|
shardNum: 6,
|
|
|
|
objectNum: 99,
|
|
|
|
batchSize: 100,
|
|
|
|
},
|
|
|
|
}
|
2023-05-05 13:17:29 +00:00
|
|
|
for i := range tests {
|
|
|
|
tt := tests[i]
|
2023-04-16 14:03:42 +00:00
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2023-05-05 13:17:29 +00:00
|
|
|
t.Parallel()
|
2023-04-16 14:03:42 +00:00
|
|
|
e := testNewEngine(t).setShardsNumOpts(t, tt.shardNum, func(id int) []shard.Option {
|
|
|
|
return []shard.Option{
|
2024-01-09 08:37:41 +00:00
|
|
|
shard.WithLogger(test.NewLogger(t)),
|
2023-04-16 14:03:42 +00:00
|
|
|
shard.WithBlobStorOptions(
|
|
|
|
blobstor.WithStorages(
|
2023-08-14 11:01:39 +00:00
|
|
|
newStorages(t.TempDir(), 1<<20))),
|
|
|
|
shard.WithPiloramaOptions(pilorama.WithPath(filepath.Join(t.TempDir(), "pilorama"))),
|
2023-04-16 14:03:42 +00:00
|
|
|
shard.WithMetaBaseOptions(
|
2023-08-14 11:01:39 +00:00
|
|
|
meta.WithPath(filepath.Join(t.TempDir(), "metabase")),
|
2023-10-31 11:56:55 +00:00
|
|
|
meta.WithPermissions(0o700),
|
2023-04-16 14:03:42 +00:00
|
|
|
meta.WithEpochState(epochState{}),
|
2023-10-31 11:56:55 +00:00
|
|
|
),
|
|
|
|
}
|
2023-04-16 14:03:42 +00:00
|
|
|
}).engine
|
2023-08-31 16:26:47 +00:00
|
|
|
require.NoError(t, e.Open(context.Background()))
|
2023-04-16 14:03:42 +00:00
|
|
|
require.NoError(t, e.Init(context.Background()))
|
|
|
|
|
|
|
|
t.Cleanup(func() {
|
2023-08-31 16:26:47 +00:00
|
|
|
e.Close(context.Background())
|
2023-04-16 14:03:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
expected := make([]object.AddressWithType, 0, tt.objectNum)
|
|
|
|
got := make([]object.AddressWithType, 0, tt.objectNum)
|
|
|
|
|
|
|
|
for i := 0; i < tt.objectNum; i++ {
|
|
|
|
containerID := cidtest.ID()
|
|
|
|
obj := testutil.GenerateObjectWithCIDWithPayload(containerID, []byte{'a'})
|
|
|
|
|
|
|
|
var prm PutPrm
|
|
|
|
prm.WithObject(obj)
|
|
|
|
|
|
|
|
err := e.Put(context.Background(), prm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
expected = append(expected, object.AddressWithType{Type: objectSDK.TypeRegular, Address: object.AddressOf(obj)})
|
|
|
|
}
|
|
|
|
expected = sortAddresses(expected)
|
|
|
|
|
|
|
|
var prm ListWithCursorPrm
|
|
|
|
prm.count = tt.batchSize
|
|
|
|
for {
|
2023-06-06 09:27:19 +00:00
|
|
|
res, err := e.ListWithCursor(context.Background(), prm)
|
2023-04-16 14:03:42 +00:00
|
|
|
if err == ErrEndOfListing {
|
|
|
|
require.Empty(t, res.AddressList())
|
|
|
|
break
|
|
|
|
}
|
|
|
|
require.NotEmpty(t, res.AddressList())
|
|
|
|
got = append(got, res.AddressList()...)
|
|
|
|
prm.cursor = res.Cursor()
|
|
|
|
}
|
|
|
|
|
|
|
|
got = sortAddresses(got)
|
|
|
|
require.Equal(t, expected, got)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|