[#1318] meta: Add test TestInhumeECObject
All checks were successful
DCO action / DCO (pull_request) Successful in 1m40s
Vulncheck / Vulncheck (pull_request) Successful in 1m56s
Build / Build Components (1.21) (pull_request) Successful in 2m26s
Build / Build Components (1.22) (pull_request) Successful in 2m34s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m55s
Tests and linters / Tests (1.21) (pull_request) Successful in 2m55s
Tests and linters / Tests (1.22) (pull_request) Successful in 2m54s
Tests and linters / Staticcheck (pull_request) Successful in 2m52s
Tests and linters / Tests with -race (pull_request) Successful in 2m58s
Tests and linters / Lint (pull_request) Successful in 3m11s
Tests and linters / gopls check (pull_request) Successful in 3m47s
All checks were successful
DCO action / DCO (pull_request) Successful in 1m40s
Vulncheck / Vulncheck (pull_request) Successful in 1m56s
Build / Build Components (1.21) (pull_request) Successful in 2m26s
Build / Build Components (1.22) (pull_request) Successful in 2m34s
Pre-commit hooks / Pre-commit (pull_request) Successful in 2m55s
Tests and linters / Tests (1.21) (pull_request) Successful in 2m55s
Tests and linters / Tests (1.22) (pull_request) Successful in 2m54s
Tests and linters / Staticcheck (pull_request) Successful in 2m52s
Tests and linters / Tests with -race (pull_request) Successful in 2m58s
Tests and linters / Lint (pull_request) Successful in 3m11s
Tests and linters / gopls check (pull_request) Successful in 3m47s
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
parent
dd570c9344
commit
5aef303259
1 changed files with 116 additions and 0 deletions
116
pkg/local_object_storage/metabase/inhume_ec_test.go
Normal file
116
pkg/local_object_storage/metabase/inhume_ec_test.go
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
package meta
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/testutil"
|
||||||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
|
||||||
|
apistatus "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/client/status"
|
||||||
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
||||||
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInhumeECObject(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
db := New(
|
||||||
|
WithPath(filepath.Join(t.TempDir(), "metabase")),
|
||||||
|
WithPermissions(0o600),
|
||||||
|
WithEpochState(epochState{uint64(12)}),
|
||||||
|
)
|
||||||
|
|
||||||
|
require.NoError(t, db.Open(context.Background(), mode.ReadWrite))
|
||||||
|
require.NoError(t, db.Init())
|
||||||
|
defer func() { require.NoError(t, db.Close()) }()
|
||||||
|
|
||||||
|
cnr := cidtest.ID()
|
||||||
|
ecChunk := oidtest.ID()
|
||||||
|
ecChunk2 := oidtest.ID()
|
||||||
|
ecParent := oidtest.ID()
|
||||||
|
tombstoneID := oidtest.ID()
|
||||||
|
|
||||||
|
chunkObj := testutil.GenerateObjectWithCID(cnr)
|
||||||
|
chunkObj.SetContainerID(cnr)
|
||||||
|
chunkObj.SetID(ecChunk)
|
||||||
|
chunkObj.SetPayload([]byte{0, 1, 2, 3, 4})
|
||||||
|
chunkObj.SetPayloadSize(uint64(5))
|
||||||
|
chunkObj.SetECHeader(objectSDK.NewECHeader(objectSDK.ECParentInfo{ID: ecParent}, 0, 3, []byte{}, 0))
|
||||||
|
|
||||||
|
chunkObj2 := testutil.GenerateObjectWithCID(cnr)
|
||||||
|
chunkObj2.SetContainerID(cnr)
|
||||||
|
chunkObj2.SetID(ecChunk2)
|
||||||
|
chunkObj2.SetPayload([]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9})
|
||||||
|
chunkObj2.SetPayloadSize(uint64(10))
|
||||||
|
chunkObj2.SetECHeader(objectSDK.NewECHeader(objectSDK.ECParentInfo{ID: ecParent}, 1, 3, []byte{}, 0))
|
||||||
|
|
||||||
|
// put object with EC
|
||||||
|
|
||||||
|
var prm PutPrm
|
||||||
|
prm.SetObject(chunkObj)
|
||||||
|
prm.SetStorageID([]byte("0/0"))
|
||||||
|
_, err := db.Put(context.Background(), prm)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
prm.SetObject(chunkObj2)
|
||||||
|
_, err = db.Put(context.Background(), prm)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var ecChunkAddress oid.Address
|
||||||
|
ecChunkAddress.SetContainer(cnr)
|
||||||
|
ecChunkAddress.SetObject(ecChunk)
|
||||||
|
|
||||||
|
var ecParentAddress oid.Address
|
||||||
|
ecParentAddress.SetContainer(cnr)
|
||||||
|
ecParentAddress.SetObject(ecParent)
|
||||||
|
|
||||||
|
var chunkObjectAddress oid.Address
|
||||||
|
chunkObjectAddress.SetContainer(cnr)
|
||||||
|
chunkObjectAddress.SetObject(ecChunk)
|
||||||
|
|
||||||
|
var getPrm GetPrm
|
||||||
|
|
||||||
|
getPrm.SetAddress(ecChunkAddress)
|
||||||
|
_, err = db.Get(context.Background(), getPrm)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
var ecInfoError *objectSDK.ECInfoError
|
||||||
|
getPrm.SetAddress(ecParentAddress)
|
||||||
|
_, err = db.Get(context.Background(), getPrm)
|
||||||
|
require.ErrorAs(t, err, &ecInfoError)
|
||||||
|
require.True(t, len(ecInfoError.ECInfo().Chunks) == 2 &&
|
||||||
|
ecInfoError.ECInfo().Chunks[0].Index == 0 &&
|
||||||
|
ecInfoError.ECInfo().Chunks[0].Total == 3)
|
||||||
|
|
||||||
|
// inhume Chunk
|
||||||
|
var inhumePrm InhumePrm
|
||||||
|
var tombAddress oid.Address
|
||||||
|
inhumePrm.SetAddresses(chunkObjectAddress)
|
||||||
|
res, err := db.Inhume(context.Background(), inhumePrm)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.True(t, len(res.deletionDetails) == 1)
|
||||||
|
require.True(t, res.deletionDetails[0].Size == 5)
|
||||||
|
|
||||||
|
// inhume EC parent (like Delete does)
|
||||||
|
tombAddress.SetContainer(cnr)
|
||||||
|
tombAddress.SetObject(tombstoneID)
|
||||||
|
inhumePrm.SetAddresses(ecParentAddress)
|
||||||
|
inhumePrm.SetTombstoneAddress(tombAddress)
|
||||||
|
res, err = db.Inhume(context.Background(), inhumePrm)
|
||||||
|
require.NoError(t, err)
|
||||||
|
// Previously deleted chunk shouldn't be in the details, because it is marked as garbage
|
||||||
|
require.True(t, len(res.deletionDetails) == 1)
|
||||||
|
require.True(t, res.deletionDetails[0].Size == 10)
|
||||||
|
|
||||||
|
getPrm.SetAddress(ecParentAddress)
|
||||||
|
_, err = db.Get(context.Background(), getPrm)
|
||||||
|
require.ErrorAs(t, err, new(*apistatus.ObjectAlreadyRemoved))
|
||||||
|
|
||||||
|
getPrm.SetAddress(ecChunkAddress)
|
||||||
|
_, err = db.Get(context.Background(), getPrm)
|
||||||
|
require.ErrorAs(t, err, new(*apistatus.ObjectAlreadyRemoved))
|
||||||
|
}
|
Loading…
Reference in a new issue