[#574] core: Extend Source interface with DeletionInfo method
* Introduce common method EverExisted * Define DeletionInfo for struct that must implement Source * Refactor tree srv Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
9072772a09
commit
554ff2c06b
8 changed files with 115 additions and 43 deletions
|
@ -34,8 +34,13 @@ func TestBuryObjectWithoutContainer(t *testing.T) {
|
|||
|
||||
// Container source and bury function
|
||||
buryCh := make(chan oid.Address)
|
||||
containerSrc := func(id cid.ID) (*container.Container, error) {
|
||||
return nil, new(apistatus.ContainerNotFound)
|
||||
containerSrc := containerSrc{
|
||||
get: func(id cid.ID) (*container.Container, error) {
|
||||
return nil, new(apistatus.ContainerNotFound)
|
||||
},
|
||||
deletionInfo: func(id cid.ID) (*container.DelInfo, error) {
|
||||
return &container.DelInfo{}, nil
|
||||
},
|
||||
}
|
||||
buryFn := func(ctx context.Context, a oid.Address) error {
|
||||
buryCh <- a
|
||||
|
@ -49,7 +54,7 @@ func TestBuryObjectWithoutContainer(t *testing.T) {
|
|||
// Policer instance
|
||||
p := New(
|
||||
WithKeySpaceIterator(&sliceKeySpaceIterator{objs: objs}),
|
||||
WithContainerSource(containerSrcFunc(containerSrc)),
|
||||
WithContainerSource(containerSrc),
|
||||
WithBuryFunc(buryFn),
|
||||
WithPool(pool),
|
||||
)
|
||||
|
@ -194,12 +199,17 @@ func TestProcessObject(t *testing.T) {
|
|||
cnr := &container.Container{}
|
||||
cnr.Value.Init()
|
||||
cnr.Value.SetPlacementPolicy(policy)
|
||||
containerSrc := func(id cid.ID) (*container.Container, error) {
|
||||
if id.Equals(addr.Container()) {
|
||||
return cnr, nil
|
||||
}
|
||||
t.Errorf("unexpected container requested: got=%v, want=%v", id, addr.Container())
|
||||
return nil, new(apistatus.ContainerNotFound)
|
||||
containerSrc := containerSrc{
|
||||
get: func(id cid.ID) (*container.Container, error) {
|
||||
if id.Equals(addr.Container()) {
|
||||
return cnr, nil
|
||||
}
|
||||
t.Errorf("unexpected container requested: got=%v, want=%v", id, addr.Container())
|
||||
return nil, new(apistatus.ContainerNotFound)
|
||||
},
|
||||
deletionInfo: func(id cid.ID) (*container.DelInfo, error) {
|
||||
return &container.DelInfo{}, nil
|
||||
},
|
||||
}
|
||||
buryFn := func(ctx context.Context, a oid.Address) error {
|
||||
t.Errorf("unexpected object buried: %v", a)
|
||||
|
@ -211,7 +221,7 @@ func TestProcessObject(t *testing.T) {
|
|||
var gotReplicateTo []int
|
||||
|
||||
p := New(
|
||||
WithContainerSource(containerSrcFunc(containerSrc)),
|
||||
WithContainerSource(containerSrc),
|
||||
WithPlacementBuilder(placementBuilderFunc(placementBuilder)),
|
||||
WithNetmapKeys(announcedKeysFunc(func(k []byte) bool {
|
||||
return bytes.Equal(k, nodes[0].PublicKey())
|
||||
|
@ -251,9 +261,6 @@ func TestIteratorContract(t *testing.T) {
|
|||
Type: objectSDK.TypeRegular,
|
||||
}}
|
||||
|
||||
containerSrc := func(id cid.ID) (*container.Container, error) {
|
||||
return nil, new(apistatus.ContainerNotFound)
|
||||
}
|
||||
buryFn := func(ctx context.Context, a oid.Address) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -273,9 +280,18 @@ func TestIteratorContract(t *testing.T) {
|
|||
finishCh: make(chan struct{}),
|
||||
}
|
||||
|
||||
containerSrc := containerSrc{
|
||||
get: func(id cid.ID) (*container.Container, error) {
|
||||
return nil, new(apistatus.ContainerNotFound)
|
||||
},
|
||||
deletionInfo: func(id cid.ID) (*container.DelInfo, error) {
|
||||
return &container.DelInfo{}, nil
|
||||
},
|
||||
}
|
||||
|
||||
p := New(
|
||||
WithKeySpaceIterator(it),
|
||||
WithContainerSource(containerSrcFunc(containerSrc)),
|
||||
WithContainerSource(containerSrc),
|
||||
WithBuryFunc(buryFn),
|
||||
WithPool(pool),
|
||||
func(c *cfg) {
|
||||
|
@ -353,10 +369,14 @@ func (it *sliceKeySpaceIterator) Rewind() {
|
|||
it.cur = 0
|
||||
}
|
||||
|
||||
// containerSrcFunc is a container.Source backed by a function.
|
||||
type containerSrcFunc func(cid.ID) (*container.Container, error)
|
||||
type containerSrc struct {
|
||||
get func(id cid.ID) (*container.Container, error)
|
||||
deletionInfo func(id cid.ID) (*container.DelInfo, error)
|
||||
}
|
||||
|
||||
func (f containerSrcFunc) Get(id cid.ID) (*container.Container, error) { return f(id) }
|
||||
func (f containerSrc) Get(id cid.ID) (*container.Container, error) { return f.get(id) }
|
||||
|
||||
func (f containerSrc) DeletionInfo(id cid.ID) (*container.DelInfo, error) { return f.deletionInfo(id) }
|
||||
|
||||
// placementBuilderFunc is a placement.Builder backed by a function
|
||||
type placementBuilderFunc func(cid.ID, *oid.ID, netmap.PlacementPolicy) ([][]netmap.NodeInfo, error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue