query_coord_test.go 2.8 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 querycoord
X
xige-16 已提交
13 14 15 16 17 18

import (
	"context"
	"testing"

	"github.com/stretchr/testify/assert"
19

X
Xiangyu Wang 已提交
20 21 22
	"github.com/milvus-io/milvus/internal/msgstream"
	"github.com/milvus-io/milvus/internal/proto/commonpb"
	"github.com/milvus-io/milvus/internal/proto/querypb"
X
xige-16 已提交
23 24
)

25
func TestQueryCoord_Init(t *testing.T) {
G
godchen 已提交
26
	ctx := context.Background()
X
Xiangyu Wang 已提交
27
	msFactory := msgstream.NewPmsFactory()
28
	service, err := NewQueryCoord(context.Background(), msFactory)
X
xige-16 已提交
29 30 31 32 33
	assert.Nil(t, err)
	service.Init()
	service.Start()

	t.Run("Test create channel", func(t *testing.T) {
34 35
		request := &querypb.CreateQueryChannelRequest{}
		response, err := service.CreateQueryChannel(ctx, request)
X
xige-16 已提交
36 37 38 39 40 41
		assert.Nil(t, err)
		assert.Equal(t, response.RequestChannel, "query-0")
		assert.Equal(t, response.ResultChannel, "queryResult-0")
	})

	t.Run("Test Get statistics channel", func(t *testing.T) {
G
godchen 已提交
42
		response, err := service.GetStatisticsChannel(ctx)
X
xige-16 已提交
43 44 45 46 47
		assert.Nil(t, err)
		assert.Equal(t, response, "query-node-stats")
	})

	t.Run("Test Get timeTick channel", func(t *testing.T) {
G
godchen 已提交
48
		response, err := service.GetTimeTickChannel(ctx)
X
xige-16 已提交
49 50 51 52 53 54
		assert.Nil(t, err)
		assert.Equal(t, response, "queryTimeTick")
	})

	service.Stop()
}
55

56
func TestQueryCoord_load(t *testing.T) {
G
godchen 已提交
57
	ctx := context.Background()
X
Xiangyu Wang 已提交
58
	msFactory := msgstream.NewPmsFactory()
59
	service, err := NewQueryCoord(context.Background(), msFactory)
60 61 62
	assert.Nil(t, err)
	service.Init()
	service.Start()
63
	service.SetRootCoord(NewRootCoordMock())
64
	service.SetDataCoord(NewDataMock())
65 66 67
	registerNodeRequest := &querypb.RegisterNodeRequest{
		Address: &commonpb.Address{},
	}
G
godchen 已提交
68
	service.RegisterNode(ctx, registerNodeRequest)
69 70 71 72 73

	t.Run("Test LoadSegment", func(t *testing.T) {
		loadCollectionRequest := &querypb.LoadCollectionRequest{
			CollectionID: 1,
		}
G
godchen 已提交
74
		response, err := service.LoadCollection(ctx, loadCollectionRequest)
75
		assert.Nil(t, err)
76
		assert.Equal(t, response.ErrorCode, commonpb.ErrorCode_Success)
77 78 79
	})

	t.Run("Test LoadPartition", func(t *testing.T) {
G
godchen 已提交
80
		loadPartitionRequest := &querypb.LoadPartitionsRequest{
81 82 83
			CollectionID: 1,
			PartitionIDs: []UniqueID{1},
		}
G
godchen 已提交
84
		response, err := service.LoadPartitions(ctx, loadPartitionRequest)
85
		assert.Nil(t, err)
86
		assert.Equal(t, response.ErrorCode, commonpb.ErrorCode_Success)
87 88
	})
}