2021-04-19 11:35:38 +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-02-02 18:53:10 +08:00
|
|
|
package dataservice
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2021-02-02 18:53:10 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-04-08 15:08:34 +08:00
|
|
|
"golang.org/x/net/context"
|
2021-02-02 18:53:10 +08:00
|
|
|
)
|
|
|
|
|
2021-04-08 15:08:34 +08:00
|
|
|
func TestDataNodeClusterRegister(t *testing.T) {
|
|
|
|
Params.Init()
|
2021-04-13 09:47:02 +08:00
|
|
|
cluster := newDataNodeCluster()
|
2021-04-22 11:04:59 +08:00
|
|
|
dataNodeNum := 3
|
|
|
|
ids := make([]int64, 0, dataNodeNum)
|
|
|
|
for i := 0; i < dataNodeNum; i++ {
|
2021-05-25 15:47:08 +08:00
|
|
|
c, err := newMockDataNodeClient(int64(i))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = c.Init()
|
2021-04-08 15:08:34 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = c.Start()
|
|
|
|
assert.Nil(t, err)
|
|
|
|
cluster.Register(&dataNode{
|
|
|
|
id: int64(i),
|
|
|
|
address: struct {
|
|
|
|
ip string
|
|
|
|
port int64
|
|
|
|
}{"localhost", int64(9999 + i)},
|
|
|
|
client: c,
|
|
|
|
channelNum: 0,
|
|
|
|
})
|
|
|
|
ids = append(ids, int64(i))
|
|
|
|
}
|
2021-04-22 11:04:59 +08:00
|
|
|
assert.EqualValues(t, dataNodeNum, cluster.GetNumOfNodes())
|
2021-04-08 15:08:34 +08:00
|
|
|
assert.EqualValues(t, ids, cluster.GetNodeIDs())
|
|
|
|
states, err := cluster.GetDataNodeStates(context.TODO())
|
|
|
|
assert.Nil(t, err)
|
2021-04-22 11:04:59 +08:00
|
|
|
assert.EqualValues(t, dataNodeNum, len(states))
|
2021-04-08 15:08:34 +08:00
|
|
|
for _, s := range states {
|
|
|
|
assert.EqualValues(t, internalpb.StateCode_Healthy, s.StateCode)
|
|
|
|
}
|
|
|
|
cluster.ShutDownClients()
|
|
|
|
states, err = cluster.GetDataNodeStates(context.TODO())
|
|
|
|
assert.Nil(t, err)
|
2021-04-22 11:04:59 +08:00
|
|
|
assert.EqualValues(t, dataNodeNum, len(states))
|
2021-04-08 15:08:34 +08:00
|
|
|
for _, s := range states {
|
|
|
|
assert.EqualValues(t, internalpb.StateCode_Abnormal, s.StateCode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 18:53:10 +08:00
|
|
|
func TestWatchChannels(t *testing.T) {
|
|
|
|
Params.Init()
|
2021-04-22 11:04:59 +08:00
|
|
|
dataNodeNum := 3
|
2021-02-02 18:53:10 +08:00
|
|
|
cases := []struct {
|
|
|
|
collectionID UniqueID
|
|
|
|
channels []string
|
|
|
|
channelNums []int
|
|
|
|
}{
|
|
|
|
{1, []string{"c1"}, []int{1, 0, 0}},
|
|
|
|
{1, []string{"c1", "c2", "c3"}, []int{1, 1, 1}},
|
|
|
|
{1, []string{"c1", "c2", "c3", "c4"}, []int{2, 1, 1}},
|
|
|
|
{1, []string{"c1", "c2", "c3", "c4", "c5", "c6", "c7"}, []int{3, 2, 2}},
|
|
|
|
}
|
|
|
|
|
2021-04-13 09:47:02 +08:00
|
|
|
cluster := newDataNodeCluster()
|
2021-02-02 18:53:10 +08:00
|
|
|
for _, c := range cases {
|
2021-04-22 11:04:59 +08:00
|
|
|
for i := 0; i < dataNodeNum; i++ {
|
2021-05-25 15:47:08 +08:00
|
|
|
c, err := newMockDataNodeClient(int64(i))
|
|
|
|
assert.Nil(t, err)
|
|
|
|
err = c.Init()
|
2021-04-08 15:08:34 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
err = c.Start()
|
|
|
|
assert.Nil(t, err)
|
2021-02-02 18:53:10 +08:00
|
|
|
cluster.Register(&dataNode{
|
|
|
|
id: int64(i),
|
|
|
|
address: struct {
|
|
|
|
ip string
|
|
|
|
port int64
|
|
|
|
}{"localhost", int64(9999 + i)},
|
2021-04-08 15:08:34 +08:00
|
|
|
client: c,
|
2021-02-02 18:53:10 +08:00
|
|
|
channelNum: 0,
|
|
|
|
})
|
|
|
|
}
|
2021-02-03 17:30:10 +08:00
|
|
|
cluster.WatchInsertChannels(c.channels)
|
2021-02-02 18:53:10 +08:00
|
|
|
for i := 0; i < len(cluster.nodes); i++ {
|
|
|
|
assert.EqualValues(t, c.channelNums[i], cluster.nodes[i].channelNum)
|
|
|
|
}
|
|
|
|
cluster.Clear()
|
|
|
|
}
|
|
|
|
}
|