2021-10-20 19:02:41 +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
|
2021-09-06 17:54:41 +08:00
|
|
|
// with the License. You may obtain a copy of the License at
|
|
|
|
//
|
2021-10-20 19:02:41 +08:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2021-09-06 17:54:41 +08:00
|
|
|
//
|
2021-10-20 19:02:41 +08:00
|
|
|
// 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.
|
2021-09-06 17:54:41 +08:00
|
|
|
|
|
|
|
package grpcindexnode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2022-04-07 22:05:32 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
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"
|
2021-09-06 17:54:41 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/indexnode"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/indexpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2023-09-21 09:45:27 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/metricsinfo"
|
|
|
|
"github.com/milvus-io/milvus/pkg/util/paramtable"
|
2021-09-06 17:54:41 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestIndexNodeServer(t *testing.T) {
|
2022-11-04 14:25:38 +08:00
|
|
|
paramtable.Init()
|
2021-09-06 17:54:41 +08:00
|
|
|
ctx := context.Background()
|
2022-04-07 22:05:32 +08:00
|
|
|
factory := dependency.NewDefaultFactory(true)
|
|
|
|
server, err := NewServer(ctx, factory)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-10-14 18:48:56 +08:00
|
|
|
assert.NotNil(t, server)
|
2021-09-06 17:54:41 +08:00
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
inm := indexnode.NewIndexNodeMock()
|
2023-09-26 09:57:25 +08:00
|
|
|
err = server.setServer(inm)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-06 17:54:41 +08:00
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
err = server.Run()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-06 17:54:41 +08:00
|
|
|
|
|
|
|
t.Run("GetComponentStates", func(t *testing.T) {
|
2022-10-10 15:55:22 +08:00
|
|
|
req := &milvuspb.GetComponentStatesRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
states, err := server.GetComponentStates(ctx, req)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-10 15:55:22 +08:00
|
|
|
assert.Equal(t, commonpb.StateCode_Healthy, states.State.StateCode)
|
2021-09-06 17:54:41 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("GetStatisticsChannel", func(t *testing.T) {
|
|
|
|
req := &internalpb.GetStatisticsChannelRequest{}
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.GetStatisticsChannel(ctx, req)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-09-06 17:54:41 +08:00
|
|
|
})
|
|
|
|
|
2022-08-25 15:48:54 +08:00
|
|
|
t.Run("CreateJob", func(t *testing.T) {
|
|
|
|
req := &indexpb.CreateJobRequest{
|
2022-09-06 17:19:11 +08:00
|
|
|
ClusterID: "",
|
2022-08-25 15:48:54 +08:00
|
|
|
BuildID: 0,
|
|
|
|
IndexID: 0,
|
|
|
|
DataPaths: []string{},
|
2021-09-06 17:54:41 +08:00
|
|
|
}
|
2022-08-25 15:48:54 +08:00
|
|
|
resp, err := server.CreateJob(ctx, req)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2022-08-25 15:48:54 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("QueryJob", func(t *testing.T) {
|
|
|
|
req := &indexpb.QueryJobsRequest{}
|
|
|
|
resp, err := server.QueryJobs(ctx, req)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-08-25 15:48:54 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("DropJobs", func(t *testing.T) {
|
|
|
|
req := &indexpb.DropJobsRequest{}
|
|
|
|
resp, err := server.DropJobs(ctx, req)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-06 17:54:41 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-08-12 13:20:39 +08:00
|
|
|
t.Run("ShowConfigurations", func(t *testing.T) {
|
|
|
|
req := &internalpb.ShowConfigurationsRequest{
|
|
|
|
Pattern: "",
|
|
|
|
}
|
|
|
|
resp, err := server.ShowConfigurations(ctx, req)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-08-12 13:20:39 +08:00
|
|
|
})
|
|
|
|
|
2021-09-06 17:54:41 +08:00
|
|
|
t.Run("GetMetrics", func(t *testing.T) {
|
2021-12-09 14:19:40 +08:00
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(metricsinfo.SystemInfoMetrics)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-10-14 18:48:56 +08:00
|
|
|
resp, err := server.GetMetrics(ctx, req)
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-09-06 17:54:41 +08:00
|
|
|
})
|
|
|
|
|
2022-07-07 14:44:21 +08:00
|
|
|
t.Run("GetTaskSlots", func(t *testing.T) {
|
2022-08-25 15:48:54 +08:00
|
|
|
req := &indexpb.GetJobStatsRequest{}
|
|
|
|
resp, err := server.GetJobStats(ctx, req)
|
2022-07-07 14:44:21 +08:00
|
|
|
assert.NoError(t, err)
|
2023-09-15 10:09:21 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-07-07 14:44:21 +08:00
|
|
|
})
|
|
|
|
|
2021-10-14 18:48:56 +08:00
|
|
|
err = server.Stop()
|
2023-06-08 15:36:36 +08:00
|
|
|
assert.NoError(t, err)
|
2021-09-06 17:54:41 +08:00
|
|
|
}
|