@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"math"
22
22
"strconv"
23
+ "strings"
23
24
"testing"
24
25
"time"
25
26
@@ -903,6 +904,8 @@ func Test_createCollectionTask_Execute(t *testing.T) {
903
904
mock .Anything ,
904
905
mock .Anything ,
905
906
).Return (coll , nil )
907
+ meta .EXPECT ().DescribeAlias (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
908
+ Return ("" , merr .WrapErrAliasNotFound ("" , "" ))
906
909
907
910
core := newTestCore (withMeta (meta ), withTtSynchronizer (ticker ))
908
911
@@ -950,6 +953,8 @@ func Test_createCollectionTask_Execute(t *testing.T) {
950
953
mock .Anything ,
951
954
mock .Anything ,
952
955
).Return (coll , nil )
956
+ meta .EXPECT ().DescribeAlias (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
957
+ Return ("" , merr .WrapErrAliasNotFound ("" , "" ))
953
958
954
959
core := newTestCore (withMeta (meta ), withTtSynchronizer (ticker ))
955
960
@@ -972,10 +977,11 @@ func Test_createCollectionTask_Execute(t *testing.T) {
972
977
ticker := newTickerWithMockFailStream ()
973
978
shardNum := 2
974
979
pchans := ticker .getDmlChannelNames (shardNum )
975
- meta := newMockMetaTable ()
976
- meta .GetCollectionByNameFunc = func (ctx context.Context , collectionName string , ts Timestamp ) (* model.Collection , error ) {
977
- return nil , errors .New ("error mock GetCollectionByName" )
978
- }
980
+ meta := mockrootcoord .NewIMetaTable (t )
981
+ meta .EXPECT ().GetCollectionByName (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
982
+ Return (nil , errors .New ("error mock GetCollectionByName" ))
983
+ meta .EXPECT ().DescribeAlias (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
984
+ Return ("" , merr .WrapErrAliasNotFound ("" , "" ))
979
985
core := newTestCore (withTtSynchronizer (ticker ), withMeta (meta ))
980
986
schema := & schemapb.CollectionSchema {Name : "" , Fields : []* schemapb.FieldSchema {{}}}
981
987
task := & createCollectionTask {
@@ -996,6 +1002,40 @@ func Test_createCollectionTask_Execute(t *testing.T) {
996
1002
assert .Error (t , err )
997
1003
})
998
1004
1005
+ t .Run ("collection name duplicates an alias" , func (t * testing.T ) {
1006
+ defer cleanTestEnv ()
1007
+
1008
+ collectionName := funcutil .GenRandomStr ()
1009
+ ticker := newRocksMqTtSynchronizer ()
1010
+ field1 := funcutil .GenRandomStr ()
1011
+ schema := & schemapb.CollectionSchema {Name : collectionName , Fields : []* schemapb.FieldSchema {{Name : field1 }}}
1012
+
1013
+ meta := mockrootcoord .NewIMetaTable (t )
1014
+ // mock collection name duplicates an alias
1015
+ meta .EXPECT ().DescribeAlias (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
1016
+ Return (collectionName , nil )
1017
+
1018
+ core := newTestCore (withMeta (meta ), withTtSynchronizer (ticker ))
1019
+ task := & createCollectionTask {
1020
+ baseTask : newBaseTask (context .Background (), core ),
1021
+ Req : & milvuspb.CreateCollectionRequest {
1022
+ Base : & commonpb.MsgBase {MsgType : commonpb .MsgType_CreateCollection },
1023
+ DbName : "mock-db" ,
1024
+ CollectionName : collectionName ,
1025
+ Properties : []* commonpb.KeyValuePair {
1026
+ {
1027
+ Key : common .ConsistencyLevel ,
1028
+ Value : "1" ,
1029
+ },
1030
+ },
1031
+ },
1032
+ schema : schema ,
1033
+ }
1034
+ err := task .Execute (context .Background ())
1035
+ assert .Error (t , err )
1036
+ assert .True (t , strings .Contains (err .Error (), "conflicts with an existing alias" ))
1037
+ })
1038
+
999
1039
t .Run ("normal case" , func (t * testing.T ) {
1000
1040
defer cleanTestEnv ()
1001
1041
@@ -1023,6 +1063,8 @@ func Test_createCollectionTask_Execute(t *testing.T) {
1023
1063
mock .Anything ,
1024
1064
mock .Anything ,
1025
1065
).Return (nil )
1066
+ meta .EXPECT ().DescribeAlias (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
1067
+ Return ("" , merr .WrapErrAliasNotFound ("" , "" ))
1026
1068
1027
1069
dc := newMockDataCoord ()
1028
1070
dc .GetComponentStatesFunc = func (ctx context.Context ) (* milvuspb.ComponentStates , error ) {
@@ -1107,6 +1149,8 @@ func Test_createCollectionTask_Execute(t *testing.T) {
1107
1149
mock .Anything ,
1108
1150
mock .Anything ,
1109
1151
).Return (errors .New ("error mock ChangeCollectionState" ))
1152
+ meta .EXPECT ().DescribeAlias (mock .Anything , mock .Anything , mock .Anything , mock .Anything ).
1153
+ Return ("" , merr .WrapErrAliasNotFound ("" , "" ))
1110
1154
1111
1155
removeCollectionCalled := false
1112
1156
removeCollectionChan := make (chan struct {}, 1 )
0 commit comments