2021-09-30 10:02:02 +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.
|
|
|
|
|
|
|
|
package grpcquerynode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/types"
|
|
|
|
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/commonpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
type MockQueryNode struct {
|
|
|
|
states *internalpb.ComponentStates
|
|
|
|
status *commonpb.Status
|
|
|
|
err error
|
2021-10-11 17:16:30 +08:00
|
|
|
initErr error
|
|
|
|
startErr error
|
|
|
|
regErr error
|
|
|
|
stopErr error
|
2021-09-30 10:02:02 +08:00
|
|
|
strResp *milvuspb.StringResponse
|
|
|
|
infoResp *querypb.GetSegmentInfoResponse
|
|
|
|
metricResp *milvuspb.GetMetricsResponse
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) Init() error {
|
2021-10-11 17:16:30 +08:00
|
|
|
return m.initErr
|
2021-09-30 10:02:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) Start() error {
|
2021-10-11 17:16:30 +08:00
|
|
|
return m.startErr
|
2021-09-30 10:02:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) Stop() error {
|
2021-10-11 17:16:30 +08:00
|
|
|
return m.stopErr
|
2021-09-30 10:02:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) Register() error {
|
2021-10-11 17:16:30 +08:00
|
|
|
return m.regErr
|
2021-09-30 10:02:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
|
|
|
return m.states, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) GetStatisticsChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
|
|
return m.strResp, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) GetTimeTickChannel(ctx context.Context) (*milvuspb.StringResponse, error) {
|
|
|
|
return m.strResp, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) AddQueryChannel(ctx context.Context, req *querypb.AddQueryChannelRequest) (*commonpb.Status, error) {
|
|
|
|
return m.status, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) RemoveQueryChannel(ctx context.Context, req *querypb.RemoveQueryChannelRequest) (*commonpb.Status, error) {
|
|
|
|
return m.status, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) WatchDmChannels(ctx context.Context, req *querypb.WatchDmChannelsRequest) (*commonpb.Status, error) {
|
|
|
|
return m.status, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) LoadSegments(ctx context.Context, req *querypb.LoadSegmentsRequest) (*commonpb.Status, error) {
|
|
|
|
return m.status, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) ReleaseCollection(ctx context.Context, req *querypb.ReleaseCollectionRequest) (*commonpb.Status, error) {
|
|
|
|
return m.status, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) ReleasePartitions(ctx context.Context, req *querypb.ReleasePartitionsRequest) (*commonpb.Status, error) {
|
|
|
|
return m.status, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) ReleaseSegments(ctx context.Context, req *querypb.ReleaseSegmentsRequest) (*commonpb.Status, error) {
|
|
|
|
return m.status, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) GetSegmentInfo(ctx context.Context, req *querypb.GetSegmentInfoRequest) (*querypb.GetSegmentInfoResponse, error) {
|
|
|
|
return m.infoResp, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error) {
|
|
|
|
return m.metricResp, m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) UpdateStateCode(code internalpb.StateCode) {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) SetRootCoord(rc types.RootCoord) error {
|
|
|
|
return m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockQueryNode) SetIndexCoord(index types.IndexCoord) error {
|
|
|
|
return m.err
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
type MockRootCoord struct {
|
2021-10-14 17:42:35 +08:00
|
|
|
types.RootCoord
|
2021-09-30 10:02:02 +08:00
|
|
|
initErr error
|
|
|
|
startErr error
|
|
|
|
regErr error
|
|
|
|
stopErr error
|
|
|
|
stateErr commonpb.ErrorCode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockRootCoord) Init() error {
|
|
|
|
return m.initErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockRootCoord) Start() error {
|
|
|
|
return m.startErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockRootCoord) Stop() error {
|
|
|
|
return m.stopErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockRootCoord) Register() error {
|
|
|
|
return m.regErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockRootCoord) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
|
|
|
return &internalpb.ComponentStates{
|
|
|
|
State: &internalpb.ComponentInfo{StateCode: internalpb.StateCode_Healthy},
|
|
|
|
Status: &commonpb.Status{ErrorCode: m.stateErr},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
type MockIndexCoord struct {
|
2021-10-14 17:42:35 +08:00
|
|
|
types.IndexCoord
|
2021-09-30 10:02:02 +08:00
|
|
|
initErr error
|
|
|
|
startErr error
|
|
|
|
regErr error
|
|
|
|
stopErr error
|
|
|
|
stateErr commonpb.ErrorCode
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockIndexCoord) Init() error {
|
|
|
|
return m.initErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockIndexCoord) Start() error {
|
|
|
|
return m.startErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockIndexCoord) Stop() error {
|
|
|
|
return m.stopErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockIndexCoord) Register() error {
|
|
|
|
return m.regErr
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *MockIndexCoord) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
|
|
|
return &internalpb.ComponentStates{
|
|
|
|
State: &internalpb.ComponentInfo{StateCode: internalpb.StateCode_Healthy},
|
|
|
|
Status: &commonpb.Status{ErrorCode: m.stateErr},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
func Test_NewServer(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2021-10-14 18:48:56 +08:00
|
|
|
server, err := NewServer(ctx, nil)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 18:48:56 +08:00
|
|
|
assert.NotNil(t, server)
|
2021-09-30 10:02:02 +08:00
|
|
|
|
|
|
|
mqn := &MockQueryNode{
|
|
|
|
states: &internalpb.ComponentStates{State: &internalpb.ComponentInfo{StateCode: internalpb.StateCode_Healthy}},
|
|
|
|
status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success},
|
|
|
|
err: nil,
|
|
|
|
strResp: &milvuspb.StringResponse{Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}},
|
|
|
|
infoResp: &querypb.GetSegmentInfoResponse{Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}},
|
|
|
|
metricResp: &milvuspb.GetMetricsResponse{Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}},
|
|
|
|
}
|
2021-10-14 18:48:56 +08:00
|
|
|
server.querynode = mqn
|
2021-09-30 10:02:02 +08:00
|
|
|
|
|
|
|
t.Run("Run", func(t *testing.T) {
|
2021-10-14 18:48:56 +08:00
|
|
|
server.rootCoord = &MockRootCoord{}
|
|
|
|
server.indexCoord = &MockIndexCoord{}
|
2021-09-30 10:02:02 +08:00
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
err = server.Run()
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetComponentStates", func(t *testing.T) {
|
|
|
|
req := &internalpb.GetComponentStatesRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
states, err := server.GetComponentStates(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, internalpb.StateCode_Healthy, states.State.StateCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetStatisticsChannel", func(t *testing.T) {
|
|
|
|
req := &internalpb.GetStatisticsChannelRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.GetStatisticsChannel(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetTimeTickChannel", func(t *testing.T) {
|
|
|
|
req := &internalpb.GetTimeTickChannelRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.GetTimeTickChannel(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("AddQueryChannel", func(t *testing.T) {
|
|
|
|
req := &querypb.AddQueryChannelRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.AddQueryChannel(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("RemoveQueryChannel", func(t *testing.T) {
|
|
|
|
req := &querypb.RemoveQueryChannelRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.RemoveQueryChannel(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("WatchDmChannels", func(t *testing.T) {
|
|
|
|
req := &querypb.WatchDmChannelsRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.WatchDmChannels(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("LoadSegments", func(t *testing.T) {
|
|
|
|
req := &querypb.LoadSegmentsRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.LoadSegments(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("ReleaseCollection", func(t *testing.T) {
|
|
|
|
req := &querypb.ReleaseCollectionRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.ReleaseCollection(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("ReleasePartitions", func(t *testing.T) {
|
|
|
|
req := &querypb.ReleasePartitionsRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.ReleasePartitions(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("ReleaseSegments", func(t *testing.T) {
|
|
|
|
req := &querypb.ReleaseSegmentsRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.ReleaseSegments(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetSegmentInfo", func(t *testing.T) {
|
|
|
|
req := &querypb.GetSegmentInfoRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.GetSegmentInfo(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetMetrics", func(t *testing.T) {
|
|
|
|
req := &milvuspb.GetMetricsRequest{
|
|
|
|
Request: "",
|
|
|
|
}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.GetMetrics(ctx, req)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
err = server.Stop()
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_Run(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
2021-10-14 18:48:56 +08:00
|
|
|
server, err := NewServer(ctx, nil)
|
2021-09-30 10:02:02 +08:00
|
|
|
assert.Nil(t, err)
|
2021-10-14 18:48:56 +08:00
|
|
|
assert.NotNil(t, server)
|
2021-09-30 10:02:02 +08:00
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
server.querynode = &MockQueryNode{}
|
|
|
|
server.indexCoord = &MockIndexCoord{}
|
|
|
|
server.rootCoord = &MockRootCoord{initErr: errors.New("Failed")}
|
|
|
|
assert.Panics(t, func() { err = server.Run() })
|
2021-09-30 10:02:02 +08:00
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
server.rootCoord = &MockRootCoord{startErr: errors.New("Failed")}
|
|
|
|
assert.Panics(t, func() { err = server.Run() })
|
2021-09-30 10:02:02 +08:00
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
server.querynode = &MockQueryNode{}
|
|
|
|
server.rootCoord = &MockRootCoord{}
|
|
|
|
server.indexCoord = &MockIndexCoord{initErr: errors.New("Failed")}
|
|
|
|
assert.Panics(t, func() { err = server.Run() })
|
2021-09-30 10:02:02 +08:00
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
server.indexCoord = &MockIndexCoord{startErr: errors.New("Failed")}
|
|
|
|
assert.Panics(t, func() { err = server.Run() })
|
2021-10-11 17:16:30 +08:00
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
server.indexCoord = &MockIndexCoord{}
|
|
|
|
server.rootCoord = &MockRootCoord{}
|
|
|
|
server.querynode = &MockQueryNode{initErr: errors.New("Failed")}
|
|
|
|
err = server.Run()
|
2021-10-11 17:16:30 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
server.querynode = &MockQueryNode{startErr: errors.New("Failed")}
|
|
|
|
err = server.Run()
|
2021-10-11 17:16:30 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
server.querynode = &MockQueryNode{regErr: errors.New("Failed")}
|
|
|
|
err = server.Run()
|
2021-10-11 17:16:30 +08:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
server.querynode = &MockQueryNode{stopErr: errors.New("Failed")}
|
|
|
|
err = server.Stop()
|
2021-10-11 17:16:30 +08:00
|
|
|
assert.Error(t, err)
|
2021-09-30 10:02:02 +08:00
|
|
|
}
|