2021-04-19 13:47:10 +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 16:44:09 +08:00
|
|
|
package querycoord
|
2021-01-26 15:13:20 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-07-13 14:16:00 +08:00
|
|
|
"math/rand"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
2021-01-26 15:13:20 +08:00
|
|
|
"testing"
|
2021-07-16 10:21:55 +08:00
|
|
|
"time"
|
2021-01-26 15:13:20 +08:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2021-01-27 13:52:01 +08:00
|
|
|
|
2021-04-22 14:45:57 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/msgstream"
|
2021-01-26 15:13:20 +08:00
|
|
|
)
|
|
|
|
|
2021-07-13 14:16:00 +08:00
|
|
|
func setup() {
|
|
|
|
Params.Init()
|
2021-07-16 10:21:55 +08:00
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
suffix := "-test-query-Coord" + strconv.FormatInt(rand.Int63(), 10)
|
|
|
|
Params.MetaRootPath = Params.MetaRootPath + suffix
|
2021-07-13 14:16:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
setup()
|
|
|
|
//refreshChannelNames()
|
|
|
|
exitCode := m.Run()
|
|
|
|
os.Exit(exitCode)
|
|
|
|
}
|
|
|
|
|
2021-06-22 16:44:09 +08:00
|
|
|
func TestQueryCoord_Init(t *testing.T) {
|
2021-02-26 17:44:24 +08:00
|
|
|
ctx := context.Background()
|
2021-04-02 13:48:25 +08:00
|
|
|
msFactory := msgstream.NewPmsFactory()
|
2021-06-22 16:44:09 +08:00
|
|
|
service, err := NewQueryCoord(context.Background(), msFactory)
|
2021-01-26 15:13:20 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-13 14:16:00 +08:00
|
|
|
service.Register()
|
2021-01-26 15:13:20 +08:00
|
|
|
service.Init()
|
|
|
|
service.Start()
|
|
|
|
|
|
|
|
t.Run("Test Get statistics channel", func(t *testing.T) {
|
2021-02-26 17:44:24 +08:00
|
|
|
response, err := service.GetStatisticsChannel(ctx)
|
2021-01-26 15:13:20 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-13 14:16:00 +08:00
|
|
|
assert.Equal(t, response.Value, "query-node-stats")
|
2021-01-26 15:13:20 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("Test Get timeTick channel", func(t *testing.T) {
|
2021-02-26 17:44:24 +08:00
|
|
|
response, err := service.GetTimeTickChannel(ctx)
|
2021-01-26 15:13:20 +08:00
|
|
|
assert.Nil(t, err)
|
2021-07-13 14:16:00 +08:00
|
|
|
assert.Equal(t, response.Value, "queryTimeTick")
|
2021-01-26 15:13:20 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
service.Stop()
|
|
|
|
}
|
2021-01-27 13:52:01 +08:00
|
|
|
|
2021-06-23 17:44:12 +08:00
|
|
|
//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()
|
2021-07-13 14:16:00 +08:00
|
|
|
// service.SetRootCoord(newRootCoordMock())
|
2021-06-23 17:44:12 +08:00
|
|
|
// 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)
|
|
|
|
// })
|
|
|
|
//}
|