forked from TrueCloudLab/frostfs-node
52 lines
1 KiB
Go
52 lines
1 KiB
Go
package loadstorage
|
|
|
|
import (
|
|
"math/rand"
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/container"
|
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestStorage(t *testing.T) {
|
|
const epoch uint64 = 13
|
|
|
|
a := container.NewAnnouncement()
|
|
a.SetContainerID(cidtest.ID())
|
|
a.SetEpoch(epoch)
|
|
|
|
const opinionsNum = 100
|
|
|
|
s := New(Prm{})
|
|
|
|
opinions := make([]uint64, opinionsNum)
|
|
for i := range opinions {
|
|
opinions[i] = rand.Uint64()
|
|
|
|
a.SetUsedSpace(opinions[i])
|
|
|
|
require.NoError(t, s.Put(*a))
|
|
}
|
|
|
|
iterCounter := 0
|
|
|
|
err := s.Iterate(
|
|
func(ai container.UsedSpaceAnnouncement) bool {
|
|
return ai.Epoch() == epoch
|
|
},
|
|
func(ai container.UsedSpaceAnnouncement) error {
|
|
iterCounter++
|
|
|
|
require.Equal(t, epoch, ai.Epoch())
|
|
cnr1, _ := a.ContainerID()
|
|
cnr2, _ := ai.ContainerID()
|
|
require.Equal(t, cnr1, cnr2)
|
|
require.Equal(t, finalEstimation(opinions), ai.UsedSpace())
|
|
|
|
return nil
|
|
},
|
|
)
|
|
require.NoError(t, err)
|
|
require.Equal(t, 1, iterCounter)
|
|
}
|