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"
|
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
|
2020-12-08 09:56:14 +00:00
|
|
|
toMoveList, err := meta.Movable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 0)
|
|
|
|
|
|
|
|
// mark to move object2
|
2022-03-03 14:19:05 +00:00
|
|
|
err = meta.ToMoveIt(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
|
2020-12-08 09:56:14 +00:00
|
|
|
toMoveList, err = meta.Movable(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-03-03 14:19:05 +00:00
|
|
|
err = meta.DoNotMove(db, object.AddressOf(raw1))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index hasn't changed
|
2020-12-08 09:56:14 +00:00
|
|
|
toMoveList, err = meta.Movable(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-03-03 14:19:05 +00:00
|
|
|
err = meta.DoNotMove(db, object.AddressOf(raw2))
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// check if toMoveIt index is empty now
|
2020-12-08 09:56:14 +00:00
|
|
|
toMoveList, err = meta.Movable(db)
|
2020-11-23 13:30:56 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
require.Len(t, toMoveList, 0)
|
|
|
|
}
|