2020-12-08 07:51:34 +00:00
|
|
|
package meta_test
|
2020-10-30 13:42:24 +00:00
|
|
|
|
|
|
|
import (
|
2020-12-08 07:51:34 +00:00
|
|
|
"encoding/hex"
|
2022-05-25 12:56:45 +00:00
|
|
|
"strconv"
|
2020-10-30 13:42:24 +00:00
|
|
|
"testing"
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
2022-03-03 14:19:05 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-12-08 09:56:14 +00:00
|
|
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
2022-05-25 12:56:45 +00:00
|
|
|
cidSDK "github.com/nspcc-dev/neofs-sdk-go/container/id"
|
2021-11-10 07:08:33 +00:00
|
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
2022-05-31 17:00:41 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2022-05-12 16:37:46 +00:00
|
|
|
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
2021-11-10 07:08:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/version"
|
2020-10-30 13:42:24 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectUserAttributes(t *testing.T) {
|
|
|
|
db := newDB(t)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
raw1 := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
addAttribute(raw1, "foo", "bar")
|
|
|
|
addAttribute(raw1, "x", "y")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
raw2 := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
addAttribute(raw2, "foo", "bar")
|
|
|
|
addAttribute(raw2, "x", "z")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
raw3 := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
addAttribute(raw3, "a", "b")
|
2020-10-30 13:42:24 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw3)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
raw4 := generateObjectWithCID(t, cnr)
|
2021-08-18 07:26:14 +00:00
|
|
|
addAttribute(raw4, "path", "test/1/2")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw4)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
raw5 := generateObjectWithCID(t, cnr)
|
2021-08-18 07:26:14 +00:00
|
|
|
addAttribute(raw5, "path", "test/1/3")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw5)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
raw6 := generateObjectWithCID(t, cnr)
|
2021-08-18 07:26:14 +00:00
|
|
|
addAttribute(raw6, "path", "test/2/3")
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw6)
|
2021-08-18 07:26:14 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("foo", "bar", objectSDK.MatchStringEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("x", "y", objectSDK.MatchStringEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("x", "y", objectSDK.MatchStringNotEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("a", "b", objectSDK.MatchStringEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw3))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter("c", "d", objectSDK.MatchStringEqual)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter("foo", "", objectSDK.MatchNotPresent)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("a", "", objectSDK.MatchNotPresent)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("key", "", objectSDK.MatchNotPresent)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
|
|
|
object.AddressOf(raw3),
|
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("path", "test", objectSDK.MatchCommonPrefix)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
|
|
|
object.AddressOf(raw6),
|
2021-08-18 07:26:14 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("path", "test/1", objectSDK.MatchCommonPrefix)
|
2022-05-12 16:37:46 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw4),
|
|
|
|
object.AddressOf(raw5),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-10-30 13:42:24 +00:00
|
|
|
}
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectRootPhyParent(t *testing.T) {
|
2020-11-03 13:12:34 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// prepare
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
small := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, small)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
ts := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, ts)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
sg := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, sg)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
leftChild := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
leftChild.InitRelations()
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, leftChild)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 13:12:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
lock := generateObjectWithCID(t, cnr)
|
2022-02-15 12:51:56 +00:00
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
err = putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
parent := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
rightChild := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
rightChild.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent, _ := parent.ID()
|
|
|
|
rightChild.SetParentID(idParent)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, rightChild)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
link := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
link.SetParent(parent)
|
2022-05-12 16:37:46 +00:00
|
|
|
link.SetParentID(idParent)
|
|
|
|
idLeftChild, _ := leftChild.ID()
|
|
|
|
idRightChild, _ := rightChild.ID()
|
|
|
|
link.SetChildren(idLeftChild, idRightChild)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, link)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("root objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddRootFilter()
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(parent),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterPropertyRoot, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("phy objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddPhyFilter()
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterPropertyPhy, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("regular objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
2020-11-03 14:09:59 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeRegular.String(), objectSDK.MatchStringNotEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(sg),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tombstone objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(ts))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeTombstone.String(), objectSDK.MatchStringNotEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("storage group objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2021-02-01 21:00:40 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(sg))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, v2object.TypeStorageGroup.String(), objectSDK.MatchStringNotEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderObjectType, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("objects with parent", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent, _ := parent.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderParent,
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent.EncodeToString(),
|
2020-12-08 07:51:34 +00:00
|
|
|
objectSDK.MatchStringEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderParent, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("all objects", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(small),
|
|
|
|
object.AddressOf(ts),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(leftChild),
|
|
|
|
object.AddressOf(rightChild),
|
|
|
|
object.AddressOf(link),
|
|
|
|
object.AddressOf(parent),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
|
|
|
})
|
2020-11-03 14:09:59 +00:00
|
|
|
}
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectInhume(t *testing.T) {
|
2020-11-03 14:09:59 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
raw1 := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
raw2 := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
|
|
|
object.AddressOf(raw2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var tombstone oid.Address
|
|
|
|
tombstone.SetContainer(cnr)
|
|
|
|
tombstone.SetObject(oidtest.ID())
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = meta.Inhume(db, object.AddressOf(raw2), tombstone)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:09:59 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(raw1),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-03 14:09:59 +00:00
|
|
|
}
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectPayloadHash(t *testing.T) {
|
2020-11-03 14:24:23 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
raw1 := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
raw2 := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-11 16:35:01 +00:00
|
|
|
cs, _ := raw1.PayloadChecksum()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
2022-05-11 16:35:01 +00:00
|
|
|
hex.EncodeToString(cs.Value()),
|
2020-12-08 07:51:34 +00:00
|
|
|
objectSDK.MatchStringEqual)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
2022-05-11 16:35:01 +00:00
|
|
|
hex.EncodeToString(cs.Value()),
|
2021-02-01 21:00:40 +00:00
|
|
|
objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadHash,
|
|
|
|
"",
|
|
|
|
objectSDK.MatchNotPresent)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
}
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectWithSlowFilters(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2021-11-10 07:08:33 +00:00
|
|
|
v20 := new(version.Version)
|
2020-12-08 07:51:34 +00:00
|
|
|
v20.SetMajor(2)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
var v21 version.Version
|
2020-12-08 07:51:34 +00:00
|
|
|
v21.SetMajor(2)
|
|
|
|
v21.SetMinor(1)
|
2020-11-03 14:24:23 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
raw1 := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
raw1.SetPayloadSize(10)
|
|
|
|
raw1.SetCreationEpoch(11)
|
|
|
|
raw1.SetVersion(v20)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
raw2 := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
raw2.SetPayloadSize(20)
|
|
|
|
raw2.SetCreationEpoch(21)
|
2022-05-31 17:00:41 +00:00
|
|
|
raw2.SetVersion(&v21)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("object with TZHash", func(t *testing.T) {
|
2022-05-11 16:35:01 +00:00
|
|
|
cs, _ := raw1.PayloadHomomorphicHash()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
2022-05-11 16:35:01 +00:00
|
|
|
hex.EncodeToString(cs.Value()),
|
2020-12-08 07:51:34 +00:00
|
|
|
objectSDK.MatchStringEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
2022-05-11 16:35:01 +00:00
|
|
|
hex.EncodeToString(cs.Value()),
|
2021-02-01 21:00:40 +00:00
|
|
|
objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderHomomorphicHash,
|
|
|
|
"",
|
|
|
|
objectSDK.MatchNotPresent)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with payload length", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "20", objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderPayloadLength, "", objectSDK.MatchNotPresent)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with creation epoch", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "11", objectSDK.MatchStringNotEqual)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderCreationEpoch, "", objectSDK.MatchNotPresent)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("object with version", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchStringEqual, v21)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw2))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchStringNotEqual, v21)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(raw1))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectVersionFilter(objectSDK.MatchNotPresent, version.Version{})
|
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_SelectObjectID(t *testing.T) {
|
2020-11-05 16:54:24 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
// prepare
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
parent := generateObjectWithCID(t, cnr)
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
regular := generateObjectWithCID(t, cnr)
|
2022-05-12 16:37:46 +00:00
|
|
|
idParent, _ := parent.ID()
|
|
|
|
regular.SetParentID(idParent)
|
2022-03-03 14:19:05 +00:00
|
|
|
regular.SetParent(parent)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, regular)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
ts := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
ts.SetType(objectSDK.TypeTombstone)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, ts)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
sg := generateObjectWithCID(t, cnr)
|
2020-12-08 07:51:34 +00:00
|
|
|
sg.SetType(objectSDK.TypeStorageGroup)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, sg)
|
2020-12-08 07:51:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
lock := generateObjectWithCID(t, cnr)
|
2022-02-15 12:51:56 +00:00
|
|
|
lock.SetType(objectSDK.TypeLock)
|
|
|
|
err = putBig(db, lock)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("not found objects", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
raw := generateObjectWithCID(t, cnr)
|
2020-11-05 16:54:24 +00:00
|
|
|
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := raw.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("regular objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := regular.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(regular))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("tombstone objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := ts.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(ts))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("storage group objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := sg.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(sg))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
t.Run("parent objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := parent.ID()
|
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(parent))
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(ts),
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(lock),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("lock objects", func(t *testing.T) {
|
2022-05-12 16:37:46 +00:00
|
|
|
id, _ := lock.ID()
|
|
|
|
|
2022-02-15 12:51:56 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(lock))
|
2022-02-15 12:51:56 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-12 16:37:46 +00:00
|
|
|
fs.AddObjectIDFilter(objectSDK.MatchStringNotEqual, id)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-02-15 12:51:56 +00:00
|
|
|
object.AddressOf(regular),
|
|
|
|
object.AddressOf(parent),
|
|
|
|
object.AddressOf(sg),
|
|
|
|
object.AddressOf(ts),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-05 16:54:24 +00:00
|
|
|
}
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
func TestDB_SelectSplitID(t *testing.T) {
|
2020-11-20 07:43:41 +00:00
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
child1 := generateObjectWithCID(t, cnr)
|
|
|
|
child2 := generateObjectWithCID(t, cnr)
|
|
|
|
child3 := generateObjectWithCID(t, cnr)
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
split1 := objectSDK.NewSplitID()
|
|
|
|
split2 := objectSDK.NewSplitID()
|
|
|
|
|
|
|
|
child1.SetSplitID(split1)
|
|
|
|
child2.SetSplitID(split1)
|
|
|
|
child3.SetSplitID(split2)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
require.NoError(t, putBig(db, child1))
|
|
|
|
require.NoError(t, putBig(db, child2))
|
|
|
|
require.NoError(t, putBig(db, child3))
|
2020-12-08 07:51:34 +00:00
|
|
|
|
2021-02-01 21:00:40 +00:00
|
|
|
t.Run("not present", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchNotPresent)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2021-02-01 21:00:40 +00:00
|
|
|
})
|
|
|
|
|
2020-12-08 07:51:34 +00:00
|
|
|
t.Run("split id", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, split1.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(child1),
|
|
|
|
object.AddressOf(child2),
|
2020-12-08 07:51:34 +00:00
|
|
|
)
|
2020-11-20 07:43:41 +00:00
|
|
|
|
2020-12-10 13:17:45 +00:00
|
|
|
fs = objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, split2.String(), objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs, object.AddressOf(child3))
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty split", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID, "", objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("unknown split id", func(t *testing.T) {
|
2020-12-10 13:17:45 +00:00
|
|
|
fs := objectSDK.SearchFilters{}
|
2020-12-08 07:51:34 +00:00
|
|
|
fs.AddFilter(v2object.FilterHeaderSplitID,
|
|
|
|
objectSDK.NewSplitID().String(),
|
|
|
|
objectSDK.MatchStringEqual)
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-10 13:17:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDB_SelectContainerID(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
cnr := cidtest.ID()
|
2020-12-10 13:17:45 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
obj1 := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, obj1)
|
2020-12-10 13:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
obj2 := generateObjectWithCID(t, cnr)
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, obj2)
|
2020-12-10 13:17:45 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
t.Run("same cid", func(t *testing.T) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, cnr)
|
2020-12-10 13:17:45 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(obj1),
|
|
|
|
object.AddressOf(obj2),
|
2020-12-10 13:17:45 +00:00
|
|
|
)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringNotEqual, cnr)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs,
|
2022-03-03 14:19:05 +00:00
|
|
|
object.AddressOf(obj1),
|
|
|
|
object.AddressOf(obj2),
|
2021-02-01 21:00:40 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
fs = objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchNotPresent, cnr)
|
2021-02-01 21:00:40 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-10 13:17:45 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not same cid", func(t *testing.T) {
|
2022-05-31 17:00:41 +00:00
|
|
|
newCnr := cidtest.ID()
|
2020-12-10 13:17:45 +00:00
|
|
|
|
|
|
|
fs := objectSDK.SearchFilters{}
|
2022-05-31 17:00:41 +00:00
|
|
|
fs.AddObjectContainerIDFilter(objectSDK.MatchStringEqual, newCnr)
|
2020-12-10 13:17:45 +00:00
|
|
|
|
2022-05-31 17:00:41 +00:00
|
|
|
testSelect(t, db, cnr, fs)
|
2020-12-08 07:51:34 +00:00
|
|
|
})
|
2020-11-20 07:43:41 +00:00
|
|
|
}
|
2022-05-25 12:56:45 +00:00
|
|
|
|
|
|
|
func BenchmarkSelect(b *testing.B) {
|
|
|
|
const objCount = 1000
|
|
|
|
db := newDB(b)
|
|
|
|
cid := cidtest.ID()
|
|
|
|
|
|
|
|
for i := 0; i < objCount; i++ {
|
|
|
|
var attr objectSDK.Attribute
|
|
|
|
attr.SetKey("myHeader")
|
|
|
|
attr.SetValue(strconv.Itoa(i))
|
|
|
|
obj := generateObjectWithCID(b, cid)
|
|
|
|
obj.SetAttributes(attr)
|
|
|
|
require.NoError(b, meta.Put(db, obj, nil))
|
|
|
|
}
|
|
|
|
|
|
|
|
b.Run("string equal", func(b *testing.B) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("myHeader", strconv.Itoa(objCount/2), objectSDK.MatchStringEqual)
|
|
|
|
benchmarkSelect(b, db, cid, fs, 1)
|
|
|
|
})
|
|
|
|
b.Run("string not equal", func(b *testing.B) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("myHeader", strconv.Itoa(objCount/2), objectSDK.MatchStringNotEqual)
|
|
|
|
benchmarkSelect(b, db, cid, fs, objCount-1)
|
|
|
|
})
|
|
|
|
b.Run("common prefix", func(b *testing.B) {
|
|
|
|
prefix := "99"
|
|
|
|
n := 1 /* 99 */ + 10 /* 990..999 */
|
|
|
|
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("myHeader", prefix, objectSDK.MatchCommonPrefix)
|
|
|
|
benchmarkSelect(b, db, cid, fs, n)
|
|
|
|
})
|
|
|
|
b.Run("unknown", func(b *testing.B) {
|
|
|
|
fs := objectSDK.SearchFilters{}
|
|
|
|
fs.AddFilter("myHeader", strconv.Itoa(objCount/2), objectSDK.MatchUnknown)
|
|
|
|
benchmarkSelect(b, db, cid, fs, 0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func benchmarkSelect(b *testing.B, db *meta.DB, cid cidSDK.ID, fs objectSDK.SearchFilters, expected int) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
res, err := meta.Select(db, &cid, fs)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
if len(res) != expected {
|
|
|
|
b.Fatalf("expected %d items, got %d", expected, len(res))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|