2020-11-23 13:30:56 +00:00
|
|
|
package meta_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
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-07-12 14:42:55 +00:00
|
|
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
2020-11-23 13:30:56 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestDB_Movable(t *testing.T) {
|
|
|
|
db := newDB(t)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
raw1 := generateObject(t)
|
|
|
|
raw2 := generateObject(t)
|
2020-11-23 13:30:56 +00:00
|
|
|
|
|
|
|
// put two objects in metabase
|
2022-03-03 14:19:05 +00:00
|
|
|
err := putBig(db, raw1)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-03-03 14:19:05 +00:00
|
|
|
err = putBig(db, raw2)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index empty
|
2022-07-12 14:42:55 +00:00
|
|
|
toMoveList, err := metaMovable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 0)
|
|
|
|
|
|
|
|
// mark to move object2
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaToMoveIt(db, object.AddressOf(raw2))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index contains address of object 2
|
2022-07-12 14:42:55 +00:00
|
|
|
toMoveList, err = metaMovable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 1)
|
2022-03-03 14:19:05 +00:00
|
|
|
require.Contains(t, toMoveList, object.AddressOf(raw2))
|
2020-11-23 13:30:56 +00:00
|
|
|
|
|
|
|
// remove from toMoveIt index non existing address
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaDoNotMove(db, object.AddressOf(raw1))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index hasn't changed
|
2022-07-12 14:42:55 +00:00
|
|
|
toMoveList, err = metaMovable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 1)
|
|
|
|
|
|
|
|
// remove from toMoveIt index existing address
|
2022-07-12 14:42:55 +00:00
|
|
|
err = metaDoNotMove(db, object.AddressOf(raw2))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index is empty now
|
2022-07-12 14:42:55 +00:00
|
|
|
toMoveList, err = metaMovable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 0)
|
|
|
|
}
|
2022-07-12 14:42:55 +00:00
|
|
|
|
|
|
|
func metaToMoveIt(db *meta.DB, addr oid.Address) error {
|
|
|
|
var toMovePrm meta.ToMoveItPrm
|
|
|
|
toMovePrm.WithAddress(addr)
|
|
|
|
|
|
|
|
_, err := db.ToMoveIt(toMovePrm)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func metaMovable(db *meta.DB) ([]oid.Address, error) {
|
|
|
|
r, err := db.Movable(meta.MovablePrm{})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.AddressList(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func metaDoNotMove(db *meta.DB, addr oid.Address) error {
|
|
|
|
var doNotMovePrm meta.DoNotMovePrm
|
|
|
|
doNotMovePrm.WithAddress(addr)
|
|
|
|
|
|
|
|
_, err := db.DoNotMove(doNotMovePrm)
|
|
|
|
return err
|
|
|
|
}
|