milvus/internal/proxy/task_index_test.go
cai.zhang 53a49a9255
GetIndexState only get the state generated call CreateIndex (#17549)
Signed-off-by: Cai.Zhang <cai.zhang@zilliz.com>
2022-06-16 20:12:11 +08:00

84 lines
2.6 KiB
Go

// 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.
package proxy
import (
"context"
"testing"
"github.com/milvus-io/milvus/internal/proto/indexpb"
"github.com/milvus-io/milvus/internal/proto/commonpb"
"github.com/milvus-io/milvus/internal/proto/milvuspb"
"github.com/milvus-io/milvus/internal/util/funcutil"
"github.com/stretchr/testify/assert"
)
func TestGetIndexStateTask_Execute(t *testing.T) {
dbName := funcutil.GenRandomStr()
collectionName := funcutil.GenRandomStr()
collectionID := UniqueID(1)
fieldName := funcutil.GenRandomStr()
indexName := ""
ctx := context.Background()
rootCoord := newMockRootCoord()
indexCoord := newMockIndexCoord()
queryCoord := NewQueryCoordMock()
gist := &getIndexStateTask{
GetIndexStateRequest: &milvuspb.GetIndexStateRequest{
Base: &commonpb.MsgBase{},
DbName: dbName,
CollectionName: collectionName,
FieldName: fieldName,
IndexName: indexName,
},
ctx: ctx,
indexCoord: indexCoord,
rootCoord: rootCoord,
result: &milvuspb.GetIndexStateResponse{
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError, Reason: "mock"},
State: commonpb.IndexState_Unissued,
},
collectionID: collectionID,
}
shardMgr := newShardClientMgr()
// failed to get collection id.
_ = InitMetaCache(rootCoord, queryCoord, shardMgr)
assert.Error(t, gist.Execute(ctx))
rootCoord.GetIndexStateFunc = func(ctx context.Context, request *milvuspb.GetIndexStateRequest) (*indexpb.GetIndexStatesResponse, error) {
return &indexpb.GetIndexStatesResponse{
Status: &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success},
States: []*indexpb.IndexInfo{
{
State: commonpb.IndexState_Finished,
Reason: "",
},
{
State: commonpb.IndexState_IndexStateNone,
Reason: "",
},
},
}, nil
}
assert.NoError(t, gist.Execute(ctx))
assert.Equal(t, commonpb.IndexState_Finished, gist.result.GetState())
}