query_coord_test.go 3.0 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

import (
	"context"
16 17
	"math/rand"
	"strconv"
X
xige-16 已提交
18
	"testing"
19
	"time"
X
xige-16 已提交
20 21

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

X
Xiangyu Wang 已提交
23
	"github.com/milvus-io/milvus/internal/msgstream"
X
xige-16 已提交
24 25
)

26 27
func setup() {
	Params.Init()
28 29 30
	rand.Seed(time.Now().UnixNano())
	suffix := "-test-query-Coord" + strconv.FormatInt(rand.Int63(), 10)
	Params.MetaRootPath = Params.MetaRootPath + suffix
31 32 33 34 35 36 37 38 39
}

func refreshChannelNames() {
	suffix := "-test-query-Coord" + strconv.FormatInt(rand.Int63n(1000000), 10)
	Params.StatsChannelName = Params.StatsChannelName + suffix
	Params.TimeTickChannelName = Params.TimeTickChannelName + suffix
}

func TestMain(m *testing.M) {
G
godchen 已提交
40 41 42 43 44 45
	/*
		setup()
		//refreshChannelNames()
		exitCode := m.Run()
		os.Exit(exitCode)
	*/
46 47
}

48
func TestQueryCoord_Init(t *testing.T) {
G
godchen 已提交
49
	ctx := context.Background()
X
Xiangyu Wang 已提交
50
	msFactory := msgstream.NewPmsFactory()
51
	service, err := NewQueryCoord(context.Background(), msFactory)
X
xige-16 已提交
52
	assert.Nil(t, err)
53
	service.Register()
X
xige-16 已提交
54 55 56 57
	service.Init()
	service.Start()

	t.Run("Test Get statistics channel", func(t *testing.T) {
G
godchen 已提交
58
		response, err := service.GetStatisticsChannel(ctx)
X
xige-16 已提交
59
		assert.Nil(t, err)
60
		assert.Equal(t, response.Value, "query-node-stats")
X
xige-16 已提交
61 62 63
	})

	t.Run("Test Get timeTick channel", func(t *testing.T) {
G
godchen 已提交
64
		response, err := service.GetTimeTickChannel(ctx)
X
xige-16 已提交
65
		assert.Nil(t, err)
66
		assert.Equal(t, response.Value, "queryTimeTick")
X
xige-16 已提交
67 68 69 70
	})

	service.Stop()
}
71

72 73 74 75 76 77 78
//func TestQueryCoord_load(t *testing.T) {
//	ctx := context.Background()
//	msFactory := msgstream.NewPmsFactory()
//	service, err := NewQueryCoord(context.Background(), msFactory)
//	assert.Nil(t, err)
//	service.Init()
//	service.Start()
79
//	service.SetRootCoord(newRootCoordMock())
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
//	service.SetDataCoord(NewDataMock())
//	registerNodeRequest := &querypb.RegisterNodeRequest{
//		Address: &commonpb.Address{},
//	}
//	service.RegisterNode(ctx, registerNodeRequest)
//
//	t.Run("Test LoadSegment", func(t *testing.T) {
//		loadCollectionRequest := &querypb.LoadCollectionRequest{
//			CollectionID: 1,
//		}
//		response, err := service.LoadCollection(ctx, loadCollectionRequest)
//		assert.Nil(t, err)
//		assert.Equal(t, response.ErrorCode, commonpb.ErrorCode_Success)
//	})
//
//	t.Run("Test LoadPartition", func(t *testing.T) {
//		loadPartitionRequest := &querypb.LoadPartitionsRequest{
//			CollectionID: 1,
//			PartitionIDs: []UniqueID{1},
//		}
//		response, err := service.LoadPartitions(ctx, loadPartitionRequest)
//		assert.Nil(t, err)
//		assert.Equal(t, response.ErrorCode, commonpb.ErrorCode_Success)
//	})
//}