2021-06-18 21:30:08 +08:00
|
|
|
package rootcoord
|
2021-01-24 20:26:35 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-09-24 12:42:51 +08:00
|
|
|
"errors"
|
2022-09-29 18:35:02 +08:00
|
|
|
"fmt"
|
2021-01-24 20:26:35 +08:00
|
|
|
"math/rand"
|
2022-09-26 18:06:54 +08:00
|
|
|
"sync"
|
2021-01-24 20:26:35 +08:00
|
|
|
"testing"
|
2022-09-21 15:46:51 +08:00
|
|
|
"time"
|
2022-09-05 13:29:11 +08:00
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
"github.com/golang/protobuf/proto"
|
2022-10-16 20:49:27 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/milvuspb"
|
2022-09-26 18:06:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/allocator"
|
2022-11-03 14:41:35 +08:00
|
|
|
memkv "github.com/milvus-io/milvus/internal/kv/mem"
|
2022-11-07 17:11:02 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/kv/mocks"
|
2022-09-24 12:42:51 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/metastore/model"
|
2022-09-26 18:06:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/etcdpb"
|
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2022-09-24 12:42:51 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/proxypb"
|
2022-09-26 18:06:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/rootcoordpb"
|
2022-09-29 18:35:02 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/dependency"
|
|
|
|
"github.com/milvus-io/milvus/internal/util/etcd"
|
2022-09-26 18:06:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/funcutil"
|
2022-03-28 16:41:28 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/metricsinfo"
|
2022-11-04 14:25:38 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/paramtable"
|
2021-05-21 16:08:12 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/sessionutil"
|
2022-09-26 18:06:54 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
2022-09-29 18:35:02 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-11-07 17:11:02 +08:00
|
|
|
"github.com/stretchr/testify/mock"
|
2022-09-05 13:29:11 +08:00
|
|
|
)
|
2022-08-04 11:04:34 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestRootCoord_CreateCollection(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.CreateCollection(ctx, &milvuspb.CreateCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
2021-06-25 16:48:10 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.CreateCollection(ctx, &milvuspb.CreateCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-06-25 16:48:10 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.CreateCollection(ctx, &milvuspb.CreateCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-03-08 15:46:51 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
2022-05-31 16:36:03 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.CreateCollection(ctx, &milvuspb.CreateCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2022-05-31 16:36:03 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestRootCoord_DropCollection(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DropCollection(ctx, &milvuspb.DropCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-07-03 14:36:18 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
2021-03-13 17:05:36 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DropCollection(ctx, &milvuspb.DropCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-11-11 00:54:45 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
2022-04-06 15:33:32 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DropCollection(ctx, &milvuspb.DropCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2022-03-21 15:47:23 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
2022-04-25 11:07:47 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DropCollection(ctx, &milvuspb.DropCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2022-06-15 12:20:10 +08:00
|
|
|
}
|
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_CreatePartition(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.CreatePartition(ctx, &milvuspb.CreatePartitionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2022-06-15 12:20:10 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
c := newTestCore(withHealthyCode(),
|
2022-10-28 13:25:34 +08:00
|
|
|
withInvalidScheduler())
|
2021-02-05 14:09:55 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.CreatePartition(ctx, &milvuspb.CreatePartitionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2021-06-25 16:48:10 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
c := newTestCore(withHealthyCode(),
|
2022-10-28 13:25:34 +08:00
|
|
|
withTaskFailScheduler())
|
2021-06-25 16:48:10 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.CreatePartition(ctx, &milvuspb.CreatePartitionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2021-02-05 14:09:55 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
2022-10-28 13:25:34 +08:00
|
|
|
withValidScheduler())
|
2021-06-22 16:08:08 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.CreatePartition(ctx, &milvuspb.CreatePartitionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_DropPartition(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.DropPartition(ctx, &milvuspb.DropPartitionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2021-06-25 16:48:10 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DropPartition(ctx, &milvuspb.DropPartitionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-02-04 14:37:12 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DropPartition(ctx, &milvuspb.DropPartitionRequest{})
|
2022-09-24 12:42:51 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-02-04 14:37:12 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DropPartition(ctx, &milvuspb.DropPartitionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2021-06-04 15:00:34 +08:00
|
|
|
}
|
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_CreateAlias(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.CreateAlias(ctx, &milvuspb.CreateAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.CreateAlias(ctx, &milvuspb.CreateAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.CreateAlias(ctx, &milvuspb.CreateAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2022-09-24 12:42:51 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.CreateAlias(ctx, &milvuspb.CreateAliasRequest{})
|
2022-09-24 12:42:51 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
|
|
|
}
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_DropAlias(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.DropAlias(ctx, &milvuspb.DropAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-10-13 15:54:33 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.DropAlias(ctx, &milvuspb.DropAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.DropAlias(ctx, &milvuspb.DropAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.DropAlias(ctx, &milvuspb.DropAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-09-15 22:05:49 +08:00
|
|
|
}
|
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_AlterAlias(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.AlterAlias(ctx, &milvuspb.AlterAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-09-15 22:05:49 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.AlterAlias(ctx, &milvuspb.AlterAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-09-15 22:05:49 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.AlterAlias(ctx, &milvuspb.AlterAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2021-09-15 22:05:49 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.AlterAlias(ctx, &milvuspb.AlterAliasRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2022-04-21 19:57:42 +08:00
|
|
|
}
|
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_DescribeCollection(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.DescribeCollection(ctx, &milvuspb.DescribeCollectionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-02-05 14:09:55 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DescribeCollection(ctx, &milvuspb.DescribeCollectionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-10-28 13:25:34 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
2021-12-29 14:35:21 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DescribeCollection(ctx, &milvuspb.DescribeCollectionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-06-03 18:03:33 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.DescribeCollection(ctx, &milvuspb.DescribeCollectionRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
2021-06-11 16:39:29 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_HasCollection(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.HasCollection(ctx, &milvuspb.HasCollectionRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
c := newTestCore(withHealthyCode(),
|
2022-10-28 13:25:34 +08:00
|
|
|
withInvalidScheduler())
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.HasCollection(ctx, &milvuspb.HasCollectionRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
c := newTestCore(withHealthyCode(),
|
2022-10-28 13:25:34 +08:00
|
|
|
withTaskFailScheduler())
|
2022-09-24 12:42:51 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.HasCollection(ctx, &milvuspb.HasCollectionRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
2022-10-28 13:25:34 +08:00
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
2022-09-24 12:42:51 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.HasCollection(ctx, &milvuspb.HasCollectionRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_ShowCollections(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.ShowCollections(ctx, &milvuspb.ShowCollectionsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.ShowCollections(ctx, &milvuspb.ShowCollectionsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
2022-10-28 13:25:34 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.ShowCollections(ctx, &milvuspb.ShowCollectionsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
2022-10-28 13:25:34 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.ShowCollections(ctx, &milvuspb.ShowCollectionsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_HasPartition(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.HasPartition(ctx, &milvuspb.HasPartitionRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
2021-03-22 16:36:10 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.HasPartition(ctx, &milvuspb.HasPartitionRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
2022-10-28 13:25:34 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.HasPartition(ctx, &milvuspb.HasPartitionRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
2022-10-28 13:25:34 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.HasPartition(ctx, &milvuspb.HasPartitionRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-10-28 13:25:34 +08:00
|
|
|
func TestRootCoord_ShowPartitions(t *testing.T) {
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.ShowPartitions(ctx, &milvuspb.ShowPartitionsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-09-05 13:29:11 +08:00
|
|
|
})
|
2021-01-24 20:26:35 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to add task", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.ShowPartitions(ctx, &milvuspb.ShowPartitionsRequest{})
|
2022-03-31 13:51:28 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-03-31 13:51:28 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to execute", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.ShowPartitions(ctx, &milvuspb.ShowPartitionsRequest{})
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-03-31 13:51:28 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case, everything is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
|
|
|
ctx := context.Background()
|
2022-10-28 13:25:34 +08:00
|
|
|
resp, err := c.ShowPartitions(ctx, &milvuspb.ShowPartitionsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-10-28 13:25:34 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-03-31 13:51:28 +08:00
|
|
|
})
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestRootCoord_AllocTimestamp(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.AllocTimestamp(ctx, &rootcoordpb.AllocTimestampRequest{})
|
2022-04-25 17:37:46 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-04-25 17:37:46 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to allocate ts", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidTsoAllocator())
|
|
|
|
resp, err := c.AllocTimestamp(ctx, &rootcoordpb.AllocTimestampRequest{})
|
2022-03-31 13:51:28 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-03-31 13:51:28 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
alloc := newMockTsoAllocator()
|
|
|
|
count := uint32(10)
|
|
|
|
ts := Timestamp(100)
|
|
|
|
alloc.GenerateTSOF = func(count uint32) (uint64, error) {
|
|
|
|
// end ts
|
|
|
|
return ts, nil
|
2022-03-31 13:51:28 +08:00
|
|
|
}
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTsoAllocator(alloc))
|
|
|
|
resp, err := c.AllocTimestamp(ctx, &rootcoordpb.AllocTimestampRequest{Count: count})
|
2022-03-31 13:51:28 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
// begin ts
|
|
|
|
assert.Equal(t, ts-uint64(count)+1, resp.GetTimestamp())
|
|
|
|
assert.Equal(t, count, resp.GetCount())
|
|
|
|
})
|
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestRootCoord_AllocID(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.AllocID(ctx, &rootcoordpb.AllocIDRequest{})
|
2022-03-31 13:51:28 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-03-31 13:51:28 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to allocate id", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidIDAllocator())
|
|
|
|
resp, err := c.AllocID(ctx, &rootcoordpb.AllocIDRequest{})
|
2022-04-03 11:37:29 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-04-03 11:37:29 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
alloc := newMockIDAllocator()
|
|
|
|
id := UniqueID(100)
|
|
|
|
alloc.AllocF = func(count uint32) (allocator.UniqueID, allocator.UniqueID, error) {
|
|
|
|
return id, id + int64(count), nil
|
2022-05-12 19:23:53 +08:00
|
|
|
}
|
2022-09-05 13:29:11 +08:00
|
|
|
count := uint32(10)
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withIDAllocator(alloc))
|
|
|
|
resp, err := c.AllocID(ctx, &rootcoordpb.AllocIDRequest{Count: count})
|
2022-03-31 13:51:28 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
assert.Equal(t, id, resp.GetID())
|
|
|
|
assert.Equal(t, count, resp.GetCount())
|
2022-03-31 13:51:28 +08:00
|
|
|
})
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
2022-03-31 13:51:28 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestRootCoord_UpdateChannelTimeTick(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.UpdateChannelTimeTick(ctx, &internalpb.ChannelTimeTickMsg{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2021-09-07 11:16:37 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("invalid msg type", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode())
|
|
|
|
resp, err := c.UpdateChannelTimeTick(ctx, &internalpb.ChannelTimeTickMsg{Base: &commonpb.MsgBase{MsgType: commonpb.MsgType_DropCollection}})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2021-01-24 20:26:35 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("invalid msg", func(t *testing.T) {
|
|
|
|
defer cleanTestEnv()
|
2021-02-05 14:09:55 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ticker := newRocksMqTtSynchronizer()
|
2021-04-08 15:26:18 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTtSynchronizer(ticker))
|
2021-04-08 15:26:18 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
// the length of channel names & timestamps mismatch.
|
|
|
|
resp, err := c.UpdateChannelTimeTick(ctx, &internalpb.ChannelTimeTickMsg{
|
2021-04-08 15:26:18 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2022-09-05 13:29:11 +08:00
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
2021-04-08 15:26:18 +08:00
|
|
|
},
|
2022-09-05 13:29:11 +08:00
|
|
|
ChannelNames: []string{funcutil.GenRandomStr()},
|
|
|
|
Timestamps: []uint64{},
|
2021-04-08 15:26:18 +08:00
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2021-04-08 15:26:18 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
defer cleanTestEnv()
|
2021-04-08 15:26:18 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
source := int64(20220824)
|
|
|
|
ts := Timestamp(100)
|
|
|
|
defaultTs := Timestamp(101)
|
2021-04-08 15:26:18 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ticker := newRocksMqTtSynchronizer()
|
|
|
|
ticker.addSession(&sessionutil.Session{ServerID: source})
|
2021-04-08 15:26:18 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTtSynchronizer(ticker))
|
2021-04-08 15:26:18 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
resp, err := c.UpdateChannelTimeTick(ctx, &internalpb.ChannelTimeTickMsg{
|
2021-04-08 15:26:18 +08:00
|
|
|
Base: &commonpb.MsgBase{
|
2022-09-05 13:29:11 +08:00
|
|
|
SourceID: source,
|
|
|
|
MsgType: commonpb.MsgType_TimeTick,
|
2021-04-08 15:26:18 +08:00
|
|
|
},
|
2022-09-05 13:29:11 +08:00
|
|
|
ChannelNames: []string{funcutil.GenRandomStr()},
|
|
|
|
Timestamps: []uint64{ts},
|
|
|
|
DefaultTimestamp: defaultTs,
|
2021-04-08 15:26:18 +08:00
|
|
|
})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2021-04-08 15:26:18 +08:00
|
|
|
})
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
2021-04-08 15:26:18 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestRootCoord_InvalidateCollectionMetaCache(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.InvalidateCollectionMetaCache(ctx, &proxypb.InvalidateCollMetaCacheRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2021-05-21 16:08:12 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to invalidate cache", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidProxyManager())
|
|
|
|
resp, err := c.InvalidateCollectionMetaCache(ctx, &proxypb.InvalidateCollMetaCacheRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2021-09-18 11:13:51 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidProxyManager())
|
|
|
|
resp, err := c.InvalidateCollectionMetaCache(ctx, &proxypb.InvalidateCollMetaCacheRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
2021-09-22 16:20:48 +08:00
|
|
|
})
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
2021-09-22 16:20:48 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestRootCoord_ShowConfigurations(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.ShowConfigurations(ctx, &internalpb.ShowConfigurationsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2021-09-18 11:13:51 +08:00
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
Params.InitOnce()
|
2021-10-08 17:37:53 +08:00
|
|
|
|
2022-08-12 13:20:39 +08:00
|
|
|
pattern := "Port"
|
|
|
|
req := &internalpb.ShowConfigurationsRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
2022-09-05 13:29:11 +08:00
|
|
|
MsgID: rand.Int63(),
|
2022-08-12 13:20:39 +08:00
|
|
|
},
|
|
|
|
Pattern: pattern,
|
|
|
|
}
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode())
|
|
|
|
resp, err := c.ShowConfigurations(ctx, req)
|
2022-08-12 13:20:39 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
assert.Equal(t, 1, len(resp.GetConfiguations()))
|
|
|
|
assert.Equal(t, "rootcoord.port", resp.GetConfiguations()[0].Key)
|
2022-08-12 13:20:39 +08:00
|
|
|
})
|
2022-09-05 13:29:11 +08:00
|
|
|
}
|
2022-08-12 13:20:39 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestRootCoord_GetMetrics(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.GetMetrics(ctx, &milvuspb.GetMetricsRequest{})
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-08-31 11:45:59 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("failed to parse metric type", func(t *testing.T) {
|
|
|
|
req := &milvuspb.GetMetricsRequest{
|
|
|
|
Request: "invalid request",
|
|
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode())
|
|
|
|
resp, err := c.GetMetrics(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-08-31 11:45:59 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("unsupported metric type", func(t *testing.T) {
|
2021-08-31 11:45:59 +08:00
|
|
|
// unsupported metric type
|
|
|
|
unsupportedMetricType := "unsupported"
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(unsupportedMetricType)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode())
|
|
|
|
resp, err := c.GetMetrics(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-08-31 11:45:59 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("normal case", func(t *testing.T) {
|
2021-08-31 11:45:59 +08:00
|
|
|
systemInfoMetricType := metricsinfo.SystemInfoMetrics
|
2022-09-05 13:29:11 +08:00
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(systemInfoMetricType)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withMetricsCacheManager())
|
|
|
|
resp, err := c.GetMetrics(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("get system info metrics from cache", func(t *testing.T) {
|
2021-08-31 11:45:59 +08:00
|
|
|
systemInfoMetricType := metricsinfo.SystemInfoMetrics
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(systemInfoMetricType)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withMetricsCacheManager())
|
|
|
|
c.metricsCacheManager.UpdateSystemInfoMetrics(&milvuspb.GetMetricsResponse{
|
|
|
|
Status: succStatus(),
|
|
|
|
Response: "cached response",
|
|
|
|
ComponentName: "cached component",
|
|
|
|
})
|
|
|
|
resp, err := c.GetMetrics(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2021-08-31 11:45:59 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
})
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("get system info metrics, cache miss", func(t *testing.T) {
|
|
|
|
systemInfoMetricType := metricsinfo.SystemInfoMetrics
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(systemInfoMetricType)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withMetricsCacheManager())
|
|
|
|
c.metricsCacheManager.InvalidateSystemInfoMetrics()
|
|
|
|
resp, err := c.GetMetrics(ctx, req)
|
2022-04-25 17:37:46 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
2021-04-08 15:26:18 +08:00
|
|
|
})
|
2021-04-08 17:31:39 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
t.Run("get system info metrics", func(t *testing.T) {
|
|
|
|
systemInfoMetricType := metricsinfo.SystemInfoMetrics
|
|
|
|
req, err := metricsinfo.ConstructRequestByMetricType(systemInfoMetricType)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withMetricsCacheManager())
|
|
|
|
resp, err := c.getSystemInfoMetrics(ctx, req)
|
2022-04-06 15:33:32 +08:00
|
|
|
assert.NoError(t, err)
|
2022-09-05 13:29:11 +08:00
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
2021-04-08 17:31:39 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestCore_Import(t *testing.T) {
|
2022-09-26 18:06:54 +08:00
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.AddCollectionFunc = func(ctx context.Context, coll *model.Collection) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
meta.ChangeCollectionStateFunc = func(ctx context.Context, collectionID UniqueID, state etcdpb.CollectionState, ts Timestamp) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.Import(ctx, &milvuspb.ImportRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-12-15 11:47:10 +08:00
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
t.Run("bad collection name", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withMeta(meta))
|
|
|
|
meta.GetCollectionIDByNameFunc = func(name string) (UniqueID, error) {
|
|
|
|
return 0, errors.New("error mock GetCollectionIDByName")
|
|
|
|
}
|
2022-09-27 10:44:53 +08:00
|
|
|
meta.GetCollectionByNameFunc = func(ctx context.Context, collectionName string, ts Timestamp) (*model.Collection, error) {
|
|
|
|
return nil, errors.New("collection name not found")
|
|
|
|
}
|
2022-09-26 18:06:54 +08:00
|
|
|
_, err := c.Import(ctx, &milvuspb.ImportRequest{
|
|
|
|
CollectionName: "a-bad-name",
|
|
|
|
})
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("bad partition name", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withMeta(meta))
|
|
|
|
meta.GetCollectionIDByNameFunc = func(name string) (UniqueID, error) {
|
|
|
|
return 100, nil
|
|
|
|
}
|
|
|
|
meta.GetCollectionVirtualChannelsFunc = func(colID int64) []string {
|
|
|
|
return []string{"ch-1", "ch-2"}
|
|
|
|
}
|
|
|
|
meta.GetPartitionByNameFunc = func(collID UniqueID, partitionName string, ts Timestamp) (UniqueID, error) {
|
|
|
|
return 0, errors.New("mock GetPartitionByNameFunc error")
|
|
|
|
}
|
|
|
|
_, err := c.Import(ctx, &milvuspb.ImportRequest{
|
|
|
|
CollectionName: "a-good-name",
|
|
|
|
})
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withMeta(meta))
|
|
|
|
meta.GetCollectionIDByNameFunc = func(name string) (UniqueID, error) {
|
|
|
|
return 100, nil
|
|
|
|
}
|
|
|
|
meta.GetCollectionVirtualChannelsFunc = func(colID int64) []string {
|
|
|
|
return []string{"ch-1", "ch-2"}
|
|
|
|
}
|
|
|
|
meta.GetPartitionByNameFunc = func(collID UniqueID, partitionName string, ts Timestamp) (UniqueID, error) {
|
|
|
|
return 101, nil
|
|
|
|
}
|
2022-09-27 10:44:53 +08:00
|
|
|
coll := &model.Collection{Name: "a-good-name"}
|
|
|
|
meta.GetCollectionByNameFunc = func(ctx context.Context, collectionName string, ts Timestamp) (*model.Collection, error) {
|
|
|
|
return coll.Clone(), nil
|
|
|
|
}
|
2022-09-26 18:06:54 +08:00
|
|
|
_, err := c.Import(ctx, &milvuspb.ImportRequest{
|
|
|
|
CollectionName: "a-good-name",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
2021-05-20 14:14:14 +08:00
|
|
|
}
|
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestCore_GetImportState(t *testing.T) {
|
2022-11-03 14:41:35 +08:00
|
|
|
mockKv := memkv.NewMemoryKV()
|
2022-09-26 18:06:54 +08:00
|
|
|
ti1 := &datapb.ImportTaskInfo{
|
|
|
|
Id: 100,
|
|
|
|
State: &datapb.ImportTaskState{
|
|
|
|
StateCode: commonpb.ImportState_ImportPending,
|
|
|
|
},
|
|
|
|
CreateTs: time.Now().Unix() - 100,
|
|
|
|
}
|
|
|
|
ti2 := &datapb.ImportTaskInfo{
|
|
|
|
Id: 200,
|
|
|
|
State: &datapb.ImportTaskState{
|
|
|
|
StateCode: commonpb.ImportState_ImportPersisted,
|
|
|
|
},
|
|
|
|
CreateTs: time.Now().Unix() - 100,
|
|
|
|
}
|
|
|
|
taskInfo1, err := proto.Marshal(ti1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
taskInfo2, err := proto.Marshal(ti2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
mockKv.Save(BuildImportTaskKey(1), "value")
|
|
|
|
mockKv.Save(BuildImportTaskKey(100), string(taskInfo1))
|
|
|
|
mockKv.Save(BuildImportTaskKey(200), string(taskInfo2))
|
2021-07-03 14:36:18 +08:00
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.GetImportState(ctx, &milvuspb.GetImportStateRequest{
|
|
|
|
Task: 100,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode())
|
|
|
|
c.importManager = newImportManager(ctx, mockKv, nil, nil, nil, nil, nil, nil, nil)
|
|
|
|
resp, err := c.GetImportState(ctx, &milvuspb.GetImportStateRequest{
|
|
|
|
Task: 100,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, int64(100), resp.GetId())
|
|
|
|
assert.NotEqual(t, 0, resp.GetCreateTs())
|
|
|
|
assert.Equal(t, commonpb.ImportState_ImportPending, resp.GetState())
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
2021-01-24 20:26:35 +08:00
|
|
|
}
|
2021-08-25 14:41:52 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestCore_ListImportTasks(t *testing.T) {
|
2022-11-03 14:41:35 +08:00
|
|
|
mockKv := memkv.NewMemoryKV()
|
2022-09-26 18:06:54 +08:00
|
|
|
ti1 := &datapb.ImportTaskInfo{
|
|
|
|
Id: 100,
|
|
|
|
CollectionName: "collection-A",
|
2022-11-07 17:11:02 +08:00
|
|
|
CollectionId: 1,
|
2022-09-26 18:06:54 +08:00
|
|
|
State: &datapb.ImportTaskState{
|
|
|
|
StateCode: commonpb.ImportState_ImportPending,
|
|
|
|
},
|
2022-11-07 17:11:02 +08:00
|
|
|
CreateTs: time.Now().Unix() - 300,
|
2022-09-26 18:06:54 +08:00
|
|
|
}
|
|
|
|
ti2 := &datapb.ImportTaskInfo{
|
|
|
|
Id: 200,
|
|
|
|
CollectionName: "collection-A",
|
2022-11-07 17:11:02 +08:00
|
|
|
CollectionId: 1,
|
2022-09-26 18:06:54 +08:00
|
|
|
State: &datapb.ImportTaskState{
|
|
|
|
StateCode: commonpb.ImportState_ImportPersisted,
|
|
|
|
},
|
2022-11-07 17:11:02 +08:00
|
|
|
CreateTs: time.Now().Unix() - 200,
|
2022-09-26 18:06:54 +08:00
|
|
|
}
|
|
|
|
ti3 := &datapb.ImportTaskInfo{
|
|
|
|
Id: 300,
|
|
|
|
CollectionName: "collection-B",
|
2022-11-07 17:11:02 +08:00
|
|
|
CollectionId: 2,
|
2022-09-26 18:06:54 +08:00
|
|
|
State: &datapb.ImportTaskState{
|
|
|
|
StateCode: commonpb.ImportState_ImportPersisted,
|
|
|
|
},
|
|
|
|
CreateTs: time.Now().Unix() - 100,
|
|
|
|
}
|
|
|
|
taskInfo1, err := proto.Marshal(ti1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
taskInfo2, err := proto.Marshal(ti2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
taskInfo3, err := proto.Marshal(ti3)
|
|
|
|
assert.NoError(t, err)
|
2022-11-07 17:11:02 +08:00
|
|
|
mockKv.Save(BuildImportTaskKey(1), "value") // this item will trigger an error log in importManager.loadFromTaskStore()
|
2022-09-26 18:06:54 +08:00
|
|
|
mockKv.Save(BuildImportTaskKey(100), string(taskInfo1))
|
|
|
|
mockKv.Save(BuildImportTaskKey(200), string(taskInfo2))
|
|
|
|
mockKv.Save(BuildImportTaskKey(300), string(taskInfo3))
|
2021-09-08 15:00:00 +08:00
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.ListImportTasks(ctx, &milvuspb.ListImportTasksRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
2022-11-07 17:11:02 +08:00
|
|
|
verifyTaskFunc := func(task *milvuspb.GetImportStateResponse, taskID int64, colID int64, state commonpb.ImportState) {
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, task.GetStatus().ErrorCode)
|
|
|
|
assert.Equal(t, taskID, task.GetId())
|
|
|
|
assert.Equal(t, state, task.GetState())
|
|
|
|
assert.Equal(t, colID, task.GetCollectionId())
|
|
|
|
}
|
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
t.Run("normal case", func(t *testing.T) {
|
2022-11-07 17:11:02 +08:00
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.GetCollectionByNameFunc = func(ctx context.Context, collectionName string, ts Timestamp) (*model.Collection, error) {
|
|
|
|
if collectionName == ti1.CollectionName {
|
|
|
|
return &model.Collection{
|
|
|
|
CollectionID: ti1.CollectionId,
|
|
|
|
}, nil
|
|
|
|
} else if collectionName == ti3.CollectionName {
|
|
|
|
return &model.Collection{
|
|
|
|
CollectionID: ti3.CollectionId,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
return nil, errors.New("GetCollectionByName error")
|
|
|
|
}
|
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
ctx := context.Background()
|
2022-11-07 17:11:02 +08:00
|
|
|
c := newTestCore(withHealthyCode(), withMeta(meta))
|
2022-09-26 18:06:54 +08:00
|
|
|
c.importManager = newImportManager(ctx, mockKv, nil, nil, nil, nil, nil, nil, nil)
|
2022-11-07 17:11:02 +08:00
|
|
|
|
|
|
|
// list all tasks
|
2022-09-26 18:06:54 +08:00
|
|
|
resp, err := c.ListImportTasks(ctx, &milvuspb.ListImportTasksRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 3, len(resp.GetTasks()))
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
2022-11-07 17:11:02 +08:00
|
|
|
verifyTaskFunc(resp.GetTasks()[0], 100, 1, commonpb.ImportState_ImportPending)
|
|
|
|
verifyTaskFunc(resp.GetTasks()[1], 200, 1, commonpb.ImportState_ImportPersisted)
|
|
|
|
verifyTaskFunc(resp.GetTasks()[2], 300, 2, commonpb.ImportState_ImportPersisted)
|
|
|
|
|
|
|
|
// list tasks of collection-A
|
|
|
|
resp, err = c.ListImportTasks(ctx, &milvuspb.ListImportTasksRequest{
|
|
|
|
CollectionName: "collection-A",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 2, len(resp.GetTasks()))
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
|
|
|
|
// list tasks of collection-B
|
|
|
|
resp, err = c.ListImportTasks(ctx, &milvuspb.ListImportTasksRequest{
|
|
|
|
CollectionName: "collection-B",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(resp.GetTasks()))
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
|
|
|
|
// invalid collection name
|
|
|
|
resp, err = c.ListImportTasks(ctx, &milvuspb.ListImportTasksRequest{
|
|
|
|
CollectionName: "dummy",
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 0, len(resp.GetTasks()))
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_IllegalCollectionName, resp.GetStatus().GetErrorCode())
|
|
|
|
|
|
|
|
// list the latest 2 tasks
|
|
|
|
resp, err = c.ListImportTasks(ctx, &milvuspb.ListImportTasksRequest{
|
|
|
|
Limit: 2,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 2, len(resp.GetTasks()))
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
verifyTaskFunc(resp.GetTasks()[0], 200, 1, commonpb.ImportState_ImportPersisted)
|
|
|
|
verifyTaskFunc(resp.GetTasks()[1], 300, 2, commonpb.ImportState_ImportPersisted)
|
|
|
|
|
|
|
|
// failed to load tasks from store
|
|
|
|
mockTxnKV := &mocks.TxnKV{}
|
|
|
|
mockTxnKV.EXPECT().LoadWithPrefix(mock.Anything).Return(nil, nil, errors.New("mock error"))
|
|
|
|
c.importManager.taskStore = mockTxnKV
|
|
|
|
resp, err = c.ListImportTasks(ctx, &milvuspb.ListImportTasksRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 0, len(resp.GetTasks()))
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetStatus().GetErrorCode())
|
2022-09-26 18:06:54 +08:00
|
|
|
})
|
2021-09-08 15:00:00 +08:00
|
|
|
}
|
2021-11-19 13:57:12 +08:00
|
|
|
|
2022-09-05 13:29:11 +08:00
|
|
|
func TestCore_ReportImport(t *testing.T) {
|
2022-09-26 18:06:54 +08:00
|
|
|
Params.RootCoordCfg.ImportTaskSubPath = "importtask"
|
|
|
|
var countLock sync.RWMutex
|
|
|
|
var globalCount = typeutil.UniqueID(0)
|
|
|
|
var idAlloc = func(count uint32) (typeutil.UniqueID, typeutil.UniqueID, error) {
|
|
|
|
countLock.Lock()
|
|
|
|
defer countLock.Unlock()
|
|
|
|
globalCount++
|
|
|
|
return globalCount, 0, nil
|
|
|
|
}
|
2022-11-03 14:41:35 +08:00
|
|
|
mockKv := memkv.NewMemoryKV()
|
2022-09-26 18:06:54 +08:00
|
|
|
ti1 := &datapb.ImportTaskInfo{
|
|
|
|
Id: 100,
|
|
|
|
State: &datapb.ImportTaskState{
|
|
|
|
StateCode: commonpb.ImportState_ImportPending,
|
|
|
|
},
|
|
|
|
CreateTs: time.Now().Unix() - 100,
|
|
|
|
}
|
|
|
|
ti2 := &datapb.ImportTaskInfo{
|
|
|
|
Id: 200,
|
|
|
|
State: &datapb.ImportTaskState{
|
|
|
|
StateCode: commonpb.ImportState_ImportPersisted,
|
|
|
|
},
|
|
|
|
CreateTs: time.Now().Unix() - 100,
|
|
|
|
}
|
|
|
|
taskInfo1, err := proto.Marshal(ti1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
taskInfo2, err := proto.Marshal(ti2)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
mockKv.Save(BuildImportTaskKey(1), "value")
|
|
|
|
mockKv.Save(BuildImportTaskKey(100), string(taskInfo1))
|
|
|
|
mockKv.Save(BuildImportTaskKey(200), string(taskInfo2))
|
|
|
|
|
|
|
|
ticker := newRocksMqTtSynchronizer()
|
|
|
|
meta := newMockMetaTable()
|
|
|
|
meta.GetCollectionByNameFunc = func(ctx context.Context, collectionName string, ts Timestamp) (*model.Collection, error) {
|
|
|
|
return nil, errors.New("error mock GetCollectionByName")
|
|
|
|
}
|
|
|
|
meta.AddCollectionFunc = func(ctx context.Context, coll *model.Collection) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
meta.ChangeCollectionStateFunc = func(ctx context.Context, collectionID UniqueID, state etcdpb.CollectionState, ts Timestamp) error {
|
|
|
|
return nil
|
|
|
|
}
|
2022-06-14 16:18:09 +08:00
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
dc := newMockDataCoord()
|
2022-10-10 15:55:22 +08:00
|
|
|
dc.GetComponentStatesFunc = func(ctx context.Context) (*milvuspb.ComponentStates, error) {
|
|
|
|
return &milvuspb.ComponentStates{
|
|
|
|
State: &milvuspb.ComponentInfo{
|
2022-09-26 18:06:54 +08:00
|
|
|
NodeID: TestRootCoordID,
|
2022-10-10 15:55:22 +08:00
|
|
|
StateCode: commonpb.StateCode_Healthy,
|
2022-09-26 18:06:54 +08:00
|
|
|
},
|
|
|
|
SubcomponentStates: nil,
|
|
|
|
Status: succStatus(),
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
dc.WatchChannelsFunc = func(ctx context.Context, req *datapb.WatchChannelsRequest) (*datapb.WatchChannelsResponse, error) {
|
|
|
|
return &datapb.WatchChannelsResponse{Status: succStatus()}, nil
|
|
|
|
}
|
|
|
|
dc.FlushFunc = func(ctx context.Context, req *datapb.FlushRequest) (*datapb.FlushResponse, error) {
|
|
|
|
return &datapb.FlushResponse{Status: succStatus()}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
mockCallImportServiceErr := false
|
|
|
|
callImportServiceFn := func(ctx context.Context, req *datapb.ImportTaskRequest) (*datapb.ImportTaskResponse, error) {
|
|
|
|
if mockCallImportServiceErr {
|
|
|
|
return &datapb.ImportTaskResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
},
|
|
|
|
}, errors.New("mock err")
|
|
|
|
}
|
|
|
|
return &datapb.ImportTaskResponse{
|
|
|
|
Status: &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
},
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
callMarkSegmentsDropped := func(ctx context.Context, segIDs []typeutil.UniqueID) (*commonpb.Status, error) {
|
|
|
|
return &commonpb.Status{
|
|
|
|
ErrorCode: commonpb.ErrorCode_Success,
|
|
|
|
}, nil
|
|
|
|
}
|
2022-06-14 16:18:09 +08:00
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.ReportImport(ctx, &rootcoordpb.ImportResult{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
2022-06-14 16:18:09 +08:00
|
|
|
|
2022-09-26 18:06:54 +08:00
|
|
|
t.Run("report complete import", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode())
|
|
|
|
c.importManager = newImportManager(ctx, mockKv, idAlloc, callImportServiceFn, callMarkSegmentsDropped, nil, nil, nil, nil)
|
|
|
|
resp, err := c.ReportImport(ctx, &rootcoordpb.ImportResult{
|
|
|
|
TaskId: 100,
|
|
|
|
State: commonpb.ImportState_ImportCompleted,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
// Change the state back.
|
|
|
|
err = c.importManager.setImportTaskState(100, commonpb.ImportState_ImportPending)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("report complete import with task not found", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode())
|
|
|
|
c.importManager = newImportManager(ctx, mockKv, idAlloc, callImportServiceFn, callMarkSegmentsDropped, nil, nil, nil, nil)
|
|
|
|
resp, err := c.ReportImport(ctx, &rootcoordpb.ImportResult{
|
|
|
|
TaskId: 101,
|
|
|
|
State: commonpb.ImportState_ImportCompleted,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("report import started state", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withHealthyCode())
|
|
|
|
c.importManager = newImportManager(ctx, mockKv, idAlloc, callImportServiceFn, callMarkSegmentsDropped, nil, nil, nil, nil)
|
|
|
|
c.importManager.loadFromTaskStore(true)
|
|
|
|
c.importManager.sendOutTasks(ctx)
|
|
|
|
resp, err := c.ReportImport(ctx, &rootcoordpb.ImportResult{
|
|
|
|
TaskId: 100,
|
|
|
|
State: commonpb.ImportState_ImportStarted,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
// Change the state back.
|
|
|
|
err = c.importManager.setImportTaskState(100, commonpb.ImportState_ImportPending)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("report persisted import", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(
|
|
|
|
withHealthyCode(),
|
|
|
|
withValidIDAllocator(),
|
|
|
|
withMeta(meta),
|
|
|
|
withTtSynchronizer(ticker),
|
|
|
|
withDataCoord(dc))
|
|
|
|
c.broker = newServerBroker(c)
|
|
|
|
c.importManager = newImportManager(ctx, mockKv, idAlloc, callImportServiceFn, callMarkSegmentsDropped, nil, nil, nil, nil)
|
|
|
|
c.importManager.loadFromTaskStore(true)
|
|
|
|
c.importManager.sendOutTasks(ctx)
|
|
|
|
|
|
|
|
resp, err := c.ReportImport(ctx, &rootcoordpb.ImportResult{
|
|
|
|
TaskId: 100,
|
|
|
|
State: commonpb.ImportState_ImportPersisted,
|
|
|
|
})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
// Change the state back.
|
|
|
|
err = c.importManager.setImportTaskState(100, commonpb.ImportState_ImportPending)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
2022-06-14 16:18:09 +08:00
|
|
|
}
|
2022-06-16 20:12:11 +08:00
|
|
|
|
2022-08-04 11:04:34 +08:00
|
|
|
func TestCore_Rbac(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := &Core{
|
|
|
|
ctx: ctx,
|
|
|
|
}
|
|
|
|
|
|
|
|
// not healthy.
|
2022-10-10 15:55:22 +08:00
|
|
|
c.stateCode.Store(commonpb.StateCode_Abnormal)
|
2022-08-04 11:04:34 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
resp, err := c.CreateRole(ctx, &milvuspb.CreateRoleRequest{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
resp, err := c.DropRole(ctx, &milvuspb.DropRoleRequest{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
resp, err := c.OperateUserRole(ctx, &milvuspb.OperateUserRoleRequest{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
resp, err := c.SelectRole(ctx, &milvuspb.SelectRoleRequest{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
resp, err := c.SelectUser(ctx, &milvuspb.SelectUserRequest{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
resp, err := c.OperatePrivilege(ctx, &milvuspb.OperatePrivilegeRequest{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
resp, err := c.SelectGrant(ctx, &milvuspb.SelectGrantRequest{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
resp, err := c.ListPolicy(ctx, &internalpb.ListPolicyRequest{})
|
|
|
|
assert.NotNil(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.Status.ErrorCode)
|
|
|
|
}
|
|
|
|
}
|
2022-09-21 15:46:51 +08:00
|
|
|
|
|
|
|
func TestCore_sendMinDdlTsAsTt(t *testing.T) {
|
|
|
|
ticker := newRocksMqTtSynchronizer()
|
|
|
|
ddlManager := newMockDdlTsLockManager()
|
|
|
|
ddlManager.GetMinDdlTsFunc = func() Timestamp {
|
|
|
|
return 100
|
|
|
|
}
|
2022-10-09 12:32:57 +08:00
|
|
|
sched := newMockScheduler()
|
|
|
|
sched.GetMinDdlTsFunc = func() Timestamp {
|
|
|
|
return 100
|
|
|
|
}
|
2022-09-21 15:46:51 +08:00
|
|
|
c := newTestCore(
|
|
|
|
withTtSynchronizer(ticker),
|
2022-10-09 12:32:57 +08:00
|
|
|
withDdlTsLockManager(ddlManager),
|
|
|
|
withScheduler(sched))
|
2022-11-14 14:41:11 +08:00
|
|
|
|
|
|
|
c.stateCode.Store(commonpb.StateCode_Healthy)
|
|
|
|
c.session.ServerID = TestRootCoordID
|
2022-09-21 15:46:51 +08:00
|
|
|
c.sendMinDdlTsAsTt() // no session.
|
|
|
|
ticker.addSession(&sessionutil.Session{ServerID: TestRootCoordID})
|
|
|
|
c.sendMinDdlTsAsTt()
|
2022-10-09 12:32:57 +08:00
|
|
|
sched.GetMinDdlTsFunc = func() Timestamp {
|
|
|
|
return typeutil.ZeroTimestamp
|
|
|
|
}
|
|
|
|
c.sendMinDdlTsAsTt() // zero ts
|
|
|
|
sched.GetMinDdlTsFunc = func() Timestamp {
|
|
|
|
return typeutil.MaxTimestamp
|
|
|
|
}
|
|
|
|
ddlManager.GetMinDdlTsFunc = func() Timestamp {
|
|
|
|
return typeutil.MaxTimestamp
|
|
|
|
}
|
|
|
|
c.sendMinDdlTsAsTt()
|
2022-09-21 15:46:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCore_startTimeTickLoop(t *testing.T) {
|
|
|
|
ticker := newRocksMqTtSynchronizer()
|
|
|
|
ticker.addSession(&sessionutil.Session{ServerID: TestRootCoordID})
|
|
|
|
ddlManager := newMockDdlTsLockManager()
|
|
|
|
ddlManager.GetMinDdlTsFunc = func() Timestamp {
|
|
|
|
return 100
|
|
|
|
}
|
2022-10-09 12:32:57 +08:00
|
|
|
sched := newMockScheduler()
|
|
|
|
sched.GetMinDdlTsFunc = func() Timestamp {
|
|
|
|
return 100
|
|
|
|
}
|
2022-09-21 15:46:51 +08:00
|
|
|
c := newTestCore(
|
|
|
|
withTtSynchronizer(ticker),
|
2022-10-09 12:32:57 +08:00
|
|
|
withDdlTsLockManager(ddlManager),
|
|
|
|
withScheduler(sched))
|
2022-09-21 15:46:51 +08:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
c.ctx = ctx
|
|
|
|
Params.ProxyCfg.TimeTickInterval = time.Millisecond
|
|
|
|
c.wg.Add(1)
|
2022-11-14 14:41:11 +08:00
|
|
|
c.UpdateStateCode(commonpb.StateCode_Initializing)
|
2022-09-21 15:46:51 +08:00
|
|
|
go c.startTimeTickLoop()
|
|
|
|
|
|
|
|
time.Sleep(time.Millisecond * 4)
|
|
|
|
cancel()
|
|
|
|
c.wg.Wait()
|
|
|
|
}
|
2022-09-29 18:35:02 +08:00
|
|
|
|
|
|
|
// make sure the main functions work well when EnableActiveStandby=true
|
|
|
|
func TestRootcoord_EnableActiveStandby(t *testing.T) {
|
2022-11-17 18:59:09 +08:00
|
|
|
randVal := rand.Int()
|
2022-09-29 18:35:02 +08:00
|
|
|
Params.Init()
|
2022-11-17 18:59:09 +08:00
|
|
|
Params.BaseTable.Save("etcd.rootPath", fmt.Sprintf("/%d", randVal))
|
2022-09-29 18:35:02 +08:00
|
|
|
Params.RootCoordCfg.EnableActiveStandby = true
|
|
|
|
Params.CommonCfg.RootCoordTimeTick = fmt.Sprintf("rootcoord-time-tick-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordStatistics = fmt.Sprintf("rootcoord-statistics-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordSubName = fmt.Sprintf("subname-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordDml = fmt.Sprintf("rootcoord-dml-test-%d", randVal)
|
|
|
|
Params.CommonCfg.RootCoordDelta = fmt.Sprintf("rootcoord-delta-test-%d", randVal)
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
coreFactory := dependency.NewDefaultFactory(true)
|
|
|
|
etcdCli, err := etcd.GetEtcdClient(&Params.EtcdCfg)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer etcdCli.Close()
|
|
|
|
core, err := NewCore(ctx, coreFactory)
|
|
|
|
core.etcdCli = etcdCli
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = core.Init()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = core.Start()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
core.session.TriggerKill = false
|
|
|
|
err = core.Register()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
resp, err := core.DescribeCollection(ctx, &milvuspb.DescribeCollectionRequest{
|
|
|
|
Base: &commonpb.MsgBase{
|
|
|
|
MsgType: commonpb.MsgType_DescribeCollection,
|
|
|
|
MsgID: 0,
|
|
|
|
Timestamp: 0,
|
2022-11-04 14:25:38 +08:00
|
|
|
SourceID: paramtable.GetNodeID(),
|
2022-09-29 18:35:02 +08:00
|
|
|
},
|
|
|
|
CollectionName: "unexist"})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_UnexpectedError, resp.GetStatus().GetErrorCode())
|
|
|
|
err = core.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2022-10-10 20:31:22 +08:00
|
|
|
|
|
|
|
func TestRootCoord_AlterCollection(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.AlterCollection(ctx, &milvuspb.AlterCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("add task failed", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.AlterCollection(ctx, &milvuspb.AlterCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("execute task failed", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withTaskFailScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.AlterCollection(ctx, &milvuspb.AlterCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("run ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.AlterCollection(ctx, &milvuspb.AlterCollectionRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetErrorCode())
|
|
|
|
})
|
|
|
|
}
|
2022-10-18 13:39:26 +08:00
|
|
|
|
|
|
|
func TestRootCoord_CheckHealth(t *testing.T) {
|
|
|
|
t.Run("not healthy", func(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
c := newTestCore(withAbnormalCode())
|
|
|
|
resp, err := c.CheckHealth(ctx, &milvuspb.CheckHealthRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, false, resp.IsHealthy)
|
|
|
|
assert.NotEmpty(t, resp.Reasons)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("proxy health check is ok", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidProxyManager())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.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) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withInvalidProxyManager())
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := c.CheckHealth(ctx, &milvuspb.CheckHealthRequest{})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, false, resp.IsHealthy)
|
|
|
|
assert.NotEmpty(t, resp.Reasons)
|
|
|
|
})
|
|
|
|
}
|
2022-10-25 09:51:30 +08:00
|
|
|
|
|
|
|
func TestCore_Stop(t *testing.T) {
|
|
|
|
t.Run("abnormal stop before component is ready", func(t *testing.T) {
|
|
|
|
c := &Core{}
|
|
|
|
err := c.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
code, ok := c.stateCode.Load().(commonpb.StateCode)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, commonpb.StateCode_Abnormal, code)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
c := newTestCore(withHealthyCode(),
|
|
|
|
withValidScheduler())
|
|
|
|
c.ctx, c.cancel = context.WithCancel(context.Background())
|
|
|
|
err := c.Stop()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
code, ok := c.stateCode.Load().(commonpb.StateCode)
|
|
|
|
assert.True(t, ok)
|
|
|
|
assert.Equal(t, commonpb.StateCode_Abnormal, code)
|
|
|
|
})
|
|
|
|
}
|