policy_test.go 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// 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.

12
package datacoord
S
sunby 已提交
13 14

import (
S
sunby 已提交
15
	"context"
S
sunby 已提交
16 17 18 19 20 21
	"testing"

	"github.com/milvus-io/milvus/internal/proto/datapb"
	"github.com/stretchr/testify/assert"
)

22
func TestRandomReassign(t *testing.T) {
C
congqixia 已提交
23
	p := randomAssignRegisterFunc
24

S
sunby 已提交
25 26
	clusters := make([]*NodeInfo, 0)
	info1 := &datapb.DataNodeInfo{
27 28 29
		Address:  "addr1",
		Channels: make([]*datapb.ChannelStatus, 0, 10),
	}
S
sunby 已提交
30
	info2 := &datapb.DataNodeInfo{
31 32 33
		Address:  "addr2",
		Channels: make([]*datapb.ChannelStatus, 0, 10),
	}
S
sunby 已提交
34
	info3 := &datapb.DataNodeInfo{
35 36 37 38
		Address:  "addr3",
		Channels: make([]*datapb.ChannelStatus, 0, 10),
	}

S
sunby 已提交
39 40 41 42 43 44 45 46 47 48 49 50
	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},
51
		},
S
sunby 已提交
52 53 54 55
	}
	cases := []*NodeInfo{
		{info: caseInfo1},
		{info: caseInfo2},
56 57 58 59
		nil,
	}

	for _, ca := range cases {
S
sunby 已提交
60 61
		nodes := p(clusters, ca)
		if ca == nil || len(ca.info.GetChannels()) == 0 {
62 63
			assert.Equal(t, 0, len(nodes))
		} else {
S
sunby 已提交
64
			for _, ch := range ca.info.GetChannels() {
65 66 67
				found := false
			loop:
				for _, node := range nodes {
S
sunby 已提交
68
					for _, nch := range node.info.GetChannels() {
69 70 71 72 73 74 75 76 77 78 79 80
						if nch.Name == ch.Name {
							found = true
							assert.EqualValues(t, datapb.ChannelWatchState_Uncomplete, nch.State)
							break loop
						}
					}
				}
				assert.Equal(t, true, found)
			}
		}
	}
}