2023-03-27 00:42:00 +08:00
|
|
|
// Licensed to the LF AI & Data foundation under one
|
|
|
|
// or more contributor license agreements. See the NOTICE file
|
|
|
|
// distributed with this work for additional information
|
|
|
|
// regarding copyright ownership. The ASF licenses this file
|
|
|
|
// to you 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.
|
|
|
|
|
|
|
|
// delegator package contains the logic of shard delegator.
|
|
|
|
|
|
|
|
package cluster
|
|
|
|
|
|
|
|
import (
|
2023-09-26 09:57:25 +08:00
|
|
|
"context"
|
2023-09-12 10:19:17 +08:00
|
|
|
"io"
|
2023-03-27 00:42:00 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/cockroachdb/errors"
|
2023-09-21 09:45:27 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
"github.com/stretchr/testify/suite"
|
2023-09-26 09:57:25 +08:00
|
|
|
"google.golang.org/grpc"
|
2023-05-23 16:01:26 +08:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2023-03-27 00:42:00 +08:00
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
2023-09-12 10:19:17 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2023-07-14 10:12:31 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mocks"
|
2023-09-26 09:57:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2023-09-12 10:19:17 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/streamrpc"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2023-03-27 00:42:00 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type RemoteWorkerSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
mockClient *mocks.MockQueryNodeClient
|
2023-03-27 00:42:00 +08:00
|
|
|
worker *remoteWorker
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoteWorkerSuite) SetupTest() {
|
2023-09-26 09:57:25 +08:00
|
|
|
s.mockClient = &mocks.MockQueryNodeClient{}
|
2023-03-27 00:42:00 +08:00
|
|
|
s.worker = &remoteWorker{client: s.mockClient}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoteWorkerSuite) TearDownTest() {
|
|
|
|
s.mockClient = nil
|
|
|
|
s.worker = nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoteWorkerSuite) TestLoadSegments() {
|
|
|
|
s.Run("normal_run", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().LoadSegments(mock.Anything, mock.AnythingOfType("*querypb.LoadSegmentsRequest")).
|
|
|
|
Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.LoadSegments(ctx, &querypb.LoadSegmentsRequest{})
|
|
|
|
|
|
|
|
s.NoError(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_error", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().LoadSegments(mock.Anything, mock.AnythingOfType("*querypb.LoadSegmentsRequest")).
|
|
|
|
Return(nil, errors.New("mocked error"))
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.LoadSegments(ctx, &querypb.LoadSegmentsRequest{})
|
|
|
|
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_fail_status", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().LoadSegments(mock.Anything, mock.AnythingOfType("*querypb.LoadSegmentsRequest")).
|
|
|
|
Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError, Reason: "mocked failure"}, nil)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.LoadSegments(ctx, &querypb.LoadSegmentsRequest{})
|
|
|
|
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoteWorkerSuite) TestReleaseSegments() {
|
|
|
|
s.Run("normal_run", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().ReleaseSegments(mock.Anything, mock.AnythingOfType("*querypb.ReleaseSegmentsRequest")).
|
|
|
|
Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.ReleaseSegments(ctx, &querypb.ReleaseSegmentsRequest{})
|
|
|
|
|
|
|
|
s.NoError(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_error", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().ReleaseSegments(mock.Anything, mock.AnythingOfType("*querypb.ReleaseSegmentsRequest")).
|
|
|
|
Return(nil, errors.New("mocked error"))
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.ReleaseSegments(ctx, &querypb.ReleaseSegmentsRequest{})
|
|
|
|
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_fail_status", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().ReleaseSegments(mock.Anything, mock.AnythingOfType("*querypb.ReleaseSegmentsRequest")).
|
|
|
|
Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError, Reason: "mocked failure"}, nil)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.ReleaseSegments(ctx, &querypb.ReleaseSegmentsRequest{})
|
|
|
|
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoteWorkerSuite) TestDelete() {
|
|
|
|
s.Run("normal_run", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().Delete(mock.Anything, mock.AnythingOfType("*querypb.DeleteRequest")).
|
|
|
|
Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.Delete(ctx, &querypb.DeleteRequest{})
|
|
|
|
|
|
|
|
s.NoError(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_error", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().Delete(mock.Anything, mock.AnythingOfType("*querypb.DeleteRequest")).
|
|
|
|
Return(nil, errors.New("mocked error"))
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.Delete(ctx, &querypb.DeleteRequest{})
|
|
|
|
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_fail_status", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().Delete(mock.Anything, mock.AnythingOfType("*querypb.DeleteRequest")).
|
|
|
|
Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError, Reason: "mocked failure"}, nil)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
err := s.worker.Delete(ctx, &querypb.DeleteRequest{})
|
|
|
|
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoteWorkerSuite) TestSearch() {
|
|
|
|
s.Run("normal_run", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.SearchResults
|
|
|
|
var err error
|
|
|
|
|
|
|
|
result = &internalpb.SearchResults{
|
|
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success},
|
|
|
|
}
|
2023-05-23 16:01:26 +08:00
|
|
|
s.mockClient.EXPECT().SearchSegments(mock.Anything, mock.AnythingOfType("*querypb.SearchRequest")).
|
2023-03-27 00:42:00 +08:00
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-23 16:01:26 +08:00
|
|
|
sr, serr := s.worker.SearchSegments(ctx, &querypb.SearchRequest{})
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_error", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.SearchResults
|
|
|
|
err := errors.New("mocked error")
|
2023-05-23 16:01:26 +08:00
|
|
|
s.mockClient.EXPECT().SearchSegments(mock.Anything, mock.AnythingOfType("*querypb.SearchRequest")).
|
2023-03-27 00:42:00 +08:00
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-23 16:01:26 +08:00
|
|
|
sr, serr := s.worker.SearchSegments(ctx, &querypb.SearchRequest{})
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_fail_status", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.SearchResults
|
|
|
|
var err error
|
|
|
|
|
|
|
|
result = &internalpb.SearchResults{
|
|
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError},
|
|
|
|
}
|
2023-05-23 16:01:26 +08:00
|
|
|
s.mockClient.EXPECT().SearchSegments(mock.Anything, mock.AnythingOfType("*querypb.SearchRequest")).
|
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
sr, serr := s.worker.SearchSegments(ctx, &querypb.SearchRequest{})
|
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_search_compatible", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.SearchResults
|
|
|
|
var err error
|
|
|
|
|
2023-06-25 10:30:43 +08:00
|
|
|
grpcErr := status.Error(codes.Unimplemented, "method not implemented")
|
2023-05-23 16:01:26 +08:00
|
|
|
s.mockClient.EXPECT().SearchSegments(mock.Anything, mock.AnythingOfType("*querypb.SearchRequest")).
|
|
|
|
Return(result, grpcErr)
|
2023-03-27 00:42:00 +08:00
|
|
|
s.mockClient.EXPECT().Search(mock.Anything, mock.AnythingOfType("*querypb.SearchRequest")).
|
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-23 16:01:26 +08:00
|
|
|
sr, serr := s.worker.SearchSegments(ctx, &querypb.SearchRequest{})
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoteWorkerSuite) TestQuery() {
|
|
|
|
s.Run("normal_run", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.RetrieveResults
|
|
|
|
var err error
|
|
|
|
|
|
|
|
result = &internalpb.RetrieveResults{
|
|
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success},
|
|
|
|
}
|
2023-05-23 16:01:26 +08:00
|
|
|
s.mockClient.EXPECT().QuerySegments(mock.Anything, mock.AnythingOfType("*querypb.QueryRequest")).
|
2023-03-27 00:42:00 +08:00
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-23 16:01:26 +08:00
|
|
|
sr, serr := s.worker.QuerySegments(ctx, &querypb.QueryRequest{})
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_error", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.RetrieveResults
|
|
|
|
|
|
|
|
err := errors.New("mocked error")
|
2023-05-23 16:01:26 +08:00
|
|
|
s.mockClient.EXPECT().QuerySegments(mock.Anything, mock.AnythingOfType("*querypb.QueryRequest")).
|
2023-03-27 00:42:00 +08:00
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-23 16:01:26 +08:00
|
|
|
sr, serr := s.worker.QuerySegments(ctx, &querypb.QueryRequest{})
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_fail_status", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.RetrieveResults
|
|
|
|
var err error
|
|
|
|
|
|
|
|
result = &internalpb.RetrieveResults{
|
|
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError},
|
|
|
|
}
|
2023-05-23 16:01:26 +08:00
|
|
|
s.mockClient.EXPECT().QuerySegments(mock.Anything, mock.AnythingOfType("*querypb.QueryRequest")).
|
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
sr, serr := s.worker.QuerySegments(ctx, &querypb.QueryRequest{})
|
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_query_compatible", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.RetrieveResults
|
|
|
|
var err error
|
|
|
|
|
2023-06-25 10:30:43 +08:00
|
|
|
grpcErr := status.Error(codes.Unimplemented, "method not implemented")
|
2023-05-23 16:01:26 +08:00
|
|
|
s.mockClient.EXPECT().QuerySegments(mock.Anything, mock.AnythingOfType("*querypb.QueryRequest")).
|
|
|
|
Return(result, grpcErr)
|
2023-03-27 00:42:00 +08:00
|
|
|
s.mockClient.EXPECT().Query(mock.Anything, mock.AnythingOfType("*querypb.QueryRequest")).
|
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-23 16:01:26 +08:00
|
|
|
sr, serr := s.worker.QuerySegments(ctx, &querypb.QueryRequest{})
|
2023-03-27 00:42:00 +08:00
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-09-12 10:19:17 +08:00
|
|
|
func (s *RemoteWorkerSuite) TestQueryStream() {
|
|
|
|
s.Run("normal_run", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := client.CreateServer()
|
|
|
|
|
|
|
|
ids := []int64{10, 11, 12}
|
|
|
|
s.mockClient.EXPECT().QueryStreamSegments(
|
|
|
|
mock.Anything,
|
|
|
|
mock.AnythingOfType("*querypb.QueryRequest"),
|
2023-09-26 09:57:25 +08:00
|
|
|
).RunAndReturn(func(ctx context.Context, request *querypb.QueryRequest, option ...grpc.CallOption) (querypb.QueryNode_QueryStreamSegmentsClient, error) {
|
2023-09-12 10:19:17 +08:00
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := client.CreateServer()
|
2023-09-26 09:57:25 +08:00
|
|
|
|
2023-09-12 10:19:17 +08:00
|
|
|
for _, id := range ids {
|
2023-09-26 09:57:25 +08:00
|
|
|
err := server.Send(&internalpb.RetrieveResults{
|
2023-09-12 10:19:17 +08:00
|
|
|
Status: merr.Status(nil),
|
|
|
|
Ids: &schemapb.IDs{
|
|
|
|
IdField: &schemapb.IDs_IntId{
|
|
|
|
IntId: &schemapb.LongArray{Data: []int64{id}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2023-09-26 09:57:25 +08:00
|
|
|
s.NoError(err)
|
2023-09-12 10:19:17 +08:00
|
|
|
}
|
2023-09-26 09:57:25 +08:00
|
|
|
err := server.FinishSend(nil)
|
|
|
|
s.NoError(err)
|
|
|
|
return client, nil
|
|
|
|
})
|
2023-09-12 10:19:17 +08:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
err := s.worker.QueryStreamSegments(ctx, &querypb.QueryRequest{}, server)
|
|
|
|
if err != nil {
|
|
|
|
server.Send(&internalpb.RetrieveResults{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
server.FinishSend(err)
|
|
|
|
}()
|
|
|
|
|
|
|
|
recNum := 0
|
|
|
|
for {
|
|
|
|
result, err := client.Recv()
|
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
err = merr.Error(result.GetStatus())
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
s.Less(recNum, len(ids))
|
|
|
|
s.Equal(result.Ids.GetIntId().Data[0], ids[recNum])
|
|
|
|
recNum++
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("send msg failed", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
clientCtx, clientClose := context.WithCancel(ctx)
|
|
|
|
client := streamrpc.NewLocalQueryClient(clientCtx)
|
|
|
|
server := client.CreateServer()
|
|
|
|
clientClose()
|
|
|
|
|
|
|
|
ids := []int64{10, 11, 12}
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().QueryStreamSegments(
|
|
|
|
mock.Anything,
|
|
|
|
mock.AnythingOfType("*querypb.QueryRequest"),
|
2023-09-26 09:57:25 +08:00
|
|
|
).RunAndReturn(func(ctx context.Context, request *querypb.QueryRequest, option ...grpc.CallOption) (querypb.QueryNode_QueryStreamSegmentsClient, error) {
|
2023-09-12 10:19:17 +08:00
|
|
|
for _, id := range ids {
|
2023-09-26 09:57:25 +08:00
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := client.CreateServer()
|
|
|
|
|
2023-09-12 10:19:17 +08:00
|
|
|
err := server.Send(&internalpb.RetrieveResults{
|
|
|
|
Status: merr.Status(nil),
|
|
|
|
Ids: &schemapb.IDs{
|
|
|
|
IdField: &schemapb.IDs_IntId{
|
|
|
|
IntId: &schemapb.LongArray{Data: []int64{id}},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
s.NoError(err)
|
|
|
|
}
|
2023-09-26 09:57:25 +08:00
|
|
|
err := server.FinishSend(nil)
|
|
|
|
s.NoError(err)
|
|
|
|
return client, nil
|
|
|
|
})
|
2023-09-12 10:19:17 +08:00
|
|
|
|
|
|
|
err := s.worker.QueryStreamSegments(ctx, &querypb.QueryRequest{}, server)
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_error", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := streamrpc.NewConcurrentQueryStreamServer(client.CreateServer())
|
|
|
|
|
|
|
|
s.mockClient.EXPECT().QueryStreamSegments(
|
|
|
|
mock.Anything,
|
|
|
|
mock.AnythingOfType("*querypb.QueryRequest"),
|
2023-09-26 09:57:25 +08:00
|
|
|
).Return(nil, errors.New("mocked error"))
|
2023-09-12 10:19:17 +08:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
err := s.worker.QueryStreamSegments(ctx, &querypb.QueryRequest{}, server)
|
|
|
|
server.Send(&internalpb.RetrieveResults{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
|
|
|
|
result, err := client.Recv()
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
err = merr.Error(result.GetStatus())
|
|
|
|
// Check result
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_fail_status", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
2023-09-26 09:57:25 +08:00
|
|
|
server := client.CreateServer()
|
2023-09-12 10:19:17 +08:00
|
|
|
|
|
|
|
s.mockClient.EXPECT().QueryStreamSegments(
|
|
|
|
mock.Anything,
|
|
|
|
mock.AnythingOfType("*querypb.QueryRequest"),
|
2023-09-26 09:57:25 +08:00
|
|
|
).RunAndReturn(func(ctx context.Context, request *querypb.QueryRequest, option ...grpc.CallOption) (querypb.QueryNode_QueryStreamSegmentsClient, error) {
|
2023-09-12 10:19:17 +08:00
|
|
|
client := streamrpc.NewLocalQueryClient(ctx)
|
|
|
|
server := client.CreateServer()
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
err := server.Send(&internalpb.RetrieveResults{
|
2023-09-12 10:19:17 +08:00
|
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError},
|
|
|
|
})
|
2023-09-26 09:57:25 +08:00
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
err = server.FinishSend(nil)
|
|
|
|
s.NoError(err)
|
|
|
|
return client, nil
|
|
|
|
})
|
2023-09-12 10:19:17 +08:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
err := s.worker.QueryStreamSegments(ctx, &querypb.QueryRequest{}, server)
|
|
|
|
server.Send(&internalpb.RetrieveResults{
|
|
|
|
Status: merr.Status(err),
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
|
|
|
|
result, err := client.Recv()
|
|
|
|
s.NoError(err)
|
|
|
|
|
|
|
|
err = merr.Error(result.GetStatus())
|
|
|
|
// Check result
|
|
|
|
s.Error(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-03-27 00:42:00 +08:00
|
|
|
func (s *RemoteWorkerSuite) TestGetStatistics() {
|
|
|
|
s.Run("normal_run", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.GetStatisticsResponse
|
|
|
|
var err error
|
|
|
|
|
|
|
|
result = &internalpb.GetStatisticsResponse{
|
|
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success},
|
|
|
|
}
|
|
|
|
s.mockClient.EXPECT().GetStatistics(mock.Anything, mock.AnythingOfType("*querypb.GetStatisticsRequest")).
|
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
sr, serr := s.worker.GetStatistics(ctx, &querypb.GetStatisticsRequest{})
|
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_error", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.GetStatisticsResponse
|
|
|
|
|
|
|
|
err := errors.New("mocked error")
|
|
|
|
s.mockClient.EXPECT().GetStatistics(mock.Anything, mock.AnythingOfType("*querypb.GetStatisticsRequest")).
|
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
sr, serr := s.worker.GetStatistics(ctx, &querypb.GetStatisticsRequest{})
|
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
|
|
|
|
s.Run("client_return_fail_status", func() {
|
|
|
|
defer func() { s.mockClient.ExpectedCalls = nil }()
|
|
|
|
|
|
|
|
var result *internalpb.GetStatisticsResponse
|
|
|
|
var err error
|
|
|
|
|
|
|
|
result = &internalpb.GetStatisticsResponse{
|
|
|
|
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError},
|
|
|
|
}
|
|
|
|
s.mockClient.EXPECT().GetStatistics(mock.Anything, mock.AnythingOfType("*querypb.GetStatisticsRequest")).
|
|
|
|
Return(result, err)
|
|
|
|
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
sr, serr := s.worker.GetStatistics(ctx, &querypb.GetStatisticsRequest{})
|
|
|
|
|
|
|
|
s.Equal(err, serr)
|
|
|
|
s.Equal(result, sr)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *RemoteWorkerSuite) TestBasic() {
|
|
|
|
s.True(s.worker.IsHealthy())
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
s.mockClient.EXPECT().Close().Return(nil)
|
2023-03-27 00:42:00 +08:00
|
|
|
s.worker.Stop()
|
2023-09-26 09:57:25 +08:00
|
|
|
s.mockClient.AssertCalled(s.T(), "Close")
|
2023-03-27 00:42:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestRemoteWorker(t *testing.T) {
|
|
|
|
suite.Run(t, new(RemoteWorkerSuite))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewRemoteWorker(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
client := mocks.NewMockQueryNodeClient(t)
|
2023-03-27 00:42:00 +08:00
|
|
|
w := NewRemoteWorker(client)
|
|
|
|
|
|
|
|
rw, ok := w.(*remoteWorker)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, client, rw.client)
|
|
|
|
}
|