mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 20:09:57 +08:00
Add unittest for distributed/querynode (#9608)
Signed-off-by: yhmo <yihua.mo@zilliz.com>
This commit is contained in:
parent
9229d56c96
commit
0d49316103
@ -45,7 +45,7 @@ import (
|
|||||||
type UniqueID = typeutil.UniqueID
|
type UniqueID = typeutil.UniqueID
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
querynode qn.Base
|
querynode types.QueryNodeComponent
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@ -259,12 +259,6 @@ func (s *Server) SetIndexCoord(indexCoord types.IndexCoord) error {
|
|||||||
return s.querynode.SetIndexCoord(indexCoord)
|
return s.querynode.SetIndexCoord(indexCoord)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetClient sets the IndexNode's instance.
|
|
||||||
func (s *Server) SetClient(queryNodeClient qn.Base) error {
|
|
||||||
s.querynode = queryNodeClient
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) GetTimeTickChannel(ctx context.Context, req *internalpb.GetTimeTickChannelRequest) (*milvuspb.StringResponse, error) {
|
func (s *Server) GetTimeTickChannel(ctx context.Context, req *internalpb.GetTimeTickChannelRequest) (*milvuspb.StringResponse, error) {
|
||||||
return s.querynode.GetTimeTickChannel(ctx)
|
return s.querynode.GetTimeTickChannel(ctx)
|
||||||
}
|
}
|
||||||
|
@ -33,25 +33,29 @@ type MockQueryNode struct {
|
|||||||
states *internalpb.ComponentStates
|
states *internalpb.ComponentStates
|
||||||
status *commonpb.Status
|
status *commonpb.Status
|
||||||
err error
|
err error
|
||||||
|
initErr error
|
||||||
|
startErr error
|
||||||
|
regErr error
|
||||||
|
stopErr error
|
||||||
strResp *milvuspb.StringResponse
|
strResp *milvuspb.StringResponse
|
||||||
infoResp *querypb.GetSegmentInfoResponse
|
infoResp *querypb.GetSegmentInfoResponse
|
||||||
metricResp *milvuspb.GetMetricsResponse
|
metricResp *milvuspb.GetMetricsResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockQueryNode) Init() error {
|
func (m *MockQueryNode) Init() error {
|
||||||
return m.err
|
return m.initErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockQueryNode) Start() error {
|
func (m *MockQueryNode) Start() error {
|
||||||
return m.err
|
return m.startErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockQueryNode) Stop() error {
|
func (m *MockQueryNode) Stop() error {
|
||||||
return m.err
|
return m.stopErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockQueryNode) Register() error {
|
func (m *MockQueryNode) Register() error {
|
||||||
return m.err
|
return m.regErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MockQueryNode) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
func (m *MockQueryNode) GetComponentStates(ctx context.Context) (*internalpb.ComponentStates, error) {
|
||||||
@ -194,8 +198,7 @@ func Test_NewServer(t *testing.T) {
|
|||||||
infoResp: &querypb.GetSegmentInfoResponse{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}},
|
metricResp: &milvuspb.GetMetricsResponse{Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}},
|
||||||
}
|
}
|
||||||
err = qns.SetClient(mqn)
|
qns.querynode = mqn
|
||||||
assert.Nil(t, err)
|
|
||||||
|
|
||||||
t.Run("Run", func(t *testing.T) {
|
t.Run("Run", func(t *testing.T) {
|
||||||
qns.rootCoord = &MockRootCoord{}
|
qns.rootCoord = &MockRootCoord{}
|
||||||
@ -301,19 +304,37 @@ func Test_Run(t *testing.T) {
|
|||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.NotNil(t, qns)
|
assert.NotNil(t, qns)
|
||||||
|
|
||||||
qns.rootCoord = &MockRootCoord{initErr: errors.New("Failed")}
|
qns.querynode = &MockQueryNode{}
|
||||||
qns.indexCoord = &MockIndexCoord{}
|
qns.indexCoord = &MockIndexCoord{}
|
||||||
|
qns.rootCoord = &MockRootCoord{initErr: errors.New("Failed")}
|
||||||
assert.Panics(t, func() { err = qns.Run() })
|
assert.Panics(t, func() { err = qns.Run() })
|
||||||
|
|
||||||
qns.rootCoord = &MockRootCoord{startErr: errors.New("Failed")}
|
qns.rootCoord = &MockRootCoord{startErr: errors.New("Failed")}
|
||||||
qns.indexCoord = &MockIndexCoord{}
|
|
||||||
assert.Panics(t, func() { err = qns.Run() })
|
assert.Panics(t, func() { err = qns.Run() })
|
||||||
|
|
||||||
|
qns.querynode = &MockQueryNode{}
|
||||||
qns.rootCoord = &MockRootCoord{}
|
qns.rootCoord = &MockRootCoord{}
|
||||||
qns.indexCoord = &MockIndexCoord{initErr: errors.New("Failed")}
|
qns.indexCoord = &MockIndexCoord{initErr: errors.New("Failed")}
|
||||||
assert.Panics(t, func() { err = qns.Run() })
|
assert.Panics(t, func() { err = qns.Run() })
|
||||||
|
|
||||||
qns.rootCoord = &MockRootCoord{}
|
|
||||||
qns.indexCoord = &MockIndexCoord{startErr: errors.New("Failed")}
|
qns.indexCoord = &MockIndexCoord{startErr: errors.New("Failed")}
|
||||||
assert.Panics(t, func() { err = qns.Run() })
|
assert.Panics(t, func() { err = qns.Run() })
|
||||||
|
|
||||||
|
qns.indexCoord = &MockIndexCoord{}
|
||||||
|
qns.rootCoord = &MockRootCoord{}
|
||||||
|
qns.querynode = &MockQueryNode{initErr: errors.New("Failed")}
|
||||||
|
err = qns.Run()
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
qns.querynode = &MockQueryNode{startErr: errors.New("Failed")}
|
||||||
|
err = qns.Run()
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
qns.querynode = &MockQueryNode{regErr: errors.New("Failed")}
|
||||||
|
err = qns.Run()
|
||||||
|
assert.Error(t, err)
|
||||||
|
|
||||||
|
qns.querynode = &MockQueryNode{stopErr: errors.New("Failed")}
|
||||||
|
err = qns.Stop()
|
||||||
|
assert.Error(t, err)
|
||||||
}
|
}
|
||||||
|
@ -45,19 +45,11 @@ import (
|
|||||||
"github.com/milvus-io/milvus/internal/util/typeutil"
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Base interface {
|
|
||||||
types.QueryNode
|
|
||||||
|
|
||||||
UpdateStateCode(code internalpb.StateCode)
|
|
||||||
SetRootCoord(rc types.RootCoord) error
|
|
||||||
SetIndexCoord(index types.IndexCoord) error
|
|
||||||
}
|
|
||||||
|
|
||||||
// make sure QueryNode implements types.QueryNode
|
// make sure QueryNode implements types.QueryNode
|
||||||
var _ types.QueryNode = (*QueryNode)(nil)
|
var _ types.QueryNode = (*QueryNode)(nil)
|
||||||
|
|
||||||
// make sure QueryNode implements Base
|
// make sure QueryNode implements types.QueryNodeComponent
|
||||||
var _ Base = (*QueryNode)(nil)
|
var _ types.QueryNodeComponent = (*QueryNode)(nil)
|
||||||
|
|
||||||
// QueryNode communicates with outside services and union all
|
// QueryNode communicates with outside services and union all
|
||||||
// services in querynode package.
|
// services in querynode package.
|
||||||
|
@ -533,6 +533,33 @@ type QueryNode interface {
|
|||||||
GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error)
|
GetMetrics(ctx context.Context, req *milvuspb.GetMetricsRequest) (*milvuspb.GetMetricsResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// QueryNodeComponent is used by grpc server of QueryNode
|
||||||
|
type QueryNodeComponent interface {
|
||||||
|
QueryNode
|
||||||
|
|
||||||
|
// UpdateStateCode updates state code for QueryNode
|
||||||
|
// `stateCode` is current statement of this query node, indicating whether it's healthy.
|
||||||
|
UpdateStateCode(code internalpb.StateCode)
|
||||||
|
|
||||||
|
// SetRootCoord set RootCoord for QueryNode
|
||||||
|
// `rootCoord` is a client of root coordinator. Pass to segmentLoader.
|
||||||
|
//
|
||||||
|
// Return a generic error in status:
|
||||||
|
// If the rootCoord is nil.
|
||||||
|
// Return nil in status:
|
||||||
|
// The rootCoord is not nil.
|
||||||
|
SetRootCoord(rootCoord RootCoord) error
|
||||||
|
|
||||||
|
// SetIndexCoord set IndexCoord for QueryNode
|
||||||
|
// `indexCoord` is a client of index coordinator. Pass to segmentLoader.
|
||||||
|
//
|
||||||
|
// Return a generic error in status:
|
||||||
|
// If the indexCoord is nil.
|
||||||
|
// Return nil in status:
|
||||||
|
// The indexCoord is not nil.
|
||||||
|
SetIndexCoord(indexCoord IndexCoord) error
|
||||||
|
}
|
||||||
|
|
||||||
// QueryCoord is the interface `querycoord` package implements
|
// QueryCoord is the interface `querycoord` package implements
|
||||||
type QueryCoord interface {
|
type QueryCoord interface {
|
||||||
Component
|
Component
|
||||||
|
Loading…
Reference in New Issue
Block a user