frostfs-node/pkg/local_object_storage/metabase/graveyard_test.go
Leonard Lyubich d72d37a322 [#378] metabase: Implement iterator over metabase graveyard
Implement `DB.IterateOverGraveyard` method that iterates over all graves and
passes passes their descriptors (new type `Grave`) to handler (new type
`GraveHandler`). `Grave` currently have buried object address and garbage
flag.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2021-02-19 11:56:32 +03:00

66 lines
1.3 KiB
Go

package meta_test
import (
"testing"
"github.com/nspcc-dev/neofs-api-go/pkg/object"
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
"github.com/stretchr/testify/require"
)
func TestDB_IterateOverGraveyard(t *testing.T) {
db := newDB(t)
defer releaseDB(db)
// generate and put 2 objects
obj1 := generateRawObject(t)
obj2 := generateRawObject(t)
var err error
err = putBig(db, obj1.Object())
require.NoError(t, err)
err = putBig(db, obj2.Object())
require.NoError(t, err)
inhumePrm := new(meta.InhumePrm)
// inhume with tombstone
addrTombstone := generateAddress()
_, err = db.Inhume(inhumePrm.
WithAddresses(obj1.Object().Address()).
WithTombstoneAddress(addrTombstone),
)
require.NoError(t, err)
// inhume with GC mark
_, err = db.Inhume(inhumePrm.
WithAddresses(obj2.Object().Address()).
WithGCMark(),
)
var (
counterAll int
buriedTS, buriedGC []*object.Address
)
err = db.IterateOverGraveyard(func(g *meta.Grave) error {
if g.WithGCMark() {
buriedGC = append(buriedGC, g.Address())
} else {
buriedTS = append(buriedTS, g.Address())
}
counterAll++
return nil
})
require.NoError(t, err)
require.Equal(t, 2, counterAll)
require.Equal(t, []*object.Address{obj1.Object().Address()}, buriedTS)
require.Equal(t, []*object.Address{obj2.Object().Address()}, buriedGC)
}