[#250] pkg/container: Add epoch field to size announce body
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
e27d76e804
commit
9e01f29dda
2 changed files with 17 additions and 2 deletions
|
@ -19,6 +19,16 @@ func NewAnnouncementFromV2(v *container.UsedSpaceAnnouncement) *UsedSpaceAnnounc
|
||||||
return (*UsedSpaceAnnouncement)(v)
|
return (*UsedSpaceAnnouncement)(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Epoch of the announcement.
|
||||||
|
func (a *UsedSpaceAnnouncement) Epoch() uint64 {
|
||||||
|
return (*container.UsedSpaceAnnouncement)(a).GetEpoch()
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetEpoch sets announcement epoch value.
|
||||||
|
func (a *UsedSpaceAnnouncement) SetEpoch(epoch uint64) {
|
||||||
|
(*container.UsedSpaceAnnouncement)(a).SetEpoch(epoch)
|
||||||
|
}
|
||||||
|
|
||||||
// ContainerID of the announcement.
|
// ContainerID of the announcement.
|
||||||
func (a *UsedSpaceAnnouncement) ContainerID() *ID {
|
func (a *UsedSpaceAnnouncement) ContainerID() *ID {
|
||||||
return NewIDFromV2(
|
return NewIDFromV2(
|
||||||
|
|
|
@ -9,21 +9,23 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAnnouncement(t *testing.T) {
|
func TestAnnouncement(t *testing.T) {
|
||||||
const usedSpace uint64 = 100
|
const epoch, usedSpace uint64 = 10, 100
|
||||||
|
|
||||||
cidValue := [32]byte{1, 2, 3}
|
cidValue := [32]byte{1, 2, 3}
|
||||||
cid := container.NewID()
|
cid := container.NewID()
|
||||||
cid.SetSHA256(cidValue)
|
cid.SetSHA256(cidValue)
|
||||||
|
|
||||||
a := container.NewAnnouncement()
|
a := container.NewAnnouncement()
|
||||||
|
a.SetEpoch(epoch)
|
||||||
a.SetContainerID(cid)
|
a.SetContainerID(cid)
|
||||||
a.SetUsedSpace(usedSpace)
|
a.SetUsedSpace(usedSpace)
|
||||||
|
|
||||||
|
require.Equal(t, epoch, a.Epoch())
|
||||||
require.Equal(t, usedSpace, a.UsedSpace())
|
require.Equal(t, usedSpace, a.UsedSpace())
|
||||||
require.Equal(t, cid, a.ContainerID())
|
require.Equal(t, cid, a.ContainerID())
|
||||||
|
|
||||||
t.Run("test v2", func(t *testing.T) {
|
t.Run("test v2", func(t *testing.T) {
|
||||||
const newUsedSpace uint64 = 200
|
const newEpoch, newUsedSpace uint64 = 20, 200
|
||||||
|
|
||||||
newCidValue := [32]byte{4, 5, 6}
|
newCidValue := [32]byte{4, 5, 6}
|
||||||
newCID := new(refs.ContainerID)
|
newCID := new(refs.ContainerID)
|
||||||
|
@ -31,13 +33,16 @@ func TestAnnouncement(t *testing.T) {
|
||||||
|
|
||||||
v2 := a.ToV2()
|
v2 := a.ToV2()
|
||||||
require.Equal(t, usedSpace, v2.GetUsedSpace())
|
require.Equal(t, usedSpace, v2.GetUsedSpace())
|
||||||
|
require.Equal(t, epoch, v2.GetEpoch())
|
||||||
require.Equal(t, cidValue[:], v2.GetContainerID().GetValue())
|
require.Equal(t, cidValue[:], v2.GetContainerID().GetValue())
|
||||||
|
|
||||||
|
v2.SetEpoch(newEpoch)
|
||||||
v2.SetUsedSpace(newUsedSpace)
|
v2.SetUsedSpace(newUsedSpace)
|
||||||
v2.SetContainerID(newCID)
|
v2.SetContainerID(newCID)
|
||||||
|
|
||||||
newA := container.NewAnnouncementFromV2(v2)
|
newA := container.NewAnnouncementFromV2(v2)
|
||||||
|
|
||||||
|
require.Equal(t, newEpoch, newA.Epoch())
|
||||||
require.Equal(t, newUsedSpace, newA.UsedSpace())
|
require.Equal(t, newUsedSpace, newA.UsedSpace())
|
||||||
require.Equal(t, container.NewIDFromV2(newCID), newA.ContainerID())
|
require.Equal(t, container.NewIDFromV2(newCID), newA.ContainerID())
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue