2020-12-01 13:58:34 +00:00
|
|
|
package shard_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/core/object"
|
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard"
|
|
|
|
apistatus "github.com/TrueCloudLab/frostfs-sdk-go/client/status"
|
|
|
|
cidtest "github.com/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) {
|
|
|
|
t.Run("without write cache", func(t *testing.T) {
|
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) {
|
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
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
obj := generateObjectWithCID(t, cnr)
|
2020-12-01 13:58:34 +00:00
|
|
|
addAttribute(obj, "foo", "bar")
|
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var putPrm shard.PutPrm
|
|
|
|
var getPrm shard.GetPrm
|
2020-12-01 13:58:34 +00:00
|
|
|
|
|
|
|
t.Run("big object", func(t *testing.T) {
|
|
|
|
addPayload(obj, 1<<20)
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrm.SetObject(obj)
|
|
|
|
getPrm.SetAddress(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var delPrm shard.DeletePrm
|
2022-07-13 12:43:04 +00:00
|
|
|
delPrm.SetAddresses(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
|
|
|
_, err := sh.Put(putPrm)
|
|
|
|
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)
|
|
|
|
|
|
|
|
_, err = sh.Delete(delPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = sh.Get(getPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-01 13:58:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("small object", func(t *testing.T) {
|
2022-07-21 13:26:25 +00:00
|
|
|
obj := generateObjectWithCID(t, cnr)
|
|
|
|
addAttribute(obj, "foo", "bar")
|
2020-12-01 13:58:34 +00:00
|
|
|
addPayload(obj, 1<<5)
|
|
|
|
|
2022-07-13 12:43:04 +00:00
|
|
|
putPrm.SetObject(obj)
|
|
|
|
getPrm.SetAddress(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
2022-05-20 18:08:59 +00:00
|
|
|
var delPrm shard.DeletePrm
|
2022-07-13 12:43:04 +00:00
|
|
|
delPrm.SetAddresses(object.AddressOf(obj))
|
2020-12-01 13:58:34 +00:00
|
|
|
|
|
|
|
_, err := sh.Put(putPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = sh.Get(getPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = sh.Delete(delPrm)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
_, err = sh.Get(getPrm)
|
2022-03-17 08:03:58 +00:00
|
|
|
require.ErrorAs(t, err, new(apistatus.ObjectNotFound))
|
2020-12-01 13:58:34 +00:00
|
|
|
})
|
|
|
|
}
|