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-08-25 09:04:34 +00:00
|
|
|
"time"
|
2020-12-01 13:58:34 +00:00
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestShard_Delete(t *testing.T) {
|
2023-05-05 11:08:10 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2020-12-01 13:58:34 +00:00
|
|
|
t.Run("without write cache", func(t *testing.T) {
|
2023-05-05 11:08:10 +00:00
|
|
|
t.Parallel()
|
2021-04-06 10:56:06 +00:00
|
|
|
testShardDelete(t, false)
|
2020-12-01 13:58:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("with write cache", func(t *testing.T) {
|
2023-05-05 11:08:10 +00:00
|
|
|
t.Parallel()
|
2021-04-06 10:56:06 +00:00
|
|
|
testShardDelete(t, true)
|
2020-12-01 13:58:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-04-06 10:56:06 +00:00
|
|
|
func testShardDelete(t *testing.T, hasWriteCache bool) {
|
|
|
|
sh := newShard(t, hasWriteCache)
|
|
|
|
defer releaseShard(sh, t)
|
|
|
|
|
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")
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var putPrm PutPrm
|
|
|
|
var getPrm GetPrm
|
2020-12-01 13:58:34 +00:00
|
|
|
|
|
|
|
t.Run("big object", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
testutil.AddPayload(obj, 1<<20)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrm.SetObject(obj)
|
|
|
|
getPrm.SetAddress(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var delPrm DeletePrm
|
2022-07-13 12:43:04 +00:00
|
|
|
delPrm.SetAddresses(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
2020-12-01 13:58:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2021-04-06 10:56:06 +00:00
|
|
|
_, err = testGet(t, sh, getPrm, hasWriteCache)
|
2020-12-01 13:58:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = sh.Delete(context.TODO(), delPrm)
|
2020-12-01 13:58:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-08-25 09:04:34 +00:00
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
|
|
|
return client.IsErrObjectNotFound(err)
|
|
|
|
}, time.Second, 50*time.Millisecond)
|
2020-12-01 13:58:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("small object", func(t *testing.T) {
|
2023-03-20 14:10:26 +00:00
|
|
|
obj := testutil.GenerateObjectWithCID(cnr)
|
|
|
|
testutil.AddAttribute(obj, "foo", "bar")
|
|
|
|
testutil.AddPayload(obj, 1<<5)
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrm.SetObject(obj)
|
|
|
|
getPrm.SetAddress(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-08-31 12:47:06 +00:00
|
|
|
var delPrm DeletePrm
|
2022-07-13 12:43:04 +00:00
|
|
|
delPrm.SetAddresses(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err := sh.Put(context.Background(), putPrm)
|
2020-12-01 13:58:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-03-13 11:37:35 +00:00
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
2020-12-01 13:58:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-04-12 14:01:29 +00:00
|
|
|
_, err = sh.Delete(context.Background(), delPrm)
|
2020-12-01 13:58:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2023-08-25 09:04:34 +00:00
|
|
|
require.Eventually(t, func() bool {
|
|
|
|
_, err = sh.Get(context.Background(), getPrm)
|
|
|
|
return client.IsErrObjectNotFound(err)
|
|
|
|
}, time.Second, 50*time.Millisecond)
|
2020-12-01 13:58:34 +00:00
|
|
|
})
|
|
|
|
}
|