2021-01-15 08:33:09 +00:00
|
|
|
package control_test
|
|
|
|
|
|
|
|
import (
|
2021-12-17 15:24:19 +00:00
|
|
|
"bytes"
|
2021-01-15 08:33:09 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/control"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHealthCheckResponse_Body_StableMarshal(t *testing.T) {
|
|
|
|
testStableMarshal(t,
|
|
|
|
generateHealthCheckResponseBody(),
|
|
|
|
new(control.HealthCheckResponse_Body),
|
|
|
|
func(m1, m2 protoMessage) bool {
|
|
|
|
return equalHealthCheckResponseBodies(
|
|
|
|
m1.(*control.HealthCheckResponse_Body),
|
|
|
|
m2.(*control.HealthCheckResponse_Body),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateHealthCheckResponseBody() *control.HealthCheckResponse_Body {
|
|
|
|
body := new(control.HealthCheckResponse_Body)
|
2021-01-15 09:42:31 +00:00
|
|
|
body.SetNetmapStatus(control.NetmapStatus_ONLINE)
|
2021-01-15 10:18:03 +00:00
|
|
|
body.SetHealthStatus(control.HealthStatus_SHUTTING_DOWN)
|
2021-01-15 08:33:09 +00:00
|
|
|
|
|
|
|
return body
|
|
|
|
}
|
|
|
|
|
|
|
|
func equalHealthCheckResponseBodies(b1, b2 *control.HealthCheckResponse_Body) bool {
|
2021-01-15 10:18:03 +00:00
|
|
|
return b1.GetNetmapStatus() == b2.GetNetmapStatus() &&
|
|
|
|
b1.GetHealthStatus() == b2.GetHealthStatus()
|
2021-01-15 08:33:09 +00:00
|
|
|
}
|
|
|
|
|
2021-01-15 11:51:15 +00:00
|
|
|
func TestSetNetmapStatusRequest_Body_StableMarshal(t *testing.T) {
|
|
|
|
testStableMarshal(t,
|
|
|
|
generateSetNetmapStatusRequestBody(),
|
|
|
|
new(control.SetNetmapStatusRequest_Body),
|
|
|
|
func(m1, m2 protoMessage) bool {
|
|
|
|
return equalSetnetmapStatusRequestBodies(
|
|
|
|
m1.(*control.SetNetmapStatusRequest_Body),
|
|
|
|
m2.(*control.SetNetmapStatusRequest_Body),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateSetNetmapStatusRequestBody() *control.SetNetmapStatusRequest_Body {
|
|
|
|
body := new(control.SetNetmapStatusRequest_Body)
|
|
|
|
body.SetStatus(control.NetmapStatus_ONLINE)
|
|
|
|
|
|
|
|
return body
|
|
|
|
}
|
|
|
|
|
|
|
|
func equalSetnetmapStatusRequestBodies(b1, b2 *control.SetNetmapStatusRequest_Body) bool {
|
|
|
|
return b1.GetStatus() == b2.GetStatus()
|
|
|
|
}
|
2021-12-17 15:24:19 +00:00
|
|
|
|
|
|
|
func TestListShardsResponse_Body_StableMarshal(t *testing.T) {
|
|
|
|
testStableMarshal(t,
|
|
|
|
generateListShardsResponseBody(),
|
|
|
|
new(control.ListShardsResponse_Body),
|
|
|
|
func(m1, m2 protoMessage) bool {
|
|
|
|
return equalListShardResponseBodies(
|
|
|
|
m1.(*control.ListShardsResponse_Body),
|
|
|
|
m2.(*control.ListShardsResponse_Body),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func equalListShardResponseBodies(b1, b2 *control.ListShardsResponse_Body) bool {
|
|
|
|
if len(b1.Shards) != len(b2.Shards) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range b1.Shards {
|
|
|
|
if b1.Shards[i].GetMetabasePath() != b2.Shards[i].GetMetabasePath() ||
|
|
|
|
b1.Shards[i].GetWritecachePath() != b2.Shards[i].GetWritecachePath() ||
|
2022-05-16 13:23:09 +00:00
|
|
|
b1.Shards[i].GetPiloramaPath() != b2.Shards[i].GetPiloramaPath() ||
|
2021-12-17 15:24:19 +00:00
|
|
|
!bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[i].GetShard_ID()) {
|
|
|
|
return false
|
|
|
|
}
|
2022-10-05 12:41:36 +00:00
|
|
|
|
|
|
|
info1 := b1.Shards[i].GetBlobstor()
|
|
|
|
info2 := b2.Shards[i].GetBlobstor()
|
|
|
|
return compareBlobstorInfo(info1, info2)
|
2021-12-17 15:24:19 +00:00
|
|
|
}
|
|
|
|
|
2022-05-16 13:30:53 +00:00
|
|
|
for i := range b1.Shards {
|
|
|
|
for j := i + 1; j < len(b1.Shards); j++ {
|
|
|
|
if b1.Shards[i].GetMetabasePath() == b2.Shards[j].GetMetabasePath() ||
|
2022-10-05 12:41:36 +00:00
|
|
|
!compareBlobstorInfo(b1.Shards[i].Blobstor, b2.Shards[i].Blobstor) ||
|
2022-05-16 13:30:53 +00:00
|
|
|
b1.Shards[i].GetWritecachePath() == b2.Shards[j].GetWritecachePath() ||
|
|
|
|
bytes.Equal(b1.Shards[i].GetShard_ID(), b2.Shards[j].GetShard_ID()) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 15:24:19 +00:00
|
|
|
return true
|
|
|
|
}
|
2022-10-05 12:41:36 +00:00
|
|
|
func compareBlobstorInfo(a, b []*control.BlobstorInfo) bool {
|
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i := range a {
|
|
|
|
if a[i].Type != b[i].Type ||
|
|
|
|
a[i].Path != b[i].Path {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2021-12-17 15:24:19 +00:00
|
|
|
|
|
|
|
func generateListShardsResponseBody() *control.ListShardsResponse_Body {
|
|
|
|
body := new(control.ListShardsResponse_Body)
|
|
|
|
body.SetShards([]*control.ShardInfo{
|
2022-05-16 13:30:53 +00:00
|
|
|
generateShardInfo(0),
|
|
|
|
generateShardInfo(1),
|
2021-12-17 15:24:19 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return body
|
|
|
|
}
|
2021-12-27 16:18:53 +00:00
|
|
|
|
|
|
|
func TestSetShardModeRequest_Body_StableMarshal(t *testing.T) {
|
|
|
|
testStableMarshal(t,
|
|
|
|
generateSetShardModeRequestBody(),
|
|
|
|
new(control.SetShardModeRequest_Body),
|
|
|
|
func(m1, m2 protoMessage) bool {
|
|
|
|
return equalSetShardModeRequestBodies(
|
|
|
|
m1.(*control.SetShardModeRequest_Body),
|
|
|
|
m2.(*control.SetShardModeRequest_Body),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateSetShardModeRequestBody() *control.SetShardModeRequest_Body {
|
|
|
|
body := new(control.SetShardModeRequest_Body)
|
2022-10-10 17:54:14 +00:00
|
|
|
body.SetShardIDList([][]byte{{0, 1, 2, 3, 4}})
|
2021-12-27 16:18:53 +00:00
|
|
|
body.SetMode(control.ShardMode_READ_WRITE)
|
|
|
|
|
|
|
|
return body
|
|
|
|
}
|
|
|
|
|
|
|
|
func equalSetShardModeRequestBodies(b1, b2 *control.SetShardModeRequest_Body) bool {
|
2022-10-10 17:54:14 +00:00
|
|
|
if b1.GetMode() != b2.GetMode() || len(b1.Shard_ID) != len(b2.Shard_ID) {
|
2021-12-27 16:18:53 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2022-10-10 17:54:14 +00:00
|
|
|
for i := range b1.Shard_ID {
|
|
|
|
if !bytes.Equal(b1.Shard_ID[i], b2.Shard_ID[i]) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-27 16:18:53 +00:00
|
|
|
return true
|
|
|
|
}
|
2022-05-16 16:31:50 +00:00
|
|
|
|
|
|
|
func TestSynchronizeTreeRequest_Body_StableMarshal(t *testing.T) {
|
|
|
|
testStableMarshal(t,
|
|
|
|
&control.SynchronizeTreeRequest_Body{
|
|
|
|
ContainerId: []byte{1, 2, 3, 4, 5, 6, 7},
|
|
|
|
TreeId: "someID",
|
|
|
|
Height: 42,
|
|
|
|
},
|
|
|
|
new(control.SynchronizeTreeRequest_Body),
|
|
|
|
func(m1, m2 protoMessage) bool {
|
|
|
|
b1 := m1.(*control.SynchronizeTreeRequest_Body)
|
|
|
|
b2 := m2.(*control.SynchronizeTreeRequest_Body)
|
|
|
|
return bytes.Equal(b1.GetContainerId(), b2.GetContainerId()) &&
|
|
|
|
b1.GetTreeId() == b2.GetTreeId() &&
|
|
|
|
b1.GetHeight() == b2.GetHeight()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|