2023-08-31 12:47:06 +00:00
|
|
|
package shard
|
2020-12-01 13:58:34 +00:00
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2020-12-01 13:58:34 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/object"
|
2023-03-20 14:10:26 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
2023-08-04 11:14:07 +00:00
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client"
|
2023-03-07 13:38:26 +00:00
|
|
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
2020-12-01 13:58:34 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
func TestShard_Delete_SmallObject(t *testing.T) {
|
|
|
|
t.Run("small object without write cache", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
testShard(t, false, 1<<5)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("small object with write cache", func(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
testShard(t, true, 1<<5)
|
|
|
|
})
|
|
|
|
}
|
2023-05-05 11:08:10 +00:00
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
func TestShard_Delete_BigObject(t *testing.T) {
|
|
|
|
t.Run("big object without write cache", func(t *testing.T) {
|
2023-05-05 11:08:10 +00:00
|
|
|
t.Parallel()
|
2023-11-29 07:46:46 +00:00
|
|
|
testShard(t, false, 1<<20)
|
2020-12-01 13:58:34 +00:00
|
|
|
})
|
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
t.Run("big object with write cache", func(t *testing.T) {
|
2023-05-05 11:08:10 +00:00
|
|
|
t.Parallel()
|
2023-11-29 07:46:46 +00:00
|
|
|
testShard(t, true, 1<<20)
|
2020-12-01 13:58:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
func testShard(t *testing.T, hasWriteCache bool, payloadSize int) {
|
2021-04-06 10:56:06 +00:00
|
|
|
sh := newShard(t, hasWriteCache)
|
2024-10-21 08:56:38 +00:00
|
|
|
defer func() { require.NoError(t, sh.Close(context.Background())) }()
|
2021-04-06 10:56:06 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-03-20 14:10:26 +00:00
|
|
|
obj := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(obj, "foo", "bar")
|
2023-11-29 07:46:46 +00:00
|
|
|
testutil.AddPayload(obj, payloadSize)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var putPrm PutPrm
|
2023-11-29 07:46:46 +00:00
|
|
|
putPrm.SetObject(obj)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
var getPrm GetPrm
|
|
|
|
getPrm.SetAddress(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
var delPrm DeletePrm
|
|
|
|
delPrm.SetAddresses(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
|
|
|
require.NoError(t, err)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2024-09-17 08:24:48 +00:00
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
2023-11-29 07:46:46 +00:00
|
|
|
require.NoError(t, err)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
if hasWriteCache {
|
2024-09-17 08:24:48 +00:00
|
|
|
require.NoError(t, sh.FlushWriteCache(context.Background(), FlushWriteCachePrm{ignoreErrors: false}))
|
2023-11-29 07:46:46 +00:00
|
|
|
}
|
2024-09-17 08:24:48 +00:00
|
|
|
_, err = sh.Delete(context.Background(), delPrm)
|
|
|
|
require.NoError(t, err)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-11-29 07:46:46 +00:00
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
|
|
|
require.True(t, client.IsErrObjectNotFound(err))
|
2020-12-01 13:58:34 +00:00
|
|
|
}
|