2022-09-07 16:40:57 +00:00
|
|
|
package blobovnicza
|
|
|
|
|
|
|
|
import (
|
2023-03-13 11:37:35 +00:00
|
|
|
"context"
|
2022-09-07 16:40:57 +00:00
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
2023-03-07 13:38:26 +00:00
|
|
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
2022-09-07 16:40:57 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBlobovnicza_Get(t *testing.T) {
|
|
|
|
t.Run("re-configure object size limit", func(t *testing.T) {
|
|
|
|
filename := filepath.Join(t.TempDir(), "blob")
|
|
|
|
|
|
|
|
var blz *Blobovnicza
|
2024-01-09 13:26:43 +00:00
|
|
|
defer func() { require.NoError(t, blz.Close()) }()
|
2022-09-07 16:40:57 +00:00
|
|
|
|
|
|
|
fnInit := func(szLimit uint64) {
|
|
|
|
if blz != nil {
|
|
|
|
require.NoError(t, blz.Close())
|
|
|
|
}
|
|
|
|
|
|
|
|
blz = New(
|
|
|
|
WithPath(filename),
|
|
|
|
WithObjectSizeLimit(szLimit),
|
|
|
|
)
|
|
|
|
|
|
|
|
require.NoError(t, blz.Open())
|
|
|
|
require.NoError(t, blz.Init())
|
|
|
|
}
|
|
|
|
|
|
|
|
// initial distribution: [0:32K] (32K:64K]
|
|
|
|
fnInit(2 * firstBucketBound)
|
|
|
|
|
|
|
|
addr := oidtest.Address()
|
|
|
|
obj := make([]byte, firstBucketBound+1)
|
|
|
|
|
2023-06-20 08:24:14 +00:00
|
|
|
exists, err := blz.Exists(context.Background(), addr)
|
2022-11-17 06:06:59 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.False(t, exists)
|
|
|
|
|
2022-09-07 16:40:57 +00:00
|
|
|
var prmPut PutPrm
|
|
|
|
prmPut.SetAddress(addr)
|
|
|
|
prmPut.SetMarshaledObject(obj)
|
|
|
|
|
|
|
|
// place object to [32K:64K] bucket
|
2023-06-20 08:24:14 +00:00
|
|
|
_, err = blz.Put(context.Background(), prmPut)
|
2022-09-07 16:40:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
var prmGet GetPrm
|
|
|
|
prmGet.SetAddress(addr)
|
|
|
|
|
|
|
|
checkObj := func() {
|
2023-03-13 11:37:35 +00:00
|
|
|
res, err := blz.Get(context.Background(), prmGet)
|
2022-09-07 16:40:57 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, obj, res.Object())
|
2022-11-17 06:06:59 +00:00
|
|
|
|
2023-06-20 08:24:14 +00:00
|
|
|
exists, err := blz.Exists(context.Background(), addr)
|
2022-11-17 06:06:59 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.True(t, exists)
|
2022-09-07 16:40:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// object should be available
|
|
|
|
checkObj()
|
|
|
|
|
|
|
|
// new distribution (extended): [0:32K] (32K:64K] (64K:128K]
|
|
|
|
fnInit(3 * firstBucketBound)
|
|
|
|
|
|
|
|
// object should be still available
|
|
|
|
checkObj()
|
|
|
|
|
|
|
|
// new distribution (shrunk): [0:32K]
|
|
|
|
fnInit(firstBucketBound)
|
|
|
|
|
|
|
|
// object should be still available
|
|
|
|
checkObj()
|
|
|
|
})
|
|
|
|
}
|