2022-12-30 18:35:32 +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.
|
|
|
|
|
2022-09-27 19:18:54 +08:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-10-20 14:26:09 +08:00
|
|
|
"encoding/base64"
|
2024-01-17 19:16:55 +08:00
|
|
|
"fmt"
|
2022-09-27 19:18:54 +08:00
|
|
|
"testing"
|
2023-10-20 14:26:09 +08:00
|
|
|
"time"
|
2022-09-27 19:18:54 +08:00
|
|
|
|
2023-02-26 11:31:49 +08:00
|
|
|
"github.com/cockroachdb/errors"
|
2023-01-19 14:13:43 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/mock"
|
2023-10-20 14:26:09 +08:00
|
|
|
"go.uber.org/zap"
|
2023-09-26 09:57:25 +08:00
|
|
|
"google.golang.org/grpc"
|
2023-08-03 15:53:07 +08:00
|
|
|
"google.golang.org/grpc/metadata"
|
2022-10-18 13:39:26 +08:00
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
2023-10-20 14:26:09 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/msgpb"
|
2024-01-17 19:16:55 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
2023-01-19 14:13:43 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mocks"
|
2023-03-30 11:28:25 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2022-09-27 19:18:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/proxypb"
|
2023-02-16 15:38:34 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/querypb"
|
2023-06-25 17:20:43 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
2023-01-30 10:19:48 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2022-10-18 13:39:26 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2024-01-17 19:16:55 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2023-10-20 14:26:09 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream"
|
|
|
|
"github.com/milvus-io/milvus/pkg/mq/msgstream/mqwrapper"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/commonpbutil"
|
2023-09-15 10:09:21 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2023-10-20 14:26:09 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/resource"
|
2022-09-27 19:18:54 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestProxy_InvalidateCollectionMetaCache_remove_stream(t *testing.T) {
|
2022-11-04 14:25:38 +08:00
|
|
|
paramtable.Init()
|
2022-09-27 19:18:54 +08:00
|
|
|
cache := globalMetaCache
|
|
|
|
globalMetaCache = nil
|
|
|
|
defer func() { globalMetaCache = cache }()
|
|
|
|
|
2023-09-25 10:31:26 +08:00
|
|
|
chMgr := NewMockChannelsMgr(t)
|
|
|
|
chMgr.EXPECT().removeDMLStream(mock.Anything).Return()
|
2022-09-27 19:18:54 +08:00
|
|
|
|
|
|
|
node := &Proxy{chMgr: chMgr}
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2022-09-27 19:18:54 +08:00
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
req := &proxypb.InvalidateCollMetaCacheRequest{
|
|
|
|
Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropCollection},
|
|
|
|
}
|
|
|
|
|
|
|
|
status, err := node.InvalidateCollectionMetaCache(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, status.GetErrorCode())
|
|
|
|
}
|
2022-10-18 13:39:26 +08:00
|
|
|
|
|
|
|
func TestProxy_CheckHealth(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
2023-10-01 10:33:30 +08:00
|
|
|
node := &Proxy{session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}}}
|
2022-12-30 18:35:32 +08:00
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2022-10-18 13:39:26 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.CheckHealth(ctx, &milvuspb.CheckHealthRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, false, resp.IsHealthy)
|
|
|
|
assert.Equal(t, 1, len(resp.Reasons))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("proxy health check is ok", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
qc := &mocks.MockQueryCoordClient{}
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().CheckHealth(mock.Anything, mock.Anything).Return(&milvuspb.CheckHealthResponse{IsHealthy: true}, nil)
|
2022-10-18 13:39:26 +08:00
|
|
|
node := &Proxy{
|
|
|
|
rootCoord: NewRootCoordMock(),
|
2023-02-16 15:38:34 +08:00
|
|
|
queryCoord: qc,
|
2022-10-18 13:39:26 +08:00
|
|
|
dataCoord: NewDataCoordMock(),
|
2023-10-01 10:33:30 +08:00
|
|
|
session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}},
|
2022-10-18 13:39:26 +08:00
|
|
|
}
|
2022-12-30 18:35:32 +08:00
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2022-10-18 13:39:26 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.CheckHealth(ctx, &milvuspb.CheckHealthRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, true, resp.IsHealthy)
|
|
|
|
assert.Empty(t, resp.Reasons)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("proxy health check is fail", func(t *testing.T) {
|
|
|
|
checkHealthFunc1 := func(ctx context.Context,
|
2023-09-21 09:45:27 +08:00
|
|
|
req *milvuspb.CheckHealthRequest,
|
2023-09-26 09:57:25 +08:00
|
|
|
opts ...grpc.CallOption,
|
2023-09-21 09:45:27 +08:00
|
|
|
) (*milvuspb.CheckHealthResponse, error) {
|
2022-10-18 13:39:26 +08:00
|
|
|
return &milvuspb.CheckHealthResponse{
|
|
|
|
IsHealthy: false,
|
|
|
|
Reasons: []string{"unHealth"},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
dataCoordMock := NewDataCoordMock()
|
|
|
|
dataCoordMock.checkHealthFunc = checkHealthFunc1
|
2023-02-16 15:38:34 +08:00
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
qc := &mocks.MockQueryCoordClient{}
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().CheckHealth(mock.Anything, mock.Anything).Return(nil, errors.New("test"))
|
2022-10-18 13:39:26 +08:00
|
|
|
node := &Proxy{
|
2023-10-01 10:33:30 +08:00
|
|
|
session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}},
|
2022-10-18 13:39:26 +08:00
|
|
|
rootCoord: NewRootCoordMock(func(mock *RootCoordMock) {
|
|
|
|
mock.checkHealthFunc = checkHealthFunc1
|
|
|
|
}),
|
2023-02-16 15:38:34 +08:00
|
|
|
queryCoord: qc,
|
2023-09-21 09:45:27 +08:00
|
|
|
dataCoord: dataCoordMock,
|
|
|
|
}
|
2022-12-30 18:35:32 +08:00
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2022-10-18 13:39:26 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.CheckHealth(ctx, &milvuspb.CheckHealthRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, false, resp.IsHealthy)
|
2023-01-04 19:37:36 +08:00
|
|
|
assert.Equal(t, 3, len(resp.Reasons))
|
2022-10-18 13:39:26 +08:00
|
|
|
})
|
2022-12-30 18:35:32 +08:00
|
|
|
|
|
|
|
t.Run("check quota state", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
qc := &mocks.MockQueryCoordClient{}
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().CheckHealth(mock.Anything, mock.Anything).Return(&milvuspb.CheckHealthResponse{IsHealthy: true}, nil)
|
2022-12-30 18:35:32 +08:00
|
|
|
node := &Proxy{
|
|
|
|
rootCoord: NewRootCoordMock(),
|
|
|
|
dataCoord: NewDataCoordMock(),
|
2023-02-16 15:38:34 +08:00
|
|
|
queryCoord: qc,
|
2022-12-30 18:35:32 +08:00
|
|
|
}
|
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2022-12-30 18:35:32 +08:00
|
|
|
resp, err := node.CheckHealth(context.Background(), &milvuspb.CheckHealthRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, true, resp.IsHealthy)
|
|
|
|
assert.Equal(t, 0, len(resp.GetQuotaStates()))
|
|
|
|
assert.Equal(t, 0, len(resp.GetReasons()))
|
|
|
|
|
|
|
|
states := []milvuspb.QuotaState{milvuspb.QuotaState_DenyToWrite, milvuspb.QuotaState_DenyToRead}
|
2023-01-06 14:31:37 +08:00
|
|
|
codes := []commonpb.ErrorCode{commonpb.ErrorCode_MemoryQuotaExhausted, commonpb.ErrorCode_ForceDeny}
|
2023-04-25 15:54:35 +08:00
|
|
|
node.multiRateLimiter.SetRates([]*proxypb.CollectionRate{
|
|
|
|
{
|
|
|
|
Collection: 1,
|
|
|
|
States: states,
|
|
|
|
Codes: codes,
|
|
|
|
},
|
|
|
|
})
|
2022-12-30 18:35:32 +08:00
|
|
|
resp, err = node.CheckHealth(context.Background(), &milvuspb.CheckHealthRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, true, resp.IsHealthy)
|
|
|
|
assert.Equal(t, 2, len(resp.GetQuotaStates()))
|
|
|
|
assert.Equal(t, 2, len(resp.GetReasons()))
|
|
|
|
})
|
2022-10-18 13:39:26 +08:00
|
|
|
}
|
2023-01-19 14:13:43 +08:00
|
|
|
|
|
|
|
func TestProxyRenameCollection(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
2023-10-01 10:33:30 +08:00
|
|
|
node := &Proxy{session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}}}
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2023-01-19 14:13:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.RenameCollection(ctx, &milvuspb.RenameCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp), merr.ErrServiceNotReady)
|
2023-01-19 14:13:43 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("rename with illegal new collection name", func(t *testing.T) {
|
2023-10-01 10:33:30 +08:00
|
|
|
node := &Proxy{session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}}}
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-01-19 14:13:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.RenameCollection(ctx, &milvuspb.RenameCollectionRequest{NewName: "$#^%#&#$*!)#@!"})
|
2023-01-24 10:01:46 +08:00
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp), merr.ErrParameterInvalid)
|
2023-01-19 14:13:43 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("rename fail", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
2023-01-19 14:13:43 +08:00
|
|
|
rc.On("RenameCollection", mock.Anything, mock.Anything).
|
|
|
|
Return(nil, errors.New("fail"))
|
|
|
|
node := &Proxy{
|
2023-10-01 10:33:30 +08:00
|
|
|
session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}},
|
2023-01-19 14:13:43 +08:00
|
|
|
rootCoord: rc,
|
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-01-19 14:13:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
resp, err := node.RenameCollection(ctx, &milvuspb.RenameCollectionRequest{NewName: "new"})
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("rename ok", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
2023-01-19 14:13:43 +08:00
|
|
|
rc.On("RenameCollection", mock.Anything, mock.Anything).
|
2023-10-11 21:01:35 +08:00
|
|
|
Return(merr.Success(), nil)
|
2023-01-19 14:13:43 +08:00
|
|
|
node := &Proxy{
|
2023-10-01 10:33:30 +08:00
|
|
|
session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}},
|
2023-01-19 14:13:43 +08:00
|
|
|
rootCoord: rc,
|
|
|
|
}
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-01-19 14:13:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
resp, err := node.RenameCollection(ctx, &milvuspb.RenameCollectionRequest{NewName: "new"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
2023-01-30 10:19:48 +08:00
|
|
|
|
|
|
|
func TestProxy_ResourceGroup(t *testing.T) {
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-01-30 10:19:48 +08:00
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
qc := mocks.NewMockQueryCoordClient(t)
|
2023-01-30 10:19:48 +08:00
|
|
|
node.SetQueryCoordClient(qc)
|
|
|
|
|
|
|
|
tsoAllocatorIns := newMockTsoAllocator()
|
|
|
|
node.sched, err = newTaskScheduler(node.ctx, tsoAllocatorIns, node.factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.sched.Start()
|
|
|
|
defer node.sched.Close()
|
|
|
|
|
|
|
|
rc := &MockRootCoordClientInterface{}
|
|
|
|
mgr := newShardClientMgr()
|
|
|
|
InitMetaCache(ctx, rc, qc, mgr)
|
|
|
|
|
2023-02-16 15:38:34 +08:00
|
|
|
successStatus := &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}
|
|
|
|
|
2023-01-30 10:19:48 +08:00
|
|
|
t.Run("create resource group", func(t *testing.T) {
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().CreateResourceGroup(mock.Anything, mock.Anything).Return(successStatus, nil)
|
2023-01-30 10:19:48 +08:00
|
|
|
resp, err := node.CreateResourceGroup(ctx, &milvuspb.CreateResourceGroupRequest{
|
|
|
|
ResourceGroup: "rg",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.ErrorCode, commonpb.ErrorCode_Success)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("drop resource group", func(t *testing.T) {
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().DropResourceGroup(mock.Anything, mock.Anything).Return(successStatus, nil)
|
2023-01-30 10:19:48 +08:00
|
|
|
resp, err := node.DropResourceGroup(ctx, &milvuspb.DropResourceGroupRequest{
|
|
|
|
ResourceGroup: "rg",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.ErrorCode, commonpb.ErrorCode_Success)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("transfer node", func(t *testing.T) {
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().TransferNode(mock.Anything, mock.Anything).Return(successStatus, nil)
|
2023-01-30 10:19:48 +08:00
|
|
|
resp, err := node.TransferNode(ctx, &milvuspb.TransferNodeRequest{
|
|
|
|
SourceResourceGroup: "rg1",
|
|
|
|
TargetResourceGroup: "rg2",
|
|
|
|
NumNode: 1,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.ErrorCode, commonpb.ErrorCode_Success)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("transfer replica", func(t *testing.T) {
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().TransferReplica(mock.Anything, mock.Anything).Return(successStatus, nil)
|
2023-01-30 10:19:48 +08:00
|
|
|
resp, err := node.TransferReplica(ctx, &milvuspb.TransferReplicaRequest{
|
|
|
|
SourceResourceGroup: "rg1",
|
|
|
|
TargetResourceGroup: "rg2",
|
|
|
|
NumReplica: 1,
|
|
|
|
CollectionName: "collection1",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.ErrorCode, commonpb.ErrorCode_Success)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("list resource group", func(t *testing.T) {
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().ListResourceGroups(mock.Anything, mock.Anything).Return(&milvuspb.ListResourceGroupsResponse{Status: successStatus}, nil)
|
2023-01-30 10:19:48 +08:00
|
|
|
resp, err := node.ListResourceGroups(ctx, &milvuspb.ListResourceGroupsRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.True(t, merr.Ok(resp.GetStatus()))
|
2023-01-30 10:19:48 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("describe resource group", func(t *testing.T) {
|
2023-02-16 15:38:34 +08:00
|
|
|
qc.EXPECT().DescribeResourceGroup(mock.Anything, mock.Anything).Return(&querypb.DescribeResourceGroupResponse{
|
|
|
|
Status: successStatus,
|
|
|
|
ResourceGroup: &querypb.ResourceGroupInfo{
|
|
|
|
Name: "rg",
|
|
|
|
Capacity: 1,
|
|
|
|
NumAvailableNode: 1,
|
|
|
|
NumLoadedReplica: nil,
|
|
|
|
NumOutgoingNode: nil,
|
|
|
|
NumIncomingNode: nil,
|
|
|
|
},
|
|
|
|
}, nil)
|
2023-02-07 19:30:31 +08:00
|
|
|
resp, err := node.DescribeResourceGroup(ctx, &milvuspb.DescribeResourceGroupRequest{
|
|
|
|
ResourceGroup: "rg",
|
|
|
|
})
|
2023-01-30 10:19:48 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.True(t, merr.Ok(resp.GetStatus()))
|
2023-01-30 10:19:48 +08:00
|
|
|
})
|
|
|
|
}
|
2023-02-07 17:52:31 +08:00
|
|
|
|
|
|
|
func TestProxy_InvalidResourceGroupName(t *testing.T) {
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-02-07 17:52:31 +08:00
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
qc := mocks.NewMockQueryCoordClient(t)
|
2023-02-07 17:52:31 +08:00
|
|
|
node.SetQueryCoordClient(qc)
|
2023-02-20 21:14:25 +08:00
|
|
|
qc.EXPECT().DropResourceGroup(mock.Anything, mock.Anything).Return(&commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil)
|
2023-02-07 17:52:31 +08:00
|
|
|
|
|
|
|
tsoAllocatorIns := newMockTsoAllocator()
|
|
|
|
node.sched, err = newTaskScheduler(node.ctx, tsoAllocatorIns, node.factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.sched.Start()
|
|
|
|
defer node.sched.Close()
|
|
|
|
|
|
|
|
rc := &MockRootCoordClientInterface{}
|
|
|
|
mgr := newShardClientMgr()
|
|
|
|
InitMetaCache(ctx, rc, qc, mgr)
|
|
|
|
|
|
|
|
t.Run("create resource group", func(t *testing.T) {
|
|
|
|
resp, err := node.CreateResourceGroup(ctx, &milvuspb.CreateResourceGroupRequest{
|
|
|
|
ResourceGroup: "...",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp), merr.ErrParameterInvalid)
|
2023-02-07 17:52:31 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("drop resource group", func(t *testing.T) {
|
|
|
|
resp, err := node.DropResourceGroup(ctx, &milvuspb.DropResourceGroupRequest{
|
|
|
|
ResourceGroup: "...",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2023-02-16 10:48:34 +08:00
|
|
|
assert.Equal(t, resp.ErrorCode, commonpb.ErrorCode_Success)
|
2023-02-07 17:52:31 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("transfer node", func(t *testing.T) {
|
|
|
|
resp, err := node.TransferNode(ctx, &milvuspb.TransferNodeRequest{
|
|
|
|
SourceResourceGroup: "...",
|
|
|
|
TargetResourceGroup: "!!!",
|
|
|
|
NumNode: 1,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp), merr.ErrParameterInvalid)
|
2023-02-07 17:52:31 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("transfer replica", func(t *testing.T) {
|
|
|
|
resp, err := node.TransferReplica(ctx, &milvuspb.TransferReplicaRequest{
|
|
|
|
SourceResourceGroup: "...",
|
|
|
|
TargetResourceGroup: "!!!",
|
|
|
|
NumReplica: 1,
|
|
|
|
CollectionName: "collection1",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp), merr.ErrParameterInvalid)
|
2023-02-07 17:52:31 +08:00
|
|
|
})
|
|
|
|
}
|
2023-03-30 11:28:25 +08:00
|
|
|
|
2023-09-06 10:35:48 +08:00
|
|
|
func TestProxy_FlushAll_DbCollection(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
testName string
|
|
|
|
FlushRequest *milvuspb.FlushAllRequest
|
|
|
|
ExpectedSuccess bool
|
|
|
|
}{
|
|
|
|
{"flushAll", &milvuspb.FlushAllRequest{}, true},
|
|
|
|
{"flushAll set db", &milvuspb.FlushAllRequest{DbName: "default"}, true},
|
|
|
|
{"flushAll set db, db not exist", &milvuspb.FlushAllRequest{DbName: "default2"}, false},
|
|
|
|
}
|
2023-09-21 14:53:25 +08:00
|
|
|
|
|
|
|
cacheBak := globalMetaCache
|
|
|
|
defer func() { globalMetaCache = cacheBak }()
|
|
|
|
// set expectations
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(UniqueID(0), nil).Maybe()
|
|
|
|
|
|
|
|
cache.On("RemoveDatabase",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Maybe()
|
|
|
|
|
|
|
|
globalMetaCache = cache
|
|
|
|
|
2023-09-06 10:35:48 +08:00
|
|
|
for _, test := range tests {
|
2023-10-07 20:53:38 +08:00
|
|
|
t.Run(test.testName, func(t *testing.T) {
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
paramtable.Init()
|
2023-09-06 10:35:48 +08:00
|
|
|
|
2023-10-07 20:53:38 +08:00
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-10-07 20:53:38 +08:00
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
2023-10-20 14:26:09 +08:00
|
|
|
rpcRequestChannel := Params.CommonCfg.ReplicateMsgChannel.GetValue()
|
|
|
|
node.replicateMsgStream, err = node.factory.NewMsgStream(node.ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.replicateMsgStream.AsProducer([]string{rpcRequestChannel})
|
2023-09-06 10:35:48 +08:00
|
|
|
|
2023-10-07 20:53:38 +08:00
|
|
|
Params.Save(Params.ProxyCfg.MaxTaskNum.Key, "1000")
|
|
|
|
node.sched, err = newTaskScheduler(ctx, node.tsoAllocator, node.factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = node.sched.Start()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer node.sched.Close()
|
|
|
|
node.dataCoord = mocks.NewMockDataCoordClient(t)
|
|
|
|
node.rootCoord = mocks.NewMockRootCoordClient(t)
|
|
|
|
successStatus := &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}
|
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).EXPECT().Flush(mock.Anything, mock.Anything).
|
|
|
|
Return(&datapb.FlushResponse{Status: successStatus}, nil).Maybe()
|
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).EXPECT().ShowCollections(mock.Anything, mock.Anything).
|
|
|
|
Return(&milvuspb.ShowCollectionsResponse{Status: successStatus, CollectionNames: []string{"col-0"}}, nil).Maybe()
|
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).EXPECT().ListDatabases(mock.Anything, mock.Anything).
|
|
|
|
Return(&milvuspb.ListDatabasesResponse{Status: successStatus, DbNames: []string{"default"}}, nil).Maybe()
|
2023-09-06 10:35:48 +08:00
|
|
|
|
|
|
|
resp, err := node.FlushAll(ctx, test.FlushRequest)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
if test.ExpectedSuccess {
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.True(t, merr.Ok(resp.GetStatus()))
|
2023-09-06 10:35:48 +08:00
|
|
|
} else {
|
|
|
|
assert.NotEqual(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_Success)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-30 11:28:25 +08:00
|
|
|
func TestProxy_FlushAll(t *testing.T) {
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
2023-06-25 17:20:43 +08:00
|
|
|
paramtable.Init()
|
2023-03-30 11:28:25 +08:00
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-03-30 11:28:25 +08:00
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
2023-10-20 14:26:09 +08:00
|
|
|
rpcRequestChannel := Params.CommonCfg.ReplicateMsgChannel.GetValue()
|
|
|
|
node.replicateMsgStream, err = node.factory.NewMsgStream(node.ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.replicateMsgStream.AsProducer([]string{rpcRequestChannel})
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
Params.Save(Params.ProxyCfg.MaxTaskNum.Key, "1000")
|
2023-03-30 11:28:25 +08:00
|
|
|
node.sched, err = newTaskScheduler(ctx, node.tsoAllocator, node.factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = node.sched.Start()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer node.sched.Close()
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord = mocks.NewMockDataCoordClient(t)
|
|
|
|
node.rootCoord = mocks.NewMockRootCoordClient(t)
|
2023-03-30 11:28:25 +08:00
|
|
|
|
2023-09-21 14:53:25 +08:00
|
|
|
cacheBak := globalMetaCache
|
|
|
|
defer func() { globalMetaCache = cacheBak }()
|
|
|
|
|
2023-03-30 11:28:25 +08:00
|
|
|
// set expectations
|
2023-06-25 17:20:43 +08:00
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(UniqueID(0), nil).Once()
|
|
|
|
|
|
|
|
cache.On("RemoveDatabase",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Maybe()
|
|
|
|
|
2023-03-30 11:28:25 +08:00
|
|
|
globalMetaCache = cache
|
|
|
|
successStatus := &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).EXPECT().Flush(mock.Anything, mock.Anything).
|
2023-03-30 11:28:25 +08:00
|
|
|
Return(&datapb.FlushResponse{Status: successStatus}, nil).Maybe()
|
2023-09-26 09:57:25 +08:00
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).EXPECT().ShowCollections(mock.Anything, mock.Anything).
|
2023-03-30 11:28:25 +08:00
|
|
|
Return(&milvuspb.ShowCollectionsResponse{Status: successStatus, CollectionNames: []string{"col-0"}}, nil).Maybe()
|
2023-09-26 09:57:25 +08:00
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).EXPECT().ListDatabases(mock.Anything, mock.Anything).
|
2023-06-25 17:20:43 +08:00
|
|
|
Return(&milvuspb.ListDatabasesResponse{Status: successStatus, DbNames: []string{"default"}}, nil).Maybe()
|
2023-03-30 11:28:25 +08:00
|
|
|
|
|
|
|
t.Run("FlushAll", func(t *testing.T) {
|
|
|
|
resp, err := node.FlushAll(ctx, &milvuspb.FlushAllRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.True(t, merr.Ok(resp.GetStatus()))
|
2023-03-30 11:28:25 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("FlushAll failed, server is abnormal", func(t *testing.T) {
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2023-03-30 11:28:25 +08:00
|
|
|
resp, err := node.FlushAll(ctx, &milvuspb.FlushAllRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-09-26 17:15:27 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp.GetStatus()), merr.ErrServiceNotReady)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-03-30 11:28:25 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("FlushAll failed, get id failed", func(t *testing.T) {
|
2023-06-25 17:20:43 +08:00
|
|
|
globalMetaCache.(*MockCache).On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(UniqueID(0), errors.New("mock error")).Once()
|
2023-03-30 11:28:25 +08:00
|
|
|
resp, err := node.FlushAll(ctx, &milvuspb.FlushAllRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
2023-06-25 17:20:43 +08:00
|
|
|
globalMetaCache.(*MockCache).On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(UniqueID(0), nil).Once()
|
2023-03-30 11:28:25 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("FlushAll failed, DataCoord flush failed", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).ExpectedCalls = nil
|
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).EXPECT().Flush(mock.Anything, mock.Anything).
|
2023-03-30 11:28:25 +08:00
|
|
|
Return(&datapb.FlushResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "mock err",
|
|
|
|
},
|
|
|
|
}, nil).Maybe()
|
|
|
|
resp, err := node.FlushAll(ctx, &milvuspb.FlushAllRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("FlushAll failed, RootCoord showCollections failed", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).ExpectedCalls = nil
|
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).EXPECT().ListDatabases(mock.Anything, mock.Anything).
|
2023-06-25 17:20:43 +08:00
|
|
|
Return(&milvuspb.ListDatabasesResponse{Status: successStatus, DbNames: []string{"default"}}, nil).Maybe()
|
2023-09-26 09:57:25 +08:00
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).EXPECT().ShowCollections(mock.Anything, mock.Anything).
|
2023-03-30 11:28:25 +08:00
|
|
|
Return(&milvuspb.ShowCollectionsResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "mock err",
|
|
|
|
},
|
|
|
|
}, nil).Maybe()
|
|
|
|
resp, err := node.FlushAll(ctx, &milvuspb.FlushAllRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
|
|
|
})
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
t.Run("FlushAll failed, RootCoord showCollections failed", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).ExpectedCalls = nil
|
|
|
|
node.rootCoord.(*mocks.MockRootCoordClient).EXPECT().ListDatabases(mock.Anything, mock.Anything).
|
2023-06-25 17:20:43 +08:00
|
|
|
Return(&milvuspb.ListDatabasesResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "mock err",
|
|
|
|
},
|
|
|
|
}, nil).Maybe()
|
|
|
|
resp, err := node.FlushAll(ctx, &milvuspb.FlushAllRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
|
|
|
})
|
2023-03-30 11:28:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProxy_GetFlushAllState(t *testing.T) {
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-03-30 11:28:25 +08:00
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord = mocks.NewMockDataCoordClient(t)
|
|
|
|
node.rootCoord = mocks.NewMockRootCoordClient(t)
|
2023-03-30 11:28:25 +08:00
|
|
|
|
|
|
|
// set expectations
|
|
|
|
successStatus := &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).EXPECT().GetFlushAllState(mock.Anything, mock.Anything).
|
2023-03-30 11:28:25 +08:00
|
|
|
Return(&milvuspb.GetFlushAllStateResponse{Status: successStatus}, nil).Maybe()
|
|
|
|
|
|
|
|
t.Run("GetFlushAllState success", func(t *testing.T) {
|
|
|
|
resp, err := node.GetFlushAllState(ctx, &milvuspb.GetFlushAllStateRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.True(t, merr.Ok(resp.GetStatus()))
|
2023-03-30 11:28:25 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetFlushAllState failed, server is abnormal", func(t *testing.T) {
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2023-03-30 11:28:25 +08:00
|
|
|
resp, err := node.GetFlushAllState(ctx, &milvuspb.GetFlushAllStateRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp.GetStatus()), merr.ErrServiceNotReady)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-03-30 11:28:25 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("DataCoord GetFlushAllState failed", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).ExpectedCalls = nil
|
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).EXPECT().GetFlushAllState(mock.Anything, mock.Anything).
|
2023-03-30 11:28:25 +08:00
|
|
|
Return(&milvuspb.GetFlushAllStateResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "mock err",
|
|
|
|
},
|
|
|
|
}, nil)
|
|
|
|
resp, err := node.GetFlushAllState(ctx, &milvuspb.GetFlushAllStateRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
|
|
|
})
|
|
|
|
}
|
2023-04-07 17:30:28 +08:00
|
|
|
|
2023-09-21 14:53:25 +08:00
|
|
|
func TestProxy_GetFlushState(t *testing.T) {
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-09-21 14:53:25 +08:00
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord = mocks.NewMockDataCoordClient(t)
|
|
|
|
node.rootCoord = mocks.NewMockRootCoordClient(t)
|
2023-09-21 14:53:25 +08:00
|
|
|
|
|
|
|
// set expectations
|
|
|
|
successStatus := &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).EXPECT().GetFlushState(mock.Anything, mock.Anything, mock.Anything).
|
2023-09-21 14:53:25 +08:00
|
|
|
Return(&milvuspb.GetFlushStateResponse{Status: successStatus}, nil).Maybe()
|
|
|
|
|
|
|
|
t.Run("GetFlushState success", func(t *testing.T) {
|
|
|
|
resp, err := node.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_Success)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetFlushState failed, server is abnormal", func(t *testing.T) {
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2023-09-21 14:53:25 +08:00
|
|
|
resp, err := node.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_NotReadyServe)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-09-21 14:53:25 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetFlushState with collection name", func(t *testing.T) {
|
|
|
|
resp, err := node.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{
|
|
|
|
CollectionName: "*",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp.GetStatus()), merr.ErrParameterInvalid)
|
2023-09-21 14:53:25 +08:00
|
|
|
|
|
|
|
cacheBak := globalMetaCache
|
|
|
|
defer func() { globalMetaCache = cacheBak }()
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(UniqueID(0), nil).Maybe()
|
|
|
|
globalMetaCache = cache
|
|
|
|
|
|
|
|
resp, err = node.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{
|
|
|
|
CollectionName: "collection1",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_Success)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("DataCoord GetFlushState failed", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).ExpectedCalls = nil
|
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).EXPECT().GetFlushState(mock.Anything, mock.Anything, mock.Anything).
|
2023-09-21 14:53:25 +08:00
|
|
|
Return(&milvuspb.GetFlushStateResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "mock err",
|
|
|
|
},
|
|
|
|
}, nil)
|
|
|
|
resp, err := node.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetFlushState return error", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).ExpectedCalls = nil
|
|
|
|
node.dataCoord.(*mocks.MockDataCoordClient).EXPECT().GetFlushState(mock.Anything, mock.Anything, mock.Anything).
|
2023-09-21 14:53:25 +08:00
|
|
|
Return(nil, errors.New("fake error"))
|
|
|
|
resp, err := node.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-04-07 17:30:28 +08:00
|
|
|
func TestProxy_GetReplicas(t *testing.T) {
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-04-07 17:30:28 +08:00
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
2023-09-26 09:57:25 +08:00
|
|
|
mockQC := mocks.NewMockQueryCoordClient(t)
|
|
|
|
mockRC := mocks.NewMockRootCoordClient(t)
|
2023-04-07 17:30:28 +08:00
|
|
|
node.queryCoord = mockQC
|
|
|
|
node.rootCoord = mockRC
|
|
|
|
|
|
|
|
// set expectations
|
|
|
|
successStatus := &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
mockQC.EXPECT().GetReplicas(mock.Anything, mock.AnythingOfType("*milvuspb.GetReplicasRequest")).Return(&milvuspb.GetReplicasResponse{Status: successStatus}, nil)
|
|
|
|
resp, err := node.GetReplicas(ctx, &milvuspb.GetReplicasRequest{
|
|
|
|
CollectionID: 1000,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.True(t, merr.Ok(resp.GetStatus()))
|
2023-04-07 17:30:28 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("proxy_not_healthy", func(t *testing.T) {
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2023-04-07 17:30:28 +08:00
|
|
|
resp, err := node.GetReplicas(ctx, &milvuspb.GetReplicasRequest{
|
|
|
|
CollectionID: 1000,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp.GetStatus()), merr.ErrServiceNotReady)
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-04-07 17:30:28 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("QueryCoordClient_returnsError", func(t *testing.T) {
|
|
|
|
mockQC.ExpectedCalls = nil
|
|
|
|
mockQC.EXPECT().GetReplicas(mock.Anything, mock.AnythingOfType("*milvuspb.GetReplicasRequest")).Return(nil, errors.New("mocked"))
|
|
|
|
|
|
|
|
resp, err := node.GetReplicas(ctx, &milvuspb.GetReplicasRequest{
|
|
|
|
CollectionID: 1000,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, resp.GetStatus().GetErrorCode(), commonpb.ErrorCode_UnexpectedError)
|
|
|
|
})
|
|
|
|
}
|
2023-05-19 12:51:23 +08:00
|
|
|
|
|
|
|
func TestProxy_Connect(t *testing.T) {
|
|
|
|
t.Run("proxy unhealthy", func(t *testing.T) {
|
|
|
|
node := &Proxy{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
resp, err := node.Connect(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
2023-08-03 15:53:07 +08:00
|
|
|
t.Run("failed to list database", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
r := mocks.NewMockRootCoordClient(t)
|
2023-08-03 15:53:07 +08:00
|
|
|
r.On("ListDatabases",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(nil, errors.New("error mock ListDatabases"))
|
|
|
|
|
|
|
|
node := &Proxy{rootCoord: r}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
resp, err := node.Connect(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("list database error", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
r := mocks.NewMockRootCoordClient(t)
|
2023-08-03 15:53:07 +08:00
|
|
|
r.On("ListDatabases",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(&milvuspb.ListDatabasesResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Status(merr.WrapErrServiceNotReady(paramtable.GetRole(), paramtable.GetNodeID(), "initialization")),
|
2023-08-03 15:53:07 +08:00
|
|
|
}, nil)
|
|
|
|
|
|
|
|
node := &Proxy{rootCoord: r}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
resp, err := node.Connect(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("database not found", func(t *testing.T) {
|
|
|
|
md := metadata.New(map[string]string{
|
|
|
|
"dbName": "20230525",
|
|
|
|
})
|
|
|
|
ctx := metadata.NewIncomingContext(context.TODO(), md)
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
r := mocks.NewMockRootCoordClient(t)
|
2023-08-03 15:53:07 +08:00
|
|
|
r.On("ListDatabases",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(&milvuspb.ListDatabasesResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-08-03 15:53:07 +08:00
|
|
|
DbNames: []string{},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
node := &Proxy{rootCoord: r}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
resp, err := node.Connect(ctx, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
2023-05-19 12:51:23 +08:00
|
|
|
t.Run("failed to allocate ts", func(t *testing.T) {
|
2023-08-03 15:53:07 +08:00
|
|
|
md := metadata.New(map[string]string{
|
|
|
|
"dbName": "20230525",
|
|
|
|
})
|
|
|
|
ctx := metadata.NewIncomingContext(context.TODO(), md)
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
r := mocks.NewMockRootCoordClient(t)
|
2023-08-03 15:53:07 +08:00
|
|
|
r.On("ListDatabases",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(&milvuspb.ListDatabasesResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-08-03 15:53:07 +08:00
|
|
|
DbNames: []string{"20230525"},
|
|
|
|
}, nil)
|
|
|
|
|
2023-05-19 12:51:23 +08:00
|
|
|
m := newMockTimestampAllocator(t)
|
|
|
|
m.On("AllocTimestamp",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(nil, errors.New("error mock AllocateTimestamp"))
|
|
|
|
alloc, _ := newTimestampAllocator(m, 199)
|
|
|
|
node := Proxy{
|
|
|
|
tsoAllocator: alloc,
|
2023-08-03 15:53:07 +08:00
|
|
|
rootCoord: r,
|
2023-05-19 12:51:23 +08:00
|
|
|
}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-08-03 15:53:07 +08:00
|
|
|
resp, err := node.Connect(ctx, nil)
|
2023-05-19 12:51:23 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
2023-08-03 15:53:07 +08:00
|
|
|
md := metadata.New(map[string]string{
|
|
|
|
"dbName": "20230525",
|
|
|
|
})
|
|
|
|
ctx := metadata.NewIncomingContext(context.TODO(), md)
|
|
|
|
|
2023-09-26 09:57:25 +08:00
|
|
|
r := mocks.NewMockRootCoordClient(t)
|
2023-08-03 15:53:07 +08:00
|
|
|
r.On("ListDatabases",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(&milvuspb.ListDatabasesResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-08-03 15:53:07 +08:00
|
|
|
DbNames: []string{"20230525"},
|
|
|
|
}, nil)
|
|
|
|
|
2023-05-19 12:51:23 +08:00
|
|
|
m := newMockTimestampAllocator(t)
|
|
|
|
m.On("AllocTimestamp",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(&rootcoordpb.AllocTimestampResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-05-19 12:51:23 +08:00
|
|
|
Timestamp: 20230518,
|
|
|
|
Count: 1,
|
|
|
|
}, nil)
|
|
|
|
alloc, _ := newTimestampAllocator(m, 199)
|
|
|
|
node := Proxy{
|
|
|
|
tsoAllocator: alloc,
|
2023-08-03 15:53:07 +08:00
|
|
|
rootCoord: r,
|
2023-05-19 12:51:23 +08:00
|
|
|
}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-08-03 15:53:07 +08:00
|
|
|
resp, err := node.Connect(ctx, &milvuspb.ConnectRequest{
|
2023-05-19 12:51:23 +08:00
|
|
|
ClientInfo: &commonpb.ClientInfo{},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProxy_ListClientInfos(t *testing.T) {
|
|
|
|
t.Run("proxy unhealthy", func(t *testing.T) {
|
|
|
|
node := &Proxy{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
resp, err := node.ListClientInfos(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
node := Proxy{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
resp, err := node.ListClientInfos(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
2023-06-25 17:20:43 +08:00
|
|
|
|
|
|
|
func TestProxyCreateDatabase(t *testing.T) {
|
|
|
|
paramtable.Init()
|
|
|
|
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
2023-10-01 10:33:30 +08:00
|
|
|
node := &Proxy{session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}}}
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2023-06-25 17:20:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.CreateDatabase(ctx, &milvuspb.CreateDatabaseRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp), merr.ErrServiceNotReady)
|
2023-06-25 17:20:43 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-06-25 17:20:43 +08:00
|
|
|
node.sched, err = newTaskScheduler(ctx, node.tsoAllocator, node.factory)
|
|
|
|
node.sched.ddQueue.setMaxTaskNum(10)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = node.sched.Start()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer node.sched.Close()
|
|
|
|
|
2023-10-20 14:26:09 +08:00
|
|
|
rpcRequestChannel := Params.CommonCfg.ReplicateMsgChannel.GetValue()
|
|
|
|
node.replicateMsgStream, err = node.factory.NewMsgStream(node.ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.replicateMsgStream.AsProducer([]string{rpcRequestChannel})
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
t.Run("create database fail", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
2023-06-25 17:20:43 +08:00
|
|
|
rc.On("CreateDatabase", mock.Anything, mock.Anything).
|
|
|
|
Return(nil, errors.New("fail"))
|
|
|
|
node.rootCoord = rc
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.CreateDatabase(ctx, &milvuspb.CreateDatabaseRequest{DbName: "db"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("create database ok", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
2023-06-25 17:20:43 +08:00
|
|
|
rc.On("CreateDatabase", mock.Anything, mock.Anything).
|
2023-10-11 21:01:35 +08:00
|
|
|
Return(merr.Success(), nil)
|
2023-06-25 17:20:43 +08:00
|
|
|
node.rootCoord = rc
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-06-25 17:20:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
resp, err := node.CreateDatabase(ctx, &milvuspb.CreateDatabaseRequest{DbName: "db"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProxyDropDatabase(t *testing.T) {
|
|
|
|
paramtable.Init()
|
|
|
|
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
2023-10-01 10:33:30 +08:00
|
|
|
node := &Proxy{session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}}}
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2023-06-25 17:20:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.DropDatabase(ctx, &milvuspb.DropDatabaseRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-10-09 10:09:33 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp), merr.ErrServiceNotReady)
|
2023-06-25 17:20:43 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-06-25 17:20:43 +08:00
|
|
|
node.sched, err = newTaskScheduler(ctx, node.tsoAllocator, node.factory)
|
|
|
|
node.sched.ddQueue.setMaxTaskNum(10)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = node.sched.Start()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer node.sched.Close()
|
|
|
|
|
2023-10-20 14:26:09 +08:00
|
|
|
rpcRequestChannel := Params.CommonCfg.ReplicateMsgChannel.GetValue()
|
|
|
|
node.replicateMsgStream, err = node.factory.NewMsgStream(node.ctx)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.replicateMsgStream.AsProducer([]string{rpcRequestChannel})
|
|
|
|
|
2023-06-25 17:20:43 +08:00
|
|
|
t.Run("drop database fail", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
2023-06-25 17:20:43 +08:00
|
|
|
rc.On("DropDatabase", mock.Anything, mock.Anything).
|
|
|
|
Return(nil, errors.New("fail"))
|
|
|
|
node.rootCoord = rc
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.DropDatabase(ctx, &milvuspb.DropDatabaseRequest{DbName: "db"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("drop database ok", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
2023-06-25 17:20:43 +08:00
|
|
|
rc.On("DropDatabase", mock.Anything, mock.Anything).
|
2023-10-11 21:01:35 +08:00
|
|
|
Return(merr.Success(), nil)
|
2023-06-25 17:20:43 +08:00
|
|
|
node.rootCoord = rc
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-06-25 17:20:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
resp, err := node.DropDatabase(ctx, &milvuspb.DropDatabaseRequest{DbName: "db"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestProxyListDatabase(t *testing.T) {
|
|
|
|
paramtable.Init()
|
|
|
|
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
2023-10-01 10:33:30 +08:00
|
|
|
node := &Proxy{session: &sessionutil.Session{SessionRaw: sessionutil.SessionRaw{ServerID: 1}}}
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
2023-06-25 17:20:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.ListDatabases(ctx, &milvuspb.ListDatabasesRequest{})
|
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.ErrorIs(t, merr.Error(resp.GetStatus()), merr.ErrServiceNotReady)
|
2023-06-25 17:20:43 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
node, err := NewProxy(ctx, factory)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
|
|
|
node.multiRateLimiter = NewMultiRateLimiter()
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-06-25 17:20:43 +08:00
|
|
|
node.sched, err = newTaskScheduler(ctx, node.tsoAllocator, node.factory)
|
|
|
|
node.sched.ddQueue.setMaxTaskNum(10)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = node.sched.Start()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer node.sched.Close()
|
|
|
|
|
|
|
|
t.Run("list database fail", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
2023-06-25 17:20:43 +08:00
|
|
|
rc.On("ListDatabases", mock.Anything, mock.Anything).
|
|
|
|
Return(nil, errors.New("fail"))
|
|
|
|
node.rootCoord = rc
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := node.ListDatabases(ctx, &milvuspb.ListDatabasesRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("list database ok", func(t *testing.T) {
|
2023-09-26 09:57:25 +08:00
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
2023-06-25 17:20:43 +08:00
|
|
|
rc.On("ListDatabases", mock.Anything, mock.Anything).
|
|
|
|
Return(&milvuspb.ListDatabasesResponse{
|
2023-10-11 21:01:35 +08:00
|
|
|
Status: merr.Success(),
|
2023-09-21 09:45:27 +08:00
|
|
|
}, nil)
|
2023-06-25 17:20:43 +08:00
|
|
|
node.rootCoord = rc
|
2023-10-09 10:09:33 +08:00
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
2023-06-25 17:20:43 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
resp, err := node.ListDatabases(ctx, &milvuspb.ListDatabasesRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
2023-07-25 10:05:00 +08:00
|
|
|
|
|
|
|
func TestProxy_AllocTimestamp(t *testing.T) {
|
|
|
|
t.Run("proxy unhealthy", func(t *testing.T) {
|
|
|
|
node := &Proxy{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
resp, err := node.AllocTimestamp(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
node := &Proxy{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
node.tsoAllocator = ×tampAllocator{
|
|
|
|
tso: newMockTimestampAllocatorInterface(),
|
|
|
|
}
|
|
|
|
|
|
|
|
resp, err := node.AllocTimestamp(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed", func(t *testing.T) {
|
|
|
|
m := newMockTimestampAllocator(t)
|
|
|
|
m.On("AllocTimestamp",
|
|
|
|
mock.Anything,
|
|
|
|
mock.Anything,
|
|
|
|
).Return(&rootcoordpb.AllocTimestampResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_UnexpectedError,
|
|
|
|
Reason: "failed",
|
|
|
|
},
|
|
|
|
Timestamp: 20230518,
|
|
|
|
Count: 1,
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
alloc, _ := newTimestampAllocator(m, 199)
|
|
|
|
node := Proxy{
|
|
|
|
tsoAllocator: alloc,
|
|
|
|
}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
resp, err := node.AllocTimestamp(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
2023-10-20 14:26:09 +08:00
|
|
|
|
2024-01-17 19:16:55 +08:00
|
|
|
func TestProxy_Delete(t *testing.T) {
|
|
|
|
collectionName := "test_delete"
|
|
|
|
collectionID := int64(111)
|
|
|
|
partitionName := "default"
|
|
|
|
partitionID := int64(222)
|
|
|
|
channels := []string{"test_vchannel"}
|
|
|
|
dbName := "test_1"
|
|
|
|
collSchema := &schemapb.CollectionSchema{
|
|
|
|
Name: collectionName,
|
|
|
|
Description: "",
|
|
|
|
AutoID: false,
|
|
|
|
Fields: []*schemapb.FieldSchema{
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID,
|
|
|
|
Name: "pk",
|
|
|
|
IsPrimaryKey: true,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
FieldID: common.StartOfUserFieldID + 1,
|
|
|
|
Name: "non_pk",
|
|
|
|
IsPrimaryKey: false,
|
|
|
|
DataType: schemapb.DataType_Int64,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
schema := newSchemaInfo(collSchema)
|
|
|
|
paramtable.Init()
|
|
|
|
|
|
|
|
t.Run("delete run failed", func(t *testing.T) {
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
chMgr := NewMockChannelsMgr(t)
|
|
|
|
|
|
|
|
req := &milvuspb.DeleteRequest{
|
|
|
|
CollectionName: collectionName,
|
|
|
|
DbName: dbName,
|
|
|
|
PartitionName: partitionName,
|
|
|
|
Expr: "pk in [1, 2, 3]",
|
|
|
|
}
|
|
|
|
cache := NewMockCache(t)
|
|
|
|
cache.On("GetCollectionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(collectionID, nil)
|
|
|
|
cache.On("GetCollectionSchema",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(schema, nil)
|
|
|
|
cache.On("GetPartitionID",
|
|
|
|
mock.Anything, // context.Context
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
mock.AnythingOfType("string"),
|
|
|
|
).Return(partitionID, nil)
|
|
|
|
chMgr.On("getVChannels", mock.Anything).Return(channels, nil)
|
|
|
|
chMgr.On("getChannels", mock.Anything).Return(nil, fmt.Errorf("mock error"))
|
|
|
|
globalMetaCache = cache
|
|
|
|
rc := mocks.NewMockRootCoordClient(t)
|
|
|
|
tsoAllocator := &mockTsoAllocator{}
|
|
|
|
idAllocator, err := allocator.NewIDAllocator(ctx, rc, 0)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
queue, err := newTaskScheduler(ctx, tsoAllocator, nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
node := &Proxy{chMgr: chMgr, rowIDAllocator: idAllocator, sched: queue}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.Delete(ctx, req)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Error(t, merr.Error(resp.GetStatus()))
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-10-20 14:26:09 +08:00
|
|
|
func TestProxy_ReplicateMessage(t *testing.T) {
|
|
|
|
paramtable.Init()
|
|
|
|
defer paramtable.Get().Save(paramtable.Get().CommonCfg.TTMsgEnabled.Key, "true")
|
|
|
|
t.Run("proxy unhealthy", func(t *testing.T) {
|
|
|
|
node := &Proxy{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Abnormal)
|
|
|
|
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, 0, resp.GetStatus().GetCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("not backup instance", func(t *testing.T) {
|
|
|
|
node := &Proxy{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, 0, resp.GetStatus().GetCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("empty channel name", func(t *testing.T) {
|
|
|
|
node := &Proxy{}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
paramtable.Get().Save(paramtable.Get().CommonCfg.TTMsgEnabled.Key, "false")
|
|
|
|
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), nil)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, 0, resp.GetStatus().GetCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("fail to get msg stream", func(t *testing.T) {
|
|
|
|
factory := newMockMsgStreamFactory()
|
|
|
|
factory.f = func(ctx context.Context) (msgstream.MsgStream, error) {
|
|
|
|
return nil, errors.New("mock error: get msg stream")
|
|
|
|
}
|
|
|
|
resourceManager := resource.NewManager(time.Second, 2*time.Second, nil)
|
|
|
|
manager := NewReplicateStreamManager(context.Background(), factory, resourceManager)
|
|
|
|
|
|
|
|
node := &Proxy{
|
|
|
|
replicateStreamManager: manager,
|
|
|
|
}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
paramtable.Get().Save(paramtable.Get().CommonCfg.TTMsgEnabled.Key, "false")
|
|
|
|
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), &milvuspb.ReplicateMessageRequest{ChannelName: "unit_test_replicate_message"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, 0, resp.GetStatus().GetCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("get latest position", func(t *testing.T) {
|
|
|
|
paramtable.Get().Save(paramtable.Get().CommonCfg.TTMsgEnabled.Key, "false")
|
|
|
|
defer paramtable.Get().Save(paramtable.Get().CommonCfg.TTMsgEnabled.Key, "true")
|
|
|
|
|
|
|
|
factory := dependency.NewMockFactory(t)
|
|
|
|
stream := msgstream.NewMockMsgStream(t)
|
|
|
|
mockMsgID := mqwrapper.NewMockMessageID(t)
|
|
|
|
|
|
|
|
factory.EXPECT().NewMsgStream(mock.Anything).Return(stream, nil).Once()
|
|
|
|
mockMsgID.EXPECT().Serialize().Return([]byte("mock")).Once()
|
|
|
|
stream.EXPECT().AsConsumer(mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil).Once()
|
|
|
|
stream.EXPECT().GetLatestMsgID(mock.Anything).Return(mockMsgID, nil).Once()
|
|
|
|
stream.EXPECT().Close().Return()
|
|
|
|
node := &Proxy{
|
|
|
|
factory: factory,
|
|
|
|
}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), &milvuspb.ReplicateMessageRequest{
|
|
|
|
ChannelName: Params.CommonCfg.ReplicateMsgChannel.GetValue(),
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 0, resp.GetStatus().GetCode())
|
|
|
|
assert.Equal(t, base64.StdEncoding.EncodeToString([]byte("mock")), resp.GetPosition())
|
|
|
|
|
|
|
|
factory.EXPECT().NewMsgStream(mock.Anything).Return(nil, errors.New("mock")).Once()
|
|
|
|
resp, err = node.ReplicateMessage(context.TODO(), &milvuspb.ReplicateMessageRequest{
|
|
|
|
ChannelName: Params.CommonCfg.ReplicateMsgChannel.GetValue(),
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqualValues(t, 0, resp.GetStatus().GetCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("invalid msg pack", func(t *testing.T) {
|
|
|
|
node := &Proxy{
|
|
|
|
replicateStreamManager: NewReplicateStreamManager(context.Background(), nil, nil),
|
|
|
|
}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
paramtable.Get().Save(paramtable.Get().CommonCfg.TTMsgEnabled.Key, "false")
|
|
|
|
{
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), &milvuspb.ReplicateMessageRequest{
|
|
|
|
ChannelName: "unit_test_replicate_message",
|
|
|
|
Msgs: [][]byte{{1, 2, 3}},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, 0, resp.GetStatus().GetCode())
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
timeTickResult := msgpb.TimeTickMsg{}
|
|
|
|
timeTickMsg := &msgstream.TimeTickMsg{
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
|
|
|
BeginTimestamp: 1,
|
|
|
|
EndTimestamp: 10,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
},
|
|
|
|
TimeTickMsg: timeTickResult,
|
|
|
|
}
|
|
|
|
msgBytes, _ := timeTickMsg.Marshal(timeTickMsg)
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), &milvuspb.ReplicateMessageRequest{
|
|
|
|
ChannelName: "unit_test_replicate_message",
|
|
|
|
Msgs: [][]byte{msgBytes.([]byte)},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
log.Info("resp", zap.Any("resp", resp))
|
|
|
|
assert.NotEqual(t, 0, resp.GetStatus().GetCode())
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
timeTickResult := msgpb.TimeTickMsg{
|
|
|
|
Base: commonpbutil.NewMsgBase(
|
|
|
|
commonpbutil.WithMsgType(commonpb.MsgType(-1)),
|
|
|
|
commonpbutil.WithTimeStamp(10),
|
|
|
|
commonpbutil.WithSourceID(-1),
|
|
|
|
),
|
|
|
|
}
|
|
|
|
timeTickMsg := &msgstream.TimeTickMsg{
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
|
|
|
BeginTimestamp: 1,
|
|
|
|
EndTimestamp: 10,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
},
|
|
|
|
TimeTickMsg: timeTickResult,
|
|
|
|
}
|
|
|
|
msgBytes, _ := timeTickMsg.Marshal(timeTickMsg)
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), &milvuspb.ReplicateMessageRequest{
|
|
|
|
ChannelName: "unit_test_replicate_message",
|
|
|
|
Msgs: [][]byte{msgBytes.([]byte)},
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
log.Info("resp", zap.Any("resp", resp))
|
|
|
|
assert.NotEqual(t, 0, resp.GetStatus().GetCode())
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("success", func(t *testing.T) {
|
|
|
|
paramtable.Init()
|
|
|
|
factory := newMockMsgStreamFactory()
|
|
|
|
msgStreamObj := msgstream.NewMockMsgStream(t)
|
|
|
|
msgStreamObj.EXPECT().SetRepackFunc(mock.Anything).Return()
|
|
|
|
msgStreamObj.EXPECT().AsProducer(mock.Anything).Return()
|
|
|
|
msgStreamObj.EXPECT().EnableProduce(mock.Anything).Return()
|
|
|
|
msgStreamObj.EXPECT().Close().Return()
|
|
|
|
mockMsgID1 := mqwrapper.NewMockMessageID(t)
|
|
|
|
mockMsgID2 := mqwrapper.NewMockMessageID(t)
|
|
|
|
mockMsgID2.EXPECT().Serialize().Return([]byte("mock message id 2"))
|
|
|
|
broadcastMock := msgStreamObj.EXPECT().Broadcast(mock.Anything).Return(map[string][]mqwrapper.MessageID{
|
|
|
|
"unit_test_replicate_message": {mockMsgID1, mockMsgID2},
|
|
|
|
}, nil)
|
|
|
|
|
|
|
|
factory.f = func(ctx context.Context) (msgstream.MsgStream, error) {
|
|
|
|
return msgStreamObj, nil
|
|
|
|
}
|
|
|
|
resourceManager := resource.NewManager(time.Second, 2*time.Second, nil)
|
|
|
|
manager := NewReplicateStreamManager(context.Background(), factory, resourceManager)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
dataCoord := &mockDataCoord{}
|
|
|
|
dataCoord.expireTime = Timestamp(1000)
|
|
|
|
segAllocator, err := newSegIDAssigner(ctx, dataCoord, getLastTick1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
segAllocator.Start()
|
|
|
|
|
|
|
|
node := &Proxy{
|
|
|
|
replicateStreamManager: manager,
|
|
|
|
segAssigner: segAllocator,
|
|
|
|
}
|
|
|
|
node.UpdateStateCode(commonpb.StateCode_Healthy)
|
|
|
|
paramtable.Get().Save(paramtable.Get().CommonCfg.TTMsgEnabled.Key, "false")
|
|
|
|
|
|
|
|
insertMsg := &msgstream.InsertMsg{
|
|
|
|
BaseMsg: msgstream.BaseMsg{
|
|
|
|
BeginTimestamp: 4,
|
|
|
|
EndTimestamp: 10,
|
|
|
|
HashValues: []uint32{0},
|
|
|
|
MsgPosition: &msgstream.MsgPosition{
|
|
|
|
ChannelName: "unit_test_replicate_message",
|
|
|
|
MsgID: []byte("mock message id 2"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
InsertRequest: msgpb.InsertRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_Insert,
|
|
|
|
MsgID: 10001,
|
|
|
|
Timestamp: 10,
|
|
|
|
SourceID: -1,
|
|
|
|
},
|
|
|
|
ShardName: "unit_test_replicate_message_v1",
|
|
|
|
DbName: "default",
|
|
|
|
CollectionName: "foo_collection",
|
|
|
|
PartitionName: "_default",
|
|
|
|
DbID: 1,
|
|
|
|
CollectionID: 11,
|
|
|
|
PartitionID: 22,
|
|
|
|
SegmentID: 33,
|
|
|
|
Timestamps: []uint64{10},
|
|
|
|
RowIDs: []int64{66},
|
|
|
|
NumRows: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
msgBytes, _ := insertMsg.Marshal(insertMsg)
|
|
|
|
|
|
|
|
replicateRequest := &milvuspb.ReplicateMessageRequest{
|
|
|
|
ChannelName: "unit_test_replicate_message",
|
|
|
|
BeginTs: 1,
|
|
|
|
EndTs: 10,
|
|
|
|
Msgs: [][]byte{msgBytes.([]byte)},
|
|
|
|
StartPositions: []*msgpb.MsgPosition{
|
|
|
|
{ChannelName: "unit_test_replicate_message", MsgID: []byte("mock message id 1")},
|
|
|
|
},
|
|
|
|
EndPositions: []*msgpb.MsgPosition{
|
|
|
|
{ChannelName: "unit_test_replicate_message", MsgID: []byte("mock message id 2")},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), replicateRequest)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 0, resp.GetStatus().GetCode())
|
|
|
|
assert.Equal(t, base64.StdEncoding.EncodeToString([]byte("mock message id 2")), resp.GetPosition())
|
|
|
|
|
|
|
|
res := resourceManager.Delete(ReplicateMsgStreamTyp, replicateRequest.GetChannelName())
|
|
|
|
assert.NotNil(t, res)
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
|
|
|
{
|
|
|
|
broadcastMock.Unset()
|
|
|
|
broadcastMock = msgStreamObj.EXPECT().Broadcast(mock.Anything).Return(nil, errors.New("mock error: broadcast"))
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), replicateRequest)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqualValues(t, 0, resp.GetStatus().GetCode())
|
|
|
|
resourceManager.Delete(ReplicateMsgStreamTyp, replicateRequest.GetChannelName())
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
}
|
|
|
|
{
|
|
|
|
broadcastMock.Unset()
|
|
|
|
broadcastMock = msgStreamObj.EXPECT().Broadcast(mock.Anything).Return(map[string][]mqwrapper.MessageID{
|
|
|
|
"unit_test_replicate_message": {},
|
|
|
|
}, nil)
|
|
|
|
resp, err := node.ReplicateMessage(context.TODO(), replicateRequest)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, 0, resp.GetStatus().GetCode())
|
|
|
|
assert.Empty(t, resp.GetPosition())
|
|
|
|
resourceManager.Delete(ReplicateMsgStreamTyp, replicateRequest.GetChannelName())
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
broadcastMock.Unset()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|