2022-11-21 10:09:10 +08:00
|
|
|
package datacoord
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
2023-01-12 09:55:42 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/mocks"
|
|
|
|
"github.com/stretchr/testify/mock"
|
|
|
|
|
2023-01-04 19:37:36 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-11-21 10:09:10 +08:00
|
|
|
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/commonpb"
|
2023-01-04 19:37:36 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/datapb"
|
2022-11-21 10:09:10 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBroadcastAlteredCollection(t *testing.T) {
|
|
|
|
t.Run("test server is closed", func(t *testing.T) {
|
|
|
|
s := &Server{}
|
|
|
|
s.stateCode.Store(commonpb.StateCode_Initializing)
|
|
|
|
ctx := context.Background()
|
|
|
|
resp, err := s.BroadcastAlteredCollection(ctx, nil)
|
|
|
|
assert.NotNil(t, resp.Reason)
|
|
|
|
assert.Nil(t, err)
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test meta non exist", func(t *testing.T) {
|
|
|
|
s := &Server{meta: &meta{collections: make(map[UniqueID]*collectionInfo, 1)}}
|
|
|
|
s.stateCode.Store(commonpb.StateCode_Healthy)
|
|
|
|
ctx := context.Background()
|
|
|
|
req := &datapb.AlterCollectionRequest{
|
|
|
|
CollectionID: 1,
|
|
|
|
PartitionIDs: []int64{1},
|
|
|
|
Properties: []*commonpb.KeyValuePair{{Key: "k", Value: "v"}},
|
|
|
|
}
|
|
|
|
resp, err := s.BroadcastAlteredCollection(ctx, req)
|
|
|
|
assert.NotNil(t, resp)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(s.meta.collections))
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("test update meta", func(t *testing.T) {
|
|
|
|
s := &Server{meta: &meta{collections: map[UniqueID]*collectionInfo{
|
|
|
|
1: {ID: 1},
|
|
|
|
}}}
|
|
|
|
s.stateCode.Store(commonpb.StateCode_Healthy)
|
|
|
|
ctx := context.Background()
|
|
|
|
req := &datapb.AlterCollectionRequest{
|
|
|
|
CollectionID: 1,
|
|
|
|
PartitionIDs: []int64{1},
|
|
|
|
Properties: []*commonpb.KeyValuePair{{Key: "k", Value: "v"}},
|
|
|
|
}
|
|
|
|
|
|
|
|
assert.Nil(t, s.meta.collections[1].Properties)
|
|
|
|
resp, err := s.BroadcastAlteredCollection(ctx, req)
|
|
|
|
assert.NotNil(t, resp)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, s.meta.collections[1].Properties)
|
|
|
|
})
|
|
|
|
}
|
2023-01-12 09:55:42 +08:00
|
|
|
|
|
|
|
func TestServer_GcConfirm(t *testing.T) {
|
|
|
|
t.Run("closed server", func(t *testing.T) {
|
|
|
|
s := &Server{}
|
|
|
|
s.stateCode.Store(commonpb.StateCode_Initializing)
|
|
|
|
resp, err := s.GcConfirm(context.TODO(), &datapb.GcConfirmRequest{CollectionId: 100, PartitionId: 10000})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
})
|
|
|
|
|
|
|
|
t.Run("normal case", func(t *testing.T) {
|
|
|
|
s := &Server{}
|
|
|
|
s.stateCode.Store(commonpb.StateCode_Healthy)
|
|
|
|
|
|
|
|
m := &meta{}
|
|
|
|
catalog := mocks.NewDataCoordCatalog(t)
|
|
|
|
m.catalog = catalog
|
|
|
|
|
|
|
|
catalog.On("GcConfirm",
|
|
|
|
mock.Anything,
|
|
|
|
mock.AnythingOfType("int64"),
|
|
|
|
mock.AnythingOfType("int64")).
|
|
|
|
Return(false)
|
|
|
|
|
|
|
|
s.meta = m
|
|
|
|
|
|
|
|
resp, err := s.GcConfirm(context.TODO(), &datapb.GcConfirmRequest{CollectionId: 100, PartitionId: 10000})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, commonpb.ErrorCode_Success, resp.GetStatus().GetErrorCode())
|
|
|
|
assert.False(t, resp.GetGcFinished())
|
|
|
|
})
|
|
|
|
}
|