storj/satellite/metabase/rangedloop/rangedlooptest/infiniteprovider.go
Michal Niewrzal 4bdbb25d83 satellite/metabase/rangedloop: move Segment definition
We will remove segments loop soon so we need first to move
Segment definition to rangedloop package.

https://github.com/storj/storj/issues/5237

Change-Id: Ibe6aad316ffb7073cc4de166f1f17b87aac07363
2023-05-16 12:37:17 +00:00

41 lines
1.2 KiB
Go

// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package rangedlooptest
import (
"context"
"storj.io/storj/satellite/metabase/rangedloop"
)
var _ rangedloop.RangeSplitter = (*InfiniteSegmentProvider)(nil)
var _ rangedloop.SegmentProvider = (*InfiniteSegmentProvider)(nil)
// InfiniteSegmentProvider allow to iterate indefinitely to test service cancellation.
type InfiniteSegmentProvider struct {
}
// CreateRanges splits the segments into equal ranges.
func (m *InfiniteSegmentProvider) CreateRanges(nRanges int, batchSize int) (segmentsProviders []rangedloop.SegmentProvider, err error) {
for i := 0; i < nRanges; i++ {
segmentsProviders = append(segmentsProviders, &InfiniteSegmentProvider{})
}
return segmentsProviders, nil
}
// Range returns range which is processed by this provider.
func (m *InfiniteSegmentProvider) Range() rangedloop.UUIDRange {
return rangedloop.UUIDRange{}
}
// Iterate allows to loop over the segments stored in the provider.
func (m *InfiniteSegmentProvider) Iterate(ctx context.Context, fn func([]rangedloop.Segment) error) error {
for {
err := fn(make([]rangedloop.Segment, 3))
if err != nil {
return err
}
}
}