2021-05-28 16:48:31 +08:00
|
|
|
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
|
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
|
|
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
// or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
|
|
|
2021-06-22 10:42:07 +08:00
|
|
|
package datacoord
|
2021-05-28 15:13:51 +08:00
|
|
|
|
|
|
|
import (
|
2021-07-12 11:03:52 +08:00
|
|
|
"context"
|
2021-05-28 15:13:51 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-05-28 16:48:31 +08:00
|
|
|
func TestRandomReassign(t *testing.T) {
|
2021-06-23 14:28:08 +08:00
|
|
|
p := randomAssignRegisterFunc
|
2021-05-28 16:48:31 +08:00
|
|
|
|
2021-07-12 11:03:52 +08:00
|
|
|
clusters := make([]*NodeInfo, 0)
|
|
|
|
info1 := &datapb.DataNodeInfo{
|
2021-05-28 16:48:31 +08:00
|
|
|
Address: "addr1",
|
|
|
|
Channels: make([]*datapb.ChannelStatus, 0, 10),
|
|
|
|
}
|
2021-07-12 11:03:52 +08:00
|
|
|
info2 := &datapb.DataNodeInfo{
|
2021-05-28 16:48:31 +08:00
|
|
|
Address: "addr2",
|
|
|
|
Channels: make([]*datapb.ChannelStatus, 0, 10),
|
|
|
|
}
|
2021-07-12 11:03:52 +08:00
|
|
|
info3 := &datapb.DataNodeInfo{
|
2021-05-28 16:48:31 +08:00
|
|
|
Address: "addr3",
|
|
|
|
Channels: make([]*datapb.ChannelStatus, 0, 10),
|
|
|
|
}
|
|
|
|
|
2021-07-12 11:03:52 +08:00
|
|
|
node1 := NewNodeInfo(context.TODO(), info1)
|
|
|
|
node2 := NewNodeInfo(context.TODO(), info2)
|
|
|
|
node3 := NewNodeInfo(context.TODO(), info3)
|
|
|
|
clusters = append(clusters, node1, node2, node3)
|
|
|
|
|
|
|
|
caseInfo1 := &datapb.DataNodeInfo{
|
|
|
|
Channels: []*datapb.ChannelStatus{},
|
|
|
|
}
|
|
|
|
caseInfo2 := &datapb.DataNodeInfo{
|
|
|
|
Channels: []*datapb.ChannelStatus{
|
|
|
|
{Name: "VChan1", CollectionID: 1},
|
|
|
|
{Name: "VChan2", CollectionID: 2},
|
2021-05-28 16:48:31 +08:00
|
|
|
},
|
2021-07-12 11:03:52 +08:00
|
|
|
}
|
|
|
|
cases := []*NodeInfo{
|
|
|
|
{info: caseInfo1},
|
|
|
|
{info: caseInfo2},
|
2021-05-28 16:48:31 +08:00
|
|
|
nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, ca := range cases {
|
2021-07-12 11:03:52 +08:00
|
|
|
nodes := p(clusters, ca)
|
|
|
|
if ca == nil || len(ca.info.GetChannels()) == 0 {
|
2021-05-28 16:48:31 +08:00
|
|
|
assert.Equal(t, 0, len(nodes))
|
|
|
|
} else {
|
2021-07-12 11:03:52 +08:00
|
|
|
for _, ch := range ca.info.GetChannels() {
|
2021-05-28 16:48:31 +08:00
|
|
|
found := false
|
|
|
|
loop:
|
|
|
|
for _, node := range nodes {
|
2021-07-12 11:03:52 +08:00
|
|
|
for _, nch := range node.info.GetChannels() {
|
2021-05-28 16:48:31 +08:00
|
|
|
if nch.Name == ch.Name {
|
|
|
|
found = true
|
|
|
|
assert.EqualValues(t, datapb.ChannelWatchState_Uncomplete, nch.State)
|
|
|
|
break loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert.Equal(t, true, found)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|