From 5f71bb2a41f98de5b9c5c79a2c09ae18628450a6 Mon Sep 17 00:00:00 2001 From: ThreadDao Date: Wed, 26 Feb 2025 16:27:59 +0800 Subject: [PATCH] test: Split gosdk cases into different packages and add rg cases (#39694) issue: #33419 --------- Signed-off-by: ThreadDao --- tests/go_client/README.md | 16 + tests/go_client/base/milvus_client.go | 36 + tests/go_client/common/response_checker.go | 53 ++ .../go_client/testcases/advcases/main_test.go | 12 + .../testcases/advcases/resource_group_test.go | 775 ++++++++++++++++++ tests/go_client/testcases/client_test.go | 42 +- tests/go_client/testcases/collection_test.go | 96 +-- tests/go_client/testcases/database_test.go | 28 +- tests/go_client/testcases/delete_test.go | 32 +- .../testcases/full_text_search_test.go | 10 +- .../testcases/groupby_search_test.go | 8 +- tests/go_client/testcases/helper/helper.go | 52 +- .../go_client/testcases/helper/read_helper.go | 12 + .../go_client/testcases/helper/test_setup.go | 94 +++ .../go_client/testcases/hybrid_search_test.go | 18 +- tests/go_client/testcases/index_test.go | 68 +- tests/go_client/testcases/insert_test.go | 58 +- .../go_client/testcases/load_release_test.go | 38 +- tests/go_client/testcases/main_test.go | 104 +-- tests/go_client/testcases/partition_test.go | 12 +- tests/go_client/testcases/query_test.go | 42 +- tests/go_client/testcases/search_test.go | 66 +- tests/go_client/testcases/upsert_test.go | 20 +- 23 files changed, 1311 insertions(+), 381 deletions(-) create mode 100644 tests/go_client/testcases/advcases/main_test.go create mode 100644 tests/go_client/testcases/advcases/resource_group_test.go create mode 100644 tests/go_client/testcases/helper/test_setup.go diff --git a/tests/go_client/README.md b/tests/go_client/README.md index e54244b5d5..a136feac04 100644 --- a/tests/go_client/README.md +++ b/tests/go_client/README.md @@ -178,6 +178,22 @@ go test -run TestYourFeature ./testcases/ # Run with verbose output go test -v ./testcases/... + +# gotestsum +Recommend you to use gotestsum https://github.com/gotestyourself/gotestsum + +# Run all default cases +gotestsum --format testname --hide-summary=output -v ./testcases/... --addr=127.0.0.1:19530 -timeout=30m + +# Run a specified file +gotestsum --format testname --hide-summary=output ./testcases/collection_test.go ./testcases/main_test.go --addr=127.0.0.1:19530 + +# Run L3 rg cases +gotestsum --format testname --hide-summary=output -v ./testcases/advcases/... --addr=127.0.0.1:19530 -timeout=30m -tags=rg + +# Run advanced rg cases and default cases +# rg cases conflicts with default cases, so -p=1 is required +gotestsum --format testname --hide-summary=output -v ./testcases/... --addr=127.0.0.1:19530 -timeout=30m -tags=rg -p 1 ``` ## Contributing diff --git a/tests/go_client/base/milvus_client.go b/tests/go_client/base/milvus_client.go index 50b827bfc5..d7a4d0238b 100644 --- a/tests/go_client/base/milvus_client.go +++ b/tests/go_client/base/milvus_client.go @@ -322,3 +322,39 @@ func (mc *MilvusClient) HybridSearch(ctx context.Context, option client.HybridSe resultSets, err := mc.mClient.HybridSearch(ctx, option, callOptions...) return resultSets, err } + +// ListResourceGroups list all resource groups +func (mc *MilvusClient) ListResourceGroups(ctx context.Context, option client.ListResourceGroupsOption, callOptions ...grpc.CallOption) ([]string, error) { + resourceGroups, err := mc.mClient.ListResourceGroups(ctx, option, callOptions...) + return resourceGroups, err +} + +// CreateResourceGroup create resource group +func (mc *MilvusClient) CreateResourceGroup(ctx context.Context, option client.CreateResourceGroupOption, callOptions ...grpc.CallOption) error { + err := mc.mClient.CreateResourceGroup(ctx, option, callOptions...) + return err +} + +// DropResourceGroup drop resource group +func (mc *MilvusClient) DropResourceGroup(ctx context.Context, option client.DropResourceGroupOption, callOptions ...grpc.CallOption) error { + err := mc.mClient.DropResourceGroup(ctx, option, callOptions...) + return err +} + +// DescribeResourceGroup describe resource group +func (mc *MilvusClient) DescribeResourceGroup(ctx context.Context, option client.DescribeResourceGroupOption, callOptions ...grpc.CallOption) (*entity.ResourceGroup, error) { + resourceGroup, err := mc.mClient.DescribeResourceGroup(ctx, option, callOptions...) + return resourceGroup, err +} + +// UpdateResourceGroup update resource group +func (mc *MilvusClient) UpdateResourceGroup(ctx context.Context, option client.UpdateResourceGroupOption, callOptions ...grpc.CallOption) error { + err := mc.mClient.UpdateResourceGroup(ctx, option, callOptions...) + return err +} + +// TransferReplica transfer replica +func (mc *MilvusClient) TransferReplica(ctx context.Context, option client.TransferReplicaOption, callOptions ...grpc.CallOption) error { + err := mc.mClient.TransferReplica(ctx, option, callOptions...) + return err +} diff --git a/tests/go_client/common/response_checker.go b/tests/go_client/common/response_checker.go index 151432b93a..501ea4cf03 100644 --- a/tests/go_client/common/response_checker.go +++ b/tests/go_client/common/response_checker.go @@ -222,3 +222,56 @@ func CheckIndex(t *testing.T, actualIdxDesc client.IndexDescription, idx index.I require.Equal(t, opt.pendingIndexRows, actualIdxDesc.PendingIndexRows) } } + +func CheckTransfer(t *testing.T, actualRgs []*entity.ResourceGroupTransfer, expRgs []*entity.ResourceGroupTransfer) { + if len(expRgs) == 0 { + require.Len(t, actualRgs, 0) + } else { + _expRgs := make([]string, 0, len(expRgs)) + _actualRgs := make([]string, 0, len(actualRgs)) + for _, rg := range expRgs { + _expRgs = append(_expRgs, rg.ResourceGroup) + } + for _, rg := range actualRgs { + _actualRgs = append(_actualRgs, rg.ResourceGroup) + } + require.ElementsMatch(t, _expRgs, _actualRgs) + } +} + +func CheckResourceGroupConfig(t *testing.T, actualConfig *entity.ResourceGroupConfig, expConfig *entity.ResourceGroupConfig) { + if expConfig.Requests.NodeNum != 0 { + require.EqualValuesf(t, expConfig.Requests.NodeNum, actualConfig.Requests.NodeNum, "Requests.NodeNum mismatch") + } + + if expConfig.Limits.NodeNum != 0 { + require.EqualValuesf(t, expConfig.Limits.NodeNum, actualConfig.Limits.NodeNum, "Limits.NodeNum mismatch") + } + + if expConfig.TransferFrom != nil { + CheckTransfer(t, expConfig.TransferFrom, actualConfig.TransferFrom) + } + + if expConfig.TransferTo != nil { + CheckTransfer(t, expConfig.TransferTo, actualConfig.TransferTo) + } + if expConfig.NodeFilter.NodeLabels != nil { + require.EqualValues(t, expConfig.NodeFilter, actualConfig.NodeFilter) + } +} + +func CheckResourceGroup(t *testing.T, actualRg *entity.ResourceGroup, expRg *entity.ResourceGroup) { + require.EqualValues(t, expRg.Name, actualRg.Name, "ResourceGroup name mismatch") + require.EqualValues(t, expRg.Capacity, actualRg.Capacity, "ResourceGroup capacity mismatch") + if expRg.NumAvailableNode >= 0 { + require.EqualValues(t, expRg.NumAvailableNode, len(actualRg.Nodes), "AvailableNodesNumber mismatch") + } + + if expRg.Config != nil { + CheckResourceGroupConfig(t, actualRg.Config, expRg.Config) + } + + if expRg.Nodes != nil { + require.ElementsMatch(t, expRg.Nodes, actualRg.Nodes, "Nodes count mismatch") + } +} diff --git a/tests/go_client/testcases/advcases/main_test.go b/tests/go_client/testcases/advcases/main_test.go new file mode 100644 index 0000000000..879f71094c --- /dev/null +++ b/tests/go_client/testcases/advcases/main_test.go @@ -0,0 +1,12 @@ +package advcases + +import ( + "os" + "testing" + + "github.com/milvus-io/milvus/tests/go_client/testcases/helper" +) + +func TestMain(m *testing.M) { + os.Exit(helper.RunTests(m)) +} diff --git a/tests/go_client/testcases/advcases/resource_group_test.go b/tests/go_client/testcases/advcases/resource_group_test.go new file mode 100644 index 0000000000..1add515bde --- /dev/null +++ b/tests/go_client/testcases/advcases/resource_group_test.go @@ -0,0 +1,775 @@ +//go:build rg + +package advcases + +import ( + "context" + "fmt" + "math/rand" + "testing" + "time" + + "github.com/stretchr/testify/require" + "go.uber.org/zap" + + "github.com/milvus-io/milvus/client/v2/entity" + client "github.com/milvus-io/milvus/client/v2/milvusclient" + "github.com/milvus-io/milvus/pkg/v2/log" + "github.com/milvus-io/milvus/tests/go_client/base" + "github.com/milvus-io/milvus/tests/go_client/common" + hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper" +) + +const ( + configQnNodes = 4 + newRgNode = 2 +) + +func resetRgs(t *testing.T, ctx context.Context, mc *base.MilvusClient) { + t.Helper() + // release and drop all collections + collections, _ := mc.ListCollections(ctx, client.NewListCollectionOption()) + for _, collection := range collections { + err := mc.ReleaseCollection(ctx, client.NewReleaseCollectionOption(collection)) + common.CheckErr(t, err, true) + err = mc.DropCollection(ctx, client.NewDropCollectionOption(collection)) + common.CheckErr(t, err, true) + } + + // reset resource groups + rgs, errList := mc.ListResourceGroups(ctx, client.NewListResourceGroupsOption()) + common.CheckErr(t, errList, true) + for _, rg := range rgs { + // describe rg and get available node + err := mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(rg, &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: 0}, + Limits: entity.ResourceGroupLimit{NodeNum: 0}, + })) + common.CheckErr(t, err, true) + } + + // UpdateResourceGroup is lazy + for _, rg := range rgs { + if rg != common.DefaultRgName { + errDrop := mc.DropResourceGroup(ctx, client.NewDropResourceGroupOption(rg)) + common.CheckErr(t, errDrop, true) + } + } + + rgs2, errList2 := mc.ListResourceGroups(ctx, client.NewListResourceGroupsOption()) + common.CheckErr(t, errList2, true) + require.Len(t, rgs2, 1) +} + +func setupTest(t *testing.T, ctx context.Context, mc *base.MilvusClient) { + resetRgs(t, ctx, mc) + t.Cleanup(func() { + resetRgs(t, ctx, mc) + }) +} + +func checkResourceGroup(t *testing.T, ctx context.Context, mc *base.MilvusClient, expRg *entity.ResourceGroup) { + actualRg, err := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(expRg.Name)) + common.CheckErr(t, err, true) + log.Ctx(ctx).Info("checkResourceGroup", zap.Any("actualRg", actualRg)) + common.CheckResourceGroup(t, actualRg, expRg) +} + +// test rg default: list rg, create rg, describe rg, update rg +func TestRgDefault(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // describe default rg and check default rg info: Limits: 1000000, Nodes: all + expDefaultRg := &entity.ResourceGroup{ + Name: common.DefaultRgName, + Capacity: common.DefaultRgCapacity, + NumAvailableNode: configQnNodes, + Config: &entity.ResourceGroupConfig{ + Limits: entity.ResourceGroupLimit{NodeNum: 0}, + }, + } + checkResourceGroup(t, ctx, mc, expDefaultRg) + + // create new rg + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(newRgNode).WithNodeLimit(newRgNode)) + common.CheckErr(t, errCreate, true) + + // list rgs + rgs, errList := mc.ListResourceGroups(ctx, client.NewListResourceGroupsOption()) + common.CheckErr(t, errList, true) + require.ElementsMatch(t, rgs, []string{common.DefaultRgName, rgName}) + + // describe new rg and check new rg info + expRg := &entity.ResourceGroup{ + Name: rgName, + Capacity: newRgNode, + NumAvailableNode: newRgNode, + Config: &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: newRgNode}, + Limits: entity.ResourceGroupLimit{NodeNum: newRgNode}, + }, + } + checkResourceGroup(t, ctx, mc, expRg) + + // update resource group + errUpdate := mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(rgName, &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: configQnNodes}, + Limits: entity.ResourceGroupLimit{NodeNum: configQnNodes}, + })) + common.CheckErr(t, errUpdate, true) + + // check rg info after transfer nodes + transferRg := &entity.ResourceGroup{ + Name: rgName, + Capacity: configQnNodes, + NumAvailableNode: configQnNodes, + Config: &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: configQnNodes}, + }, + } + checkResourceGroup(t, ctx, mc, transferRg) + + // check default rg info: 0 Nodes + expDefaultRg2 := &entity.ResourceGroup{ + Name: common.DefaultRgName, + Capacity: common.DefaultRgCapacity, + NumAvailableNode: 0, + Config: &entity.ResourceGroupConfig{ + Limits: entity.ResourceGroupLimit{NodeNum: 0}, + }, + } + checkResourceGroup(t, ctx, mc, expDefaultRg2) +} + +// test create rg with invalid name +func TestCreateRgInvalidNames(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + + type invalidNameStruct struct { + name string + errMsg string + } + + invalidNames := []invalidNameStruct{ + {name: "", errMsg: "resource group name couldn't be empty"}, + {name: "12-s", errMsg: "name must be an underscore or letter"}, + {name: "(mn)", errMsg: "name must be an underscore or letter"}, + {name: "中文", errMsg: "name must be an underscore or letter"}, + {name: "%$#", errMsg: "name must be an underscore or letter"}, + {name: common.GenLongString(common.MaxCollectionNameLen + 1), errMsg: "name must be less than 255 characters"}, + } + // create rg with invalid name + for _, invalidName := range invalidNames { + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(invalidName.name)) + common.CheckErr(t, errCreate, false, invalidName.errMsg) + } +} + +// test create rg with existed name +func TestCreateExistedRg(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create default rg + mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(common.DefaultRgName)) + err := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(common.DefaultRgName)) + common.CheckErr(t, err, false, "resource group already exist, but create with different config") + + // create same repeatedly + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(configQnNodes).WithNodeLimit(configQnNodes)) + common.CheckErr(t, errCreate, true) + rg, _ := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(rgName)) + + // create existed rg with different config + errCreate = mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(newRgNode).WithNodeLimit(newRgNode)) + common.CheckErr(t, errCreate, false, "resource group already exist") + rg1, _ := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(rgName)) + // require.EqualValues(t, rg1, rg) + common.CheckResourceGroup(t, rg1, rg) + + // create existed rg with same config + errCreate = mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(configQnNodes).WithNodeLimit(configQnNodes)) + common.CheckErr(t, errCreate, true) + rg2, _ := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(rgName)) + common.CheckResourceGroup(t, rg2, rg) +} + +func TestCreateRgWithRequestsLimits(t *testing.T) { + type requestsLimits struct { + requests int + limits int + available int32 + errMsg string + } + reqAndLimits := []requestsLimits{ + {requests: 0, limits: 0, available: 0}, + {requests: -1, limits: 0, errMsg: "node num in `requests` or `limits` should not less than 0"}, + {requests: 0, limits: -2, errMsg: "node num in `requests` or `limits` should not less than 0"}, + {requests: 10, limits: 1, errMsg: "limits node num should not less than requests node num"}, + {requests: 2, limits: 3, available: 3}, + {requests: configQnNodes * 2, limits: configQnNodes * 3, available: configQnNodes}, + {requests: configQnNodes, limits: configQnNodes, available: configQnNodes}, + } + // connect + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + + rgName := common.GenRandomString("rg", 6) + // create rg with request only -> use default 0 limit -> error + err := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(newRgNode)) + common.CheckErr(t, err, false, "limits node num should not less than requests node num") + + // create rg with limit only -> use default 0 request + err = mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeLimit(newRgNode)) + common.CheckErr(t, err, true) + + for _, rl := range reqAndLimits { + log.Ctx(ctx).Info("TestCreateRgWithRequestsLimits", zap.Any("reqAndLimit", rl)) + rgName := common.GenRandomString("rg", 6) + + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(rl.requests).WithNodeLimit(rl.limits)) + if rl.errMsg != "" { + common.CheckErr(t, errCreate, false, rl.errMsg) + } else { + expDefaultRg := &entity.ResourceGroup{ + Name: rgName, + Capacity: int32(rl.requests), + NumAvailableNode: rl.available, + Config: &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: int32(rl.requests)}, + Limits: entity.ResourceGroupLimit{NodeNum: int32(rl.limits)}, + }, + } + checkResourceGroup(t, ctx, mc, expDefaultRg) + } + setupTest(t, ctx, mc) + } +} + +func TestRgAdvanced(t *testing.T) { + // test transfer replica from rg to default rg + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create new rg with requests 2 + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName)) + common.CheckErr(t, errCreate, true) + + // load two replicas with multi resource groups + prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) + prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) + _, err := mc.LoadCollection(ctx, client.NewLoadCollectionOption(schema.CollectionName).WithReplica(2).WithResourceGroup(rgName)) + common.CheckErr(t, err, false, "resource group node not enough") + + // update rg -> load -> drop rg + mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(rgName, &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: newRgNode}, + Limits: entity.ResourceGroupLimit{NodeNum: newRgNode}, + })) + prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName).TWithReplica(2).TWithResourceGroups(rgName)) + + // drop rg which loaded replicas + err = mc.DropResourceGroup(ctx, client.NewDropResourceGroupOption(rgName)) + common.CheckErr(t, err, false, "some replicas still loaded in resource group") + + err = mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, rgName, common.DefaultRgName, 2)) + common.CheckErr(t, err, true) + err = mc.DropResourceGroup(ctx, client.NewDropResourceGroupOption(rgName)) + common.CheckErr(t, err, false, "resource group's limits node num is not 0") +} + +func TestUpdateRgWithTransfer(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create rg0 with requests=2, limits=3, total 4 nodes + rg0 := common.GenRandomString("rg0", 6) + rg0Limits := newRgNode + 1 + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rg0).WithNodeRequest(newRgNode).WithNodeLimit(rg0Limits)) + common.CheckErr(t, errCreate, true) + + // check rg0 available node: 3, default available node: 1 + require.Eventuallyf(t, func() bool { + actualRg0, _ := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(rg0)) + return len(actualRg0.Nodes) == rg0Limits + }, time.Second*5, 2*time.Second, fmt.Sprintf("expected %s has %d available nodes", rg0, rg0Limits)) + actualRgDef, _ := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(common.DefaultRgName)) + require.Lenf(t, actualRgDef.Nodes, configQnNodes-rg0Limits, fmt.Sprintf("expected %s has %d available nodes", common.DefaultRgName, configQnNodes-rg0Limits)) + + // create rg1 with TransferFrom & TransferTo & requests=3, limits=4 + rg1 := common.GenRandomString("rg1", 6) + rg1Requests := newRgNode + 1 + errCreate = mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rg1).WithNodeLimit(configQnNodes).WithNodeRequest(rg1Requests)) + // Note: default Requests & Limits of ResourceGroupConfig struct is 0 + errUpdate := mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(rg1, &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: int32(rg1Requests)}, + Limits: entity.ResourceGroupLimit{NodeNum: int32(configQnNodes)}, + TransferFrom: []*entity.ResourceGroupTransfer{ + {ResourceGroup: rg0}, + }, + TransferTo: []*entity.ResourceGroupTransfer{ + {ResourceGroup: common.DefaultRgName}, + }, + })) + common.CheckErr(t, errUpdate, true) + + // verify available nodes: rg0 + rg1 = configQnNodes = 4 + time.Sleep(time.Duration(rand.Intn(6)) * time.Second) + actualRg0, _ := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(rg0)) + actualRg1, _ := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(rg1)) + require.EqualValuesf(t, configQnNodes, len(actualRg0.Nodes)+len(actualRg1.Nodes), fmt.Sprintf("Expected the total available nodes of %s and %s is %d ", rg0, rg1, configQnNodes)) + expDefaultRg1 := &entity.ResourceGroup{ + Name: rg1, + Capacity: int32(rg1Requests), + NumAvailableNode: -1, // not check + Config: &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: int32(rg1Requests)}, + Limits: entity.ResourceGroupLimit{NodeNum: configQnNodes}, + }, + } + checkResourceGroup(t, ctx, mc, expDefaultRg1) +} + +func TestUpdateRgWithNotExistTransfer(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName)) + common.CheckErr(t, errCreate, true) + + // update rg with not existed TransferFrom rg + errUpdate := mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(rgName, &entity.ResourceGroupConfig{ + TransferFrom: []*entity.ResourceGroupTransfer{ + {ResourceGroup: "aaa"}, + }, + })) + common.CheckErr(t, errUpdate, false, "resource group in `TransferFrom` aaa not exist") + + errUpdate1 := mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(common.GenRandomString("rg", 6), &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: newRgNode}, + Limits: entity.ResourceGroupLimit{NodeNum: newRgNode}, + })) + common.CheckErr(t, errUpdate1, false, "resource group not found") + + // update rg with not existed TransferTo rg + errUpdate = mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(rgName, &entity.ResourceGroupConfig{ + TransferTo: []*entity.ResourceGroupTransfer{ + {ResourceGroup: "aaa"}, + }, + })) + common.CheckErr(t, errUpdate, false, "resource group in `TransferTo` aaa not exist") +} + +func TestUpdateRgWithRequestsLimits(t *testing.T) { + type requestsLimits struct { + requests int32 + limits int32 + available int32 + errMsg string + } + reqAndLimits := []requestsLimits{ + {requests: 0, limits: 0, available: 0}, + {requests: -1, limits: 0, errMsg: "node num in `requests` or `limits` should not less than 0"}, + {requests: 0, limits: -2, errMsg: "node num in `requests` or `limits` should not less than 0"}, + {requests: 10, limits: 1, errMsg: "limits node num should not less than requests node num"}, + {requests: 2, limits: 3, available: 3}, + {requests: configQnNodes * 2, limits: configQnNodes * 3, available: configQnNodes}, + {requests: configQnNodes, limits: configQnNodes, available: configQnNodes}, + } + // connect + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + rgName := common.GenRandomString("rg", 6) + mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(newRgNode).WithNodeLimit(newRgNode)) + + // default ResourceGroupConfig.Limits.NodeNum is 0 + err := mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(rgName, &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: 1}, + })) + common.CheckErr(t, err, false, "limits node num should not less than requests node num") + + for _, rl := range reqAndLimits { + log.Ctx(ctx).Info("TestUpdateRgWithRequestsLimits", zap.Any("reqAndLimit", rl)) + errCreate := mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(rgName, &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: rl.requests}, + Limits: entity.ResourceGroupLimit{NodeNum: rl.limits}, + })) + if rl.errMsg != "" { + common.CheckErr(t, errCreate, false, rl.errMsg) + } else { + expDefaultRg := &entity.ResourceGroup{ + Name: rgName, + Capacity: rl.requests, + NumAvailableNode: rl.available, + Config: &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: rl.requests}, + Limits: entity.ResourceGroupLimit{NodeNum: rl.limits}, + }, + } + checkResourceGroup(t, ctx, mc, expDefaultRg) + } + } +} + +// describe/drop/update rg with not existed name +func TestOperateRgNotExisted(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + + // describe not existed rg + _, errDescribe := mc.DescribeResourceGroup(ctx, client.NewDescribeResourceGroupOption(common.GenRandomString("rg", 6))) + common.CheckErr(t, errDescribe, false, "resource group not found") + + // drop non-existed rg + errDrop := mc.DropResourceGroup(ctx, client.NewDropResourceGroupOption(common.GenRandomString("rg", 6))) + common.CheckErr(t, errDrop, true) + + errUpdate := mc.UpdateResourceGroup(ctx, client.NewUpdateResourceGroupOption(common.GenRandomString("rg", 6), &entity.ResourceGroupConfig{ + Requests: entity.ResourceGroupLimit{NodeNum: newRgNode}, + })) + common.CheckErr(t, errUpdate, false, "resource group not found") +} + +// drop empty default rg +func TestDropRg(t *testing.T) { + t.Log("https://github.com/milvus-io/milvus/issues/39942") + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // try to drop default rg + errDropDefault := mc.DropResourceGroup(ctx, client.NewDropResourceGroupOption(common.DefaultRgName)) + common.CheckErr(t, errDropDefault, false, "default resource group is not deletable") + + // create new rg with all nodes + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(configQnNodes).WithNodeLimit(configQnNodes)) + common.CheckErr(t, errCreate, true) + + // drop rg and rg available node is not 0 + errDrop := mc.DropResourceGroup(ctx, client.NewDropResourceGroupOption(rgName)) + common.CheckErr(t, errDrop, false, "resource group's limits node num is not 0") + + // describe default rg + transferRg := &entity.ResourceGroup{ + Name: common.DefaultRgName, + Capacity: common.DefaultRgCapacity, + NumAvailableNode: 0, + } + checkResourceGroup(t, ctx, mc, transferRg) + + // drop empty default rg + errDrop = mc.DropResourceGroup(ctx, client.NewDropResourceGroupOption(common.DefaultRgName)) + common.CheckErr(t, errDrop, false, "default resource group is not deletable") +} + +// test list rgs +func TestListRgs(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + rgNum := 10 + rgs := []string{common.DefaultRgName} + + // list default rg + listRgs, errList := mc.ListResourceGroups(ctx, client.NewListResourceGroupsOption()) + common.CheckErr(t, errList, true) + require.EqualValues(t, listRgs, rgs) + + // create 10 new rgs + for i := 1; i <= rgNum; i++ { + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName)) + common.CheckErr(t, errCreate, true) + rgs = append(rgs, rgName) + } + + // list rgs + listRgs, errList = mc.ListResourceGroups(ctx, client.NewListResourceGroupsOption()) + common.CheckErr(t, errList, true) + require.ElementsMatch(t, listRgs, rgs) +} + +// test transfer replica of not existed collection +func TestTransferReplicaNotExisted(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create new rg with 0 node + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeLimit(newRgNode)) + common.CheckErr(t, errCreate, true) + + prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) + prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) + prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName).TWithResourceGroups(rgName)) + + // transfer replica + errTransfer := mc.TransferReplica(ctx, client.NewTransferReplicaOption(common.GenRandomString("coll", 6), rgName, common.DefaultRgName, 1)) + common.CheckErr(t, errTransfer, false, "collection not found") + + // source not exist + errSource := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, common.GenRandomString("rg", 6), common.DefaultRgName, 1)) + common.CheckErr(t, errSource, false, "resource group not found") + + // target not exist + errTarget := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, common.DefaultRgName, common.GenRandomString("rg", 6), 1)) + common.CheckErr(t, errTarget, false, "resource group not found") + + // transfer to self -> error + errSelf := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, rgName, rgName, 1)) + common.CheckErr(t, errSelf, false, "source resource group and target resource group should not be the same") +} + +// test transfer replicas with invalid replica number +func TestTransferReplicaInvalidReplicaNumber(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create new rg + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeLimit(newRgNode)) + common.CheckErr(t, errCreate, true) + + // create collection -> load 2 replicas with rgName + _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) + + // invalid replicas + type invalidReplicasStruct struct { + replicaNumber int64 + errMsg string + } + invalidReplicas := []invalidReplicasStruct{ + {replicaNumber: 0, errMsg: "invalid parameter[expected=NumReplica > 0][actual=invalid NumReplica 0]"}, + {replicaNumber: -1, errMsg: "invalid parameter[expected=NumReplica > 0][actual=invalid NumReplica -1]"}, + {replicaNumber: 1, errMsg: "Collection not loaded"}, + } + + for _, invalidReplica := range invalidReplicas { + // transfer replica + log.Ctx(ctx).Info("TestTransferReplicaInvalidReplicaNumber", zap.Int64("replica", invalidReplica.replicaNumber)) + errTransfer := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, rgName, common.DefaultRgName, invalidReplica.replicaNumber)) + common.CheckErr(t, errTransfer, false, invalidReplica.errMsg) + } +} + +// test transfer replicas +func TestTransferReplicas(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create new rg1 and rg2 + rg1Name := common.GenRandomString("rg1", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rg1Name).WithNodeRequest(newRgNode).WithNodeLimit(newRgNode)) + common.CheckErr(t, errCreate, true) + + // init collection: create -> insert -> index -> load 2 replicas with rg1 + prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(common.DefaultNb)) + prepare.FlushData(ctx, t, mc, schema.CollectionName) + prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) + replica := 2 + prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName).TWithResourceGroups(rg1Name).TWithReplica(replica)) + + // transfer from defaultRg (not loaded collection) -> error + err := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, common.DefaultRgName, rg1Name, 1)) + common.CheckErr(t, err, false, "NumReplica not greater than the number of replica in source resource group]") + + // transfer replicas more than actual + errReplicas := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, rg1Name, common.DefaultRgName, int64(replica+1))) + common.CheckErr(t, errReplicas, false, "NumReplica not greater than the number of replica in source resource group]") + + // transfer replica to default rg + errDefault := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, rg1Name, common.DefaultRgName, 1)) + common.CheckErr(t, errDefault, true) + + expRg1 := &entity.ResourceGroup{ + Name: rg1Name, + Capacity: newRgNode, + NumAvailableNode: newRgNode, + NumLoadedReplica: map[string]int32{schema.CollectionName: 1}, + } + checkResourceGroup(t, ctx, mc, expRg1) + expRgDef := &entity.ResourceGroup{ + Name: common.DefaultRgName, + Capacity: common.DefaultRgCapacity, + NumAvailableNode: newRgNode, + NumLoadedReplica: map[string]int32{schema.CollectionName: 1}, + } + checkResourceGroup(t, ctx, mc, expRgDef) + + // search + for i := 0; i < 10; i++ { + vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector) + searchRes, _ := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors)) + common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit) + } +} + +// test transfer replica to 0 available nodes rg +func TestTransferReplicasNodesNotEnough(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create new rg with requests 2 + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName)) + common.CheckErr(t, errCreate, true) + + // load two replicas with multi resource groups + prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(common.DefaultNb)) + prepare.FlushData(ctx, t, mc, schema.CollectionName) + prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) + prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName).TWithReplica(2)) + + // transfer 1 replica into rg which no available node + errReplica := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, common.DefaultRgName, rgName, 1)) + common.CheckErr(t, errReplica, true) + + // check default rg + transferRg2 := &entity.ResourceGroup{ + Name: common.DefaultRgName, + Capacity: common.DefaultRgCapacity, + NumAvailableNode: configQnNodes, + NumLoadedReplica: map[string]int32{schema.CollectionName: 1}, + NumIncomingNode: map[string]int32{schema.CollectionName: 1}, + Config: &entity.ResourceGroupConfig{ + Limits: entity.ResourceGroupLimit{NodeNum: 0}, + }, + } + checkResourceGroup(t, ctx, mc, transferRg2) + + // check rg after transfer replica + expRg := &entity.ResourceGroup{ + Name: rgName, + Capacity: 0, + NumAvailableNode: 0, + NumLoadedReplica: map[string]int32{schema.CollectionName: 1}, + NumOutgoingNode: map[string]int32{schema.CollectionName: 1}, + Config: &entity.ResourceGroupConfig{ + Limits: entity.ResourceGroupLimit{NodeNum: 0}, + }, + } + checkResourceGroup(t, ctx, mc, expRg) + + // search + vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector) + searchRes, _ := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors)) + common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit) +} + +// test transfer replica from rg to default rg +/* +relationship between replicas and rg. there are n rgs: +if n == 1: + - n:1 & replicas <= rgNode & replicas <= sn +if n > 1: + - n:n +- (n+1):n -> error +- n:(n+1) -> error +*/ +func TestLoadReplicasRgs(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create new rg with requests 2 + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(newRgNode).WithNodeLimit(newRgNode)) + common.CheckErr(t, errCreate, true) + + // load two replicas with multi resource groups + prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(common.DefaultNb)) + prepare.FlushData(ctx, t, mc, schema.CollectionName) + prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) + + // load with not existed rg + _, errLoad := mc.LoadCollection(ctx, client.NewLoadCollectionOption(schema.CollectionName).WithReplica(1).WithResourceGroup(common.GenRandomString("rg", 4))) + common.CheckErr(t, errLoad, false, " resource group not found") + + // replicas:rg = n:1 but node not enough -> error + _, errLoad = mc.LoadCollection(ctx, client.NewLoadCollectionOption(schema.CollectionName).WithReplica(3).WithResourceGroup(rgName)) + common.CheckErr(t, errLoad, false, "resource group node not enough") + + // replicas:rg = n:1 and node enough -> search + _, errLoad = mc.LoadCollection(ctx, client.NewLoadCollectionOption(schema.CollectionName).WithReplica(2).WithResourceGroup(rgName)) + common.CheckErr(t, errLoad, true) + for i := 0; i < 10; i++ { + vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector) + searchRes, _ := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors)) + common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit) + } + + err := mc.ReleaseCollection(ctx, client.NewReleaseCollectionOption(schema.CollectionName)) + common.CheckErr(t, err, true) + + // replicas:rg = 2n:n -> error + _, errLoad = mc.LoadCollection(ctx, client.NewLoadCollectionOption(schema.CollectionName).WithReplica(4).WithResourceGroup(rgName, common.DefaultRgName)) + common.CheckErr(t, errLoad, false, "resource group num can only be 0, 1 or same as replica number") + + // replicas:rg = n+1:n -> error + _, errLoad = mc.LoadCollection(ctx, client.NewLoadCollectionOption(schema.CollectionName).WithReplica(3).WithResourceGroup(rgName, common.DefaultRgName)) + common.CheckErr(t, errLoad, false, "resource group num can only be 0, 1 or same as replica number") + + // replicas:rg = n:n+1 -> error + _, errLoad = mc.LoadCollection(ctx, client.NewLoadCollectionOption(schema.CollectionName).WithReplica(1).WithResourceGroup(rgName, common.DefaultRgName)) + common.CheckErr(t, errLoad, false, "resource group num can only be 0, 1 or same as replica number") + + // replicas:rg = n:n -> search + _, errLoad = mc.LoadCollection(ctx, client.NewLoadCollectionOption(schema.CollectionName).WithReplica(2).WithResourceGroup(rgName, common.DefaultRgName)) + common.CheckErr(t, errLoad, true) + for i := 0; i < 10; i++ { + vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector) + searchRes, _ := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors)) + common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit) + } +} + +// Transfer the replica to the resource group where the replica is already loaded +func TestTransferReplicaLoadedRg(t *testing.T) { + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc := hp.CreateDefaultMilvusClient(ctx, t) + setupTest(t, ctx, mc) + + // create new rg with requests 2 + rgName := common.GenRandomString("rg", 6) + errCreate := mc.CreateResourceGroup(ctx, client.NewCreateResourceGroupOption(rgName).WithNodeRequest(newRgNode).WithNodeLimit(newRgNode)) + common.CheckErr(t, errCreate, true) + + // load two replicas with multi resource groups + prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) + prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(common.DefaultNb)) + prepare.FlushData(ctx, t, mc, schema.CollectionName) + prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) + prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName).TWithReplica(2).TWithResourceGroups(rgName, common.DefaultRgName)) + + err := mc.TransferReplica(ctx, client.NewTransferReplicaOption(schema.CollectionName, common.DefaultRgName, rgName, 1)) + common.CheckErr(t, err, true) + + // search + for i := 0; i < 10; i++ { + vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector) + searchRes, _ := mc.Search(ctx, client.NewSearchOption(schema.CollectionName, common.DefaultLimit, vectors)) + common.CheckSearchResult(t, searchRes, common.DefaultNq, common.DefaultLimit) + } +} diff --git a/tests/go_client/testcases/client_test.go b/tests/go_client/testcases/client_test.go index 3ff5c77c98..b33569096d 100644 --- a/tests/go_client/testcases/client_test.go +++ b/tests/go_client/testcases/client_test.go @@ -5,21 +5,21 @@ import ( "testing" "time" - clientv2 "github.com/milvus-io/milvus/client/v2/milvusclient" + client "github.com/milvus-io/milvus/client/v2/milvusclient" "github.com/milvus-io/milvus/tests/go_client/base" "github.com/milvus-io/milvus/tests/go_client/common" - "github.com/milvus-io/milvus/tests/go_client/testcases/helper" + hp "github.com/milvus-io/milvus/tests/go_client/testcases/helper" ) // test connect and close, connect again func TestConnectClose(t *testing.T) { // connect - ctx := helper.CreateContext(t, time.Second*common.DefaultTimeout) - mc, errConnect := base.NewMilvusClient(ctx, &defaultCfg) + ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) + mc, errConnect := base.NewMilvusClient(ctx, hp.GetDefaultClientConfig()) common.CheckErr(t, errConnect, true) // verify that connect success - listOpt := clientv2.NewListCollectionOption() + listOpt := client.NewListCollectionOption() _, errList := mc.ListCollections(ctx, listOpt) common.CheckErr(t, errList, true) @@ -30,20 +30,20 @@ func TestConnectClose(t *testing.T) { common.CheckErr(t, errList2, false, "service not ready[SDK=0]: not connected") // connect again - mc, errConnect2 := base.NewMilvusClient(ctx, &defaultCfg) + mc, errConnect2 := base.NewMilvusClient(ctx, hp.GetDefaultClientConfig()) common.CheckErr(t, errConnect2, true) _, errList3 := mc.ListCollections(ctx, listOpt) common.CheckErr(t, errList3, true) } -func genInvalidClientConfig() []clientv2.ClientConfig { - invalidClientConfigs := []clientv2.ClientConfig{ - {Address: "aaa"}, // not exist address - {Address: strings.Split(*addr, ":")[0]}, // Address=localhost - {Address: strings.Split(*addr, ":")[1]}, // Address=19530 - {Address: *addr, Username: "aaa"}, // not exist username - {Address: *addr, Username: "root", Password: "aaa"}, // wrong password - {Address: *addr, DBName: "aaa"}, // not exist db +func genInvalidClientConfig() []client.ClientConfig { + invalidClientConfigs := []client.ClientConfig{ + {Address: "aaa"}, // not exist address + {Address: strings.Split(hp.GetAddr(), ":")[0]}, // Address=localhost + {Address: strings.Split(hp.GetAddr(), ":")[1]}, // Address=19530 + {Address: hp.GetAddr(), Username: "aaa"}, // not exist username + {Address: hp.GetAddr(), Username: "root", Password: "aaa"}, // wrong password + {Address: hp.GetAddr(), DBName: "aaa"}, // not exist db } return invalidClientConfigs } @@ -51,7 +51,7 @@ func genInvalidClientConfig() []clientv2.ClientConfig { // test connect with timeout and invalid addr func TestConnectInvalidAddr(t *testing.T) { // connect - ctx := helper.CreateContext(t, time.Second*5) + ctx := hp.CreateContext(t, time.Second*5) for _, invalidCfg := range genInvalidClientConfig() { cfg := invalidCfg _, errConnect := base.NewMilvusClient(ctx, &cfg) @@ -62,24 +62,24 @@ func TestConnectInvalidAddr(t *testing.T) { // test connect repeatedly func TestConnectRepeat(t *testing.T) { // connect - ctx := helper.CreateContext(t, time.Second*10) + ctx := hp.CreateContext(t, time.Second*10) - _, errConnect := base.NewMilvusClient(ctx, &defaultCfg) + _, errConnect := base.NewMilvusClient(ctx, hp.GetDefaultClientConfig()) common.CheckErr(t, errConnect, true) // connect again - mc, errConnect2 := base.NewMilvusClient(ctx, &defaultCfg) + mc, errConnect2 := base.NewMilvusClient(ctx, hp.GetDefaultClientConfig()) common.CheckErr(t, errConnect2, true) - _, err := mc.ListCollections(ctx, clientv2.NewListCollectionOption()) + _, err := mc.ListCollections(ctx, client.NewListCollectionOption()) common.CheckErr(t, err, true) } // test close repeatedly func TestCloseRepeat(t *testing.T) { // connect - ctx := helper.CreateContext(t, time.Second*10) - mc, errConnect2 := base.NewMilvusClient(ctx, &defaultCfg) + ctx := hp.CreateContext(t, time.Second*10) + mc, errConnect2 := base.NewMilvusClient(ctx, hp.GetDefaultClientConfig()) common.CheckErr(t, errConnect2, true) // close and again diff --git a/tests/go_client/testcases/collection_test.go b/tests/go_client/testcases/collection_test.go index 27100be0bc..cd77f961ef 100644 --- a/tests/go_client/testcases/collection_test.go +++ b/tests/go_client/testcases/collection_test.go @@ -23,7 +23,7 @@ var prefix = "collection" func TestCreateCollection(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, collectionFieldsType := range []hp.CollectionFieldsType{hp.Int64Vec, hp.VarcharBinary, hp.Int64VarcharSparseVec, hp.AllFields} { fields := hp.FieldsFact.GenFieldsForCollection(collectionFieldsType, hp.TNewFieldsOption()) schema := hp.GenSchema(hp.TNewSchemaOption().TWithFields(fields)) @@ -46,7 +46,7 @@ func TestCreateCollection(t *testing.T) { func TestCreateCollectionFast(t *testing.T) { // test collection property mmap ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection option: WithConsistencyLevel Strong, collName := common.GenRandomString("alter", 6) @@ -76,7 +76,7 @@ func TestCreateCollectionFastOption(t *testing.T) { // test create collection fast with option: ConsistencyLevel, varcharPk, indexOption // Collection AutoID not works !!!, please set it on the field side~ ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection option: WithConsistencyLevel Strong, collName := common.GenRandomString("alter", 6) @@ -112,7 +112,7 @@ func TestCreateCollectionFastOption(t *testing.T) { func TestCreateAutoIdCollectionField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true).WithIsAutoID(true) @@ -140,7 +140,7 @@ func TestCreateAutoIdCollectionField(t *testing.T) { // create collection and specify shard num func TestCreateCollectionShards(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true).WithIsAutoID(true) @@ -165,7 +165,7 @@ func TestCreateCollectionShards(t *testing.T) { func TestCreateAutoIdCollectionSchema(t *testing.T) { t.Skip("waiting for valid AutoId from schema params") ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -194,7 +194,7 @@ func TestCreateAutoIdCollectionSchema(t *testing.T) { func TestCreateAutoIdCollection(t *testing.T) { t.Skip("https://github.com/milvus-io/milvus/issues/39523") ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -221,7 +221,7 @@ func TestCreateAutoIdCollection(t *testing.T) { func TestCreateJsonCollection(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -241,7 +241,7 @@ func TestCreateJsonCollection(t *testing.T) { func TestCreateArrayCollections(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -270,7 +270,7 @@ func TestCreateArrayCollections(t *testing.T) { // test create collection with partition key not supported field type func TestCreateCollectionPartitionKey(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -303,7 +303,7 @@ func TestCreateCollectionPartitionKey(t *testing.T) { func TestCreateCollectionPartitionKeyNumPartition(t *testing.T) { t.Skip("Waiting for WithPartitionNum") ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -326,7 +326,7 @@ func TestCreateCollectionPartitionKeyNumPartition(t *testing.T) { func TestCreateCollectionDynamicSchema(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -358,7 +358,7 @@ func TestCreateCollectionDynamicSchema(t *testing.T) { func TestCreateCollectionDynamic(t *testing.T) { t.Skip("waiting for dynamicField alignment") ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -390,7 +390,7 @@ func TestCreateCollectionDynamic(t *testing.T) { func TestCreateCollectionAllFields(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) schema := entity.NewSchema().WithName(collName) @@ -413,7 +413,7 @@ func TestCreateCollectionAllFields(t *testing.T) { func TestCreateCollectionSparseVector(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) sparseVecField := entity.NewField().WithName(common.DefaultSparseVecFieldName).WithDataType(entity.FieldTypeSparseVector) @@ -434,7 +434,7 @@ func TestCreateCollectionWithValidFieldName(t *testing.T) { t.Parallel() // connect ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection with valid field name for _, name := range common.GenValidNames() { @@ -469,7 +469,7 @@ func TestCreateCollectionWithValidName(t *testing.T) { t.Parallel() // connect ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, name := range common.GenValidNames() { schema := genDefaultSchema().WithName(name) @@ -490,7 +490,7 @@ func TestCreateCollectionWithInvalidFieldName(t *testing.T) { t.Parallel() // connect ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection with invalid field name for _, invalidName := range common.GenInvalidNames() { @@ -514,7 +514,7 @@ func TestCreateCollectionWithInvalidCollectionName(t *testing.T) { t.Parallel() // connect ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and schema no name schema := genDefaultSchema() @@ -536,7 +536,7 @@ func TestCreateCollectionWithInvalidCollectionName(t *testing.T) { // create collection missing pk field or vector field func TestCreateCollectionInvalidFields(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) type invalidFieldsStruct struct { fields []*entity.Field @@ -572,7 +572,7 @@ func TestCreateCollectionInvalidFields(t *testing.T) { // create autoID or not collection with non-int64 and non-varchar field func TestCreateCollectionInvalidAutoPkField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection with autoID true or not collName := common.GenRandomString(prefix, 6) @@ -592,7 +592,7 @@ func TestCreateCollectionInvalidAutoPkField(t *testing.T) { // test create collection with duplicate field name func TestCreateCollectionDuplicateField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // duplicate field pkField := entity.NewField().WithName("id").WithDataType(entity.FieldTypeVarChar).WithIsPrimaryKey(true) @@ -614,7 +614,7 @@ func TestCreateCollectionDuplicateField(t *testing.T) { // test create collection with partition key not supported field type func TestCreateCollectionInvalidPartitionKeyType(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -635,7 +635,7 @@ func TestCreateCollectionInvalidPartitionKeyType(t *testing.T) { // partition key field cannot be primary field, d can only be one partition key field func TestCreateCollectionPartitionKeyPk(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true).WithIsPartitionKey(true) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -649,7 +649,7 @@ func TestCreateCollectionPartitionKeyPk(t *testing.T) { // can only be one partition key field func TestCreateCollectionPartitionKeyNum(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -666,7 +666,7 @@ func TestCreateCollectionPartitionKeyNum(t *testing.T) { func TestPartitionKeyInvalidNumPartition(t *testing.T) { t.Skip("Waiting for num partition") ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // prepare field and schema int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) @@ -693,7 +693,7 @@ func TestPartitionKeyInvalidNumPartition(t *testing.T) { // test create collection with multi auto id func TestCreateCollectionMultiAutoId(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) schema := entity.NewSchema().WithField( @@ -708,7 +708,7 @@ func TestCreateCollectionMultiAutoId(t *testing.T) { // test create collection with different autoId between pk field and schema func TestCreateCollectionInconsistentAutoId(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, autoId := range []bool{true, false} { log.Debug("TestCreateCollectionInconsistentAutoId", zap.Bool("autoId", autoId)) @@ -738,7 +738,7 @@ func TestCreateCollectionInconsistentAutoId(t *testing.T) { // create collection with field or schema description func TestCreateCollectionDescription(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // gen field with description pkDesc := "This is pk field" @@ -781,7 +781,7 @@ func TestCreateBinaryCollectionInvalidDim(t *testing.T) { } ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, invalidDim := range invalidDims { log.Debug("TestCreateBinaryCollectionInvalidDim", zap.Int64("dim", invalidDim.dim)) @@ -816,7 +816,7 @@ func TestCreateFloatCollectionInvalidDim(t *testing.T) { } ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, vecType := range []entity.FieldType{entity.FieldTypeFloatVector, entity.FieldTypeFloat16Vector, entity.FieldTypeBFloat16Vector} { for _, invalidDim := range invalidDims { @@ -837,7 +837,7 @@ func TestCreateFloatCollectionInvalidDim(t *testing.T) { func TestCreateVectorWithoutDim(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) vecFieldName := "vec" @@ -853,7 +853,7 @@ func TestCreateVectorWithoutDim(t *testing.T) { // specify dim for sparse vector -> error func TestCreateCollectionSparseVectorWithDim(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) schema := entity.NewSchema().WithField( @@ -868,7 +868,7 @@ func TestCreateCollectionSparseVectorWithDim(t *testing.T) { func TestCreateArrayFieldInvalidCapacity(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) @@ -892,7 +892,7 @@ func TestCreateArrayFieldInvalidCapacity(t *testing.T) { // test create collection varchar array with invalid max length func TestCreateVarcharArrayInvalidLength(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) @@ -915,7 +915,7 @@ func TestCreateVarcharArrayInvalidLength(t *testing.T) { // test create collection varchar array with invalid max length func TestCreateVarcharInvalidLength(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) @@ -936,7 +936,7 @@ func TestCreateVarcharInvalidLength(t *testing.T) { func TestCreateArrayNotSupportedFieldType(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) // not supported ElementType: Array, Json, FloatVector, BinaryVector @@ -953,7 +953,7 @@ func TestCreateArrayNotSupportedFieldType(t *testing.T) { // the num of vector fields > default limit=4 func TestCreateMultiVectorExceed(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) pkField := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) @@ -969,7 +969,7 @@ func TestCreateMultiVectorExceed(t *testing.T) { // func TestCreateCollection(t *testing.T) {} func TestCreateCollectionInvalidShards(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true).WithIsAutoID(true) @@ -984,7 +984,7 @@ func TestCreateCollectionInvalidShards(t *testing.T) { func TestCreateCollectionInvalid(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) collName := common.GenRandomString(prefix, 6) type mSchemaErr struct { @@ -1008,7 +1008,7 @@ func TestCreateCollectionInvalid(t *testing.T) { // test rename collection func TestRenameCollection(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -1044,7 +1044,7 @@ func TestRenameCollection(t *testing.T) { // There are collections with the same name in different db. Rename one of them. func TestRenameCollectionDb(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection collectionName := common.GenRandomString("re", 6) @@ -1075,7 +1075,7 @@ func TestRenameCollectionDb(t *testing.T) { func TestRenameCollectionInvalidName(t *testing.T) { // connect ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection collectionName := common.GenRandomString("re", 6) @@ -1096,7 +1096,7 @@ func TestRenameCollectionInvalidName(t *testing.T) { func TestRenameCollectionAdvanced(t *testing.T) { // connect ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create 2 collections name1 := common.GenRandomString("name1", 6) @@ -1121,7 +1121,7 @@ func TestRenameCollectionAdvanced(t *testing.T) { func TestCollectionPropertyTtl(t *testing.T) { // test collection property ttl ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -1154,7 +1154,7 @@ func TestCollectionPropertyTtl(t *testing.T) { func TestCollectionWithPropertyAlterMmap(t *testing.T) { // test collection property mmap ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), @@ -1183,7 +1183,7 @@ func TestCollectionWithPropertyAlterMmap(t *testing.T) { func TestCollectionPropertyMmap(t *testing.T) { // test collection property mmap ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), @@ -1218,7 +1218,7 @@ func TestCollectionPropertyMmap(t *testing.T) { func TestCollectionFakeProperties(t *testing.T) { // test collection property mmap ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection with fake property collName := common.GenRandomString("alter", 6) diff --git a/tests/go_client/testcases/database_test.go b/tests/go_client/testcases/database_test.go index 839a54ed26..6d558ced8d 100644 --- a/tests/go_client/testcases/database_test.go +++ b/tests/go_client/testcases/database_test.go @@ -23,7 +23,7 @@ func teardownTest(t *testing.T) func(t *testing.T) { log.Info("teardown func drop all non-default db") // drop all db ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) dbs, _ := mc.ListDatabase(ctx, client.NewListDatabaseOption()) for _, db := range dbs { if db != common.DefaultDb { @@ -43,7 +43,7 @@ func TestDatabase(t *testing.T) { defer teardownSuite(t) ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - clientDefault := createMilvusClient(ctx, t, &defaultCfg) + clientDefault := hp.CreateMilvusClient(ctx, t, hp.GetDefaultClientConfig()) // create db1 dbName1 := common.GenRandomString("db1", 4) @@ -56,7 +56,7 @@ func TestDatabase(t *testing.T) { require.Containsf(t, dbs, dbName1, fmt.Sprintf("%s db not in dbs: %v", dbName1, dbs)) // new client with db1 - clientDB1 := createMilvusClient(ctx, t, &client.ClientConfig{Address: *addr, DBName: dbName1}) + clientDB1 := hp.CreateMilvusClient(ctx, t, &client.ClientConfig{Address: hp.GetAddr(), DBName: dbName1}) // create collections -> verify collections contains _, db1Col1 := hp.CollPrepare.CreateCollection(ctx, t, clientDB1, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -122,7 +122,7 @@ func TestCreateDb(t *testing.T) { // create db ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) dbName := common.GenRandomString("db", 4) err := mc.CreateDatabase(ctx, client.NewCreateDatabaseOption(dbName)) common.CheckErr(t, err, true) @@ -147,7 +147,7 @@ func TestDropDb(t *testing.T) { // create collection in default db listCollOpt := client.NewListCollectionOption() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) _, defCol := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) collections, _ := mc.ListCollections(ctx, listCollOpt) require.Contains(t, collections, defCol.CollectionName) @@ -194,7 +194,7 @@ func TestUsingDb(t *testing.T) { // create collection in default db listCollOpt := client.NewListCollectionOption() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) _, col := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) // collName := createDefaultCollection(ctx, t, mc, true, common.DefaultShards) @@ -227,12 +227,12 @@ func TestClientWithDb(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) // connect with not existed db - _, err := base.NewMilvusClient(ctx, &client.ClientConfig{Address: *addr, DBName: "dbName"}) + _, err := base.NewMilvusClient(ctx, &client.ClientConfig{Address: hp.GetAddr(), DBName: "dbName"}) common.CheckErr(t, err, false, "database not found") // connect default db -> create a collection in default db mcDefault, errDefault := base.NewMilvusClient(ctx, &client.ClientConfig{ - Address: *addr, + Address: hp.GetAddr(), // DBName: common.DefaultDb, }) common.CheckErr(t, errDefault, true) @@ -248,7 +248,7 @@ func TestClientWithDb(t *testing.T) { // and connect with db mcDb, err := base.NewMilvusClient(ctx, &client.ClientConfig{ - Address: *addr, + Address: hp.GetAddr(), DBName: dbName, }) common.CheckErr(t, err, true) @@ -265,7 +265,7 @@ func TestClientWithDb(t *testing.T) { // connect empty db (actually default db) mcEmpty, err := base.NewMilvusClient(ctx, &client.ClientConfig{ - Address: *addr, + Address: hp.GetAddr(), DBName: "", }) common.CheckErr(t, err, true) @@ -280,7 +280,7 @@ func TestDatabasePropertiesCollectionsNum(t *testing.T) { // create db ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) dbName := common.GenRandomString("db", 4) err := mc.CreateDatabase(ctx, client.NewCreateDatabaseOption(dbName)) common.CheckErr(t, err, true) @@ -338,7 +338,7 @@ func TestDatabasePropertiesRgReplicas(t *testing.T) { // create db ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) dbName := common.GenRandomString("db", 4) err := mc.CreateDatabase(ctx, client.NewCreateDatabaseOption(dbName)) common.CheckErr(t, err, true) @@ -373,7 +373,7 @@ func TestDatabasePropertyDeny(t *testing.T) { // create db and use db ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) dbName := common.GenRandomString("db", 4) err := mc.CreateDatabase(ctx, client.NewCreateDatabaseOption(dbName)) common.CheckErr(t, err, true) @@ -411,7 +411,7 @@ func TestDatabaseFakeProperties(t *testing.T) { // create db ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) dbName := common.GenRandomString("db", 4) err := mc.CreateDatabase(ctx, client.NewCreateDatabaseOption(dbName)) common.CheckErr(t, err, true) diff --git a/tests/go_client/testcases/delete_test.go b/tests/go_client/testcases/delete_test.go index e4c68b680a..b6f750f910 100644 --- a/tests/go_client/testcases/delete_test.go +++ b/tests/go_client/testcases/delete_test.go @@ -18,7 +18,7 @@ import ( func TestDelete(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -54,7 +54,7 @@ func TestDelete(t *testing.T) { // test delete with string pks func TestDeleteVarcharPks(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.VarcharBinary) @@ -89,7 +89,7 @@ func TestDeleteVarcharPks(t *testing.T) { // test delete from empty collection func TestDeleteEmptyCollection(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -114,7 +114,7 @@ func TestDeleteEmptyCollection(t *testing.T) { // test delete from an not exist collection or partition func TestDeleteNotExistName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // delete from not existed collection _, errDelete := mc.Delete(ctx, client.NewDeleteOption("aaa").WithExpr("")) @@ -132,7 +132,7 @@ func TestDeleteNotExistName(t *testing.T) { // delete without loading support: pk ids func TestDeleteComplexExprWithoutLoad(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar) @@ -168,7 +168,7 @@ func TestDeleteComplexExprWithoutLoad(t *testing.T) { // test delete with nil ids func TestDeleteEmptyIds(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.VarcharBinary) @@ -195,7 +195,7 @@ func TestDeleteEmptyIds(t *testing.T) { // test delete with string pks func TestDeleteVarcharEmptyIds(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.VarcharBinary) @@ -231,7 +231,7 @@ func TestDeleteVarcharEmptyIds(t *testing.T) { // test delete with invalid ids func TestDeleteInvalidIds(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.VarcharBinary) @@ -250,7 +250,7 @@ func TestDeleteInvalidIds(t *testing.T) { // test delete with non-pk ids func TestDeleteWithIds(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and a partition pkName := "pk" @@ -296,7 +296,7 @@ func TestDeleteWithIds(t *testing.T) { // test delete with default partition name params func TestDeleteDefaultPartitionName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and a partition cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -334,7 +334,7 @@ func TestDeleteDefaultPartitionName(t *testing.T) { // test delete with empty partition "": actually delete from all partitions func TestDeleteEmptyPartitionName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and a partition cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -372,7 +372,7 @@ func TestDeleteEmptyPartitionName(t *testing.T) { // test delete with partition name func TestDeletePartitionName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and a partition cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -470,7 +470,7 @@ func TestDeleteComplexExpr(t *testing.T) { <-ch }() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and a partition cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar) @@ -533,7 +533,7 @@ func TestDeleteComplexExprJson(t *testing.T) { <-ch }() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and a partition cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar) @@ -570,7 +570,7 @@ func TestDeleteComplexExprJson(t *testing.T) { func TestDeleteInvalidExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and a partition cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar) @@ -593,7 +593,7 @@ func TestDeleteInvalidExpr(t *testing.T) { // test delete with duplicated data ids func TestDeleteDuplicatedPks(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and a partition cp := hp.NewCreateCollectionParams(hp.Int64Vec) diff --git a/tests/go_client/testcases/full_text_search_test.go b/tests/go_client/testcases/full_text_search_test.go index 5aeed1ac4f..c3470d59b4 100644 --- a/tests/go_client/testcases/full_text_search_test.go +++ b/tests/go_client/testcases/full_text_search_test.go @@ -13,7 +13,7 @@ import ( func TestFullTextSearchDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert -> flush -> index -> load analyzerParams := map[string]any{"tokenizer": "standard"} @@ -43,7 +43,7 @@ func TestFullTextSearchDefault(t *testing.T) { // TestSearchFullTextBase tests basic full text search functionality with different languages func TestSearchFullTextWithDiffLang(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // Test cases for different languages and analyzers testCases := []struct { @@ -103,7 +103,7 @@ func TestSearchFullTextWithDiffLang(t *testing.T) { // TestSearchFullTextWithDynamicField tests full text search with dynamic field enabled func TestSearchFullTextWithDynamicField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // Test cases for different languages and analyzers testCases := []struct { name string @@ -162,7 +162,7 @@ func TestSearchFullTextWithDynamicField(t *testing.T) { // TestSearchFullTextWithPartitionKey tests full text search with partition key func TestSearchFullTextWithPartitionKey(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // Test cases for different languages and analyzers testCases := []struct { @@ -222,7 +222,7 @@ func TestSearchFullTextWithPartitionKey(t *testing.T) { // TestSearchFullTextWithEmptyData tests full text search with empty data func TestSearchFullTextWithEmptyData(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // Test cases for different empty percent testCases := []struct { diff --git a/tests/go_client/testcases/groupby_search_test.go b/tests/go_client/testcases/groupby_search_test.go index ae636c296d..4bdea0bd77 100644 --- a/tests/go_client/testcases/groupby_search_test.go +++ b/tests/go_client/testcases/groupby_search_test.go @@ -58,7 +58,7 @@ func genUnsupportedFloatGroupByIndex() []index.Index { func prepareDataForGroupBySearch(t *testing.T, loopInsert int, insertNi int, idx index.Index, withGrowing bool) (*base.MilvusClient, context.Context, string) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*5) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection with all datatype prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -234,7 +234,7 @@ func TestGroupBySearchSparseVector(t *testing.T) { idxWand := index.NewSparseWANDIndex(entity.IP, 0.2) for _, idx := range []index.Index{idxInverted, idxWand} { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption().TWithMaxLen(common.TestMaxLen), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -293,7 +293,7 @@ func TestSearchGroupByBinaryDefault(t *testing.T) { for _, metricType := range hp.SupportBinIvfFlatMetricType { for _, idx := range genGroupByBinaryIndex(metricType) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -328,7 +328,7 @@ func TestSearchGroupByBinaryGrowing(t *testing.T) { for _, metricType := range hp.SupportBinIvfFlatMetricType { idxBinIvfFlat := index.NewBinIvfFlatIndex(metricType, 128) ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) diff --git a/tests/go_client/testcases/helper/helper.go b/tests/go_client/testcases/helper/helper.go index 81ed7138cd..91c65c4e94 100644 --- a/tests/go_client/testcases/helper/helper.go +++ b/tests/go_client/testcases/helper/helper.go @@ -9,7 +9,7 @@ import ( "go.uber.org/zap" "github.com/milvus-io/milvus/client/v2/entity" - clientv2 "github.com/milvus-io/milvus/client/v2/milvusclient" + client "github.com/milvus-io/milvus/client/v2/milvusclient" "github.com/milvus-io/milvus/pkg/v2/log" "github.com/milvus-io/milvus/tests/go_client/base" "github.com/milvus-io/milvus/tests/go_client/common" @@ -104,6 +104,37 @@ func GetInvalidPartitionKeyFieldType() []entity.FieldType { return nonPkFieldTypes } +// CreateDefaultMilvusClient creates a new client with default configuration +func CreateDefaultMilvusClient(ctx context.Context, t *testing.T) *base.MilvusClient { + t.Helper() + mc, err := base.NewMilvusClient(ctx, defaultClientConfig) + common.CheckErr(t, err, true) + + t.Cleanup(func() { + mc.Close(ctx) + }) + + return mc +} + +// CreateMilvusClient create connect +func CreateMilvusClient(ctx context.Context, t *testing.T, cfg *client.ClientConfig) *base.MilvusClient { + t.Helper() + + var ( + mc *base.MilvusClient + err error + ) + mc, err = base.NewMilvusClient(ctx, cfg) + common.CheckErr(t, err, true) + + t.Cleanup(func() { + mc.Close(ctx) + }) + + return mc +} + // CollectionPrepare ----------------- prepare data -------------------------- type CollectionPrepare struct{} @@ -112,9 +143,9 @@ var ( FieldsFact FieldsFactory ) -func mergeOptions(schema *entity.Schema, opts ...CreateCollectionOpt) clientv2.CreateCollectionOption { +func mergeOptions(schema *entity.Schema, opts ...CreateCollectionOpt) client.CreateCollectionOption { // - collectionOption := clientv2.NewCreateCollectionOption(schema.CollectionName, schema) + collectionOption := client.NewCreateCollectionOption(schema.CollectionName, schema) tmpOption := &createCollectionOpt{} for _, o := range opts { o(tmpOption) @@ -159,7 +190,7 @@ func (chainTask *CollectionPrepare) CreateCollection(ctx context.Context, t *tes ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), time.Second*10) defer cancel() - err := mc.DropCollection(ctx, clientv2.NewDropCollectionOption(schema.CollectionName)) + err := mc.DropCollection(ctx, client.NewDropCollectionOption(schema.CollectionName)) common.CheckErr(t, err, true) }) return chainTask, schema @@ -167,14 +198,14 @@ func (chainTask *CollectionPrepare) CreateCollection(ctx context.Context, t *tes func (chainTask *CollectionPrepare) InsertData(ctx context.Context, t *testing.T, mc *base.MilvusClient, ip *InsertParams, option *GenDataOption, -) (*CollectionPrepare, clientv2.InsertResult) { +) (*CollectionPrepare, client.InsertResult) { if nil == ip.Schema || ip.Schema.CollectionName == "" { log.Fatal("[InsertData] Nil Schema is not expected") } // print option log.Info("GenDataOption", zap.Any("option", option)) columns, dynamicColumns := GenColumnsBasedSchema(ip.Schema, option) - insertOpt := clientv2.NewColumnBasedInsertOption(ip.Schema.CollectionName).WithColumns(columns...).WithColumns(dynamicColumns...) + insertOpt := client.NewColumnBasedInsertOption(ip.Schema.CollectionName).WithColumns(columns...).WithColumns(dynamicColumns...) if ip.PartitionName != "" { insertOpt.WithPartition(ip.PartitionName) } @@ -185,7 +216,7 @@ func (chainTask *CollectionPrepare) InsertData(ctx context.Context, t *testing.T } func (chainTask *CollectionPrepare) FlushData(ctx context.Context, t *testing.T, mc *base.MilvusClient, collName string) *CollectionPrepare { - flushTask, err := mc.Flush(ctx, clientv2.NewFlushOption(collName)) + flushTask, err := mc.Flush(ctx, client.NewFlushOption(collName)) common.CheckErr(t, err, true) err = flushTask.Await(ctx) common.CheckErr(t, err, true) @@ -203,14 +234,14 @@ func (chainTask *CollectionPrepare) CreateIndex(ctx context.Context, t *testing. if field.DataType >= 100 { if idx, ok := mFieldIndex[field.Name]; ok { log.Info("CreateIndex", zap.String("indexName", idx.Name()), zap.Any("indexType", idx.IndexType()), zap.Any("indexParams", idx.Params())) - createIndexTask, err := mc.CreateIndex(ctx, clientv2.NewCreateIndexOption(collName, field.Name, idx)) + createIndexTask, err := mc.CreateIndex(ctx, client.NewCreateIndexOption(collName, field.Name, idx)) common.CheckErr(t, err, true) err = createIndexTask.Await(ctx) common.CheckErr(t, err, true) } else { idx := GetDefaultVectorIndex(field.DataType) log.Info("CreateIndex", zap.String("indexName", idx.Name()), zap.Any("indexType", idx.IndexType()), zap.Any("indexParams", idx.Params())) - createIndexTask, err := mc.CreateIndex(ctx, clientv2.NewCreateIndexOption(collName, field.Name, idx)) + createIndexTask, err := mc.CreateIndex(ctx, client.NewCreateIndexOption(collName, field.Name, idx)) common.CheckErr(t, err, true) err = createIndexTask.Await(ctx) common.CheckErr(t, err, true) @@ -224,7 +255,8 @@ func (chainTask *CollectionPrepare) Load(ctx context.Context, t *testing.T, mc * if lp.CollectionName == "" { log.Fatal("[Load] Empty collection name is not expected") } - loadTask, err := mc.LoadCollection(ctx, clientv2.NewLoadCollectionOption(lp.CollectionName).WithReplica(lp.Replica).WithLoadFields(lp.LoadFields...).WithSkipLoadDynamicField(lp.SkipLoadDynamicField)) + loadTask, err := mc.LoadCollection(ctx, client.NewLoadCollectionOption(lp.CollectionName).WithReplica(lp.Replica).WithLoadFields(lp.LoadFields...). + WithSkipLoadDynamicField(lp.SkipLoadDynamicField).WithResourceGroup(lp.ResourceGroups...).WithRefresh(lp.IsRefresh)) common.CheckErr(t, err, true) err = loadTask.Await(ctx) common.CheckErr(t, err, true) diff --git a/tests/go_client/testcases/helper/read_helper.go b/tests/go_client/testcases/helper/read_helper.go index 3d48d8d966..fcd66ca684 100644 --- a/tests/go_client/testcases/helper/read_helper.go +++ b/tests/go_client/testcases/helper/read_helper.go @@ -9,7 +9,9 @@ type LoadParams struct { CollectionName string Replica int LoadFields []string + ResourceGroups []string SkipLoadDynamicField bool + IsRefresh bool } func NewLoadParams(collectionName string) *LoadParams { @@ -23,6 +25,11 @@ func (opt *LoadParams) TWithReplica(replica int) *LoadParams { return opt } +func (opt *LoadParams) TWithResourceGroups(resourceGroups ...string) *LoadParams { + opt.ResourceGroups = resourceGroups + return opt +} + func (opt *LoadParams) TWithLoadFields(loadFields ...string) *LoadParams { opt.LoadFields = loadFields return opt @@ -33,6 +40,11 @@ func (opt *LoadParams) TWithSkipLoadDynamicField(skipFlag bool) *LoadParams { return opt } +func (opt *LoadParams) TWithIsRefresh(isRefresh bool) *LoadParams { + opt.IsRefresh = isRefresh + return opt +} + // GenSearchVectors gen search vectors func GenSearchVectors(nq int, dim int, dataType entity.FieldType) []entity.Vector { vectors := make([]entity.Vector, 0, nq) diff --git a/tests/go_client/testcases/helper/test_setup.go b/tests/go_client/testcases/helper/test_setup.go new file mode 100644 index 0000000000..f62316dde8 --- /dev/null +++ b/tests/go_client/testcases/helper/test_setup.go @@ -0,0 +1,94 @@ +package helper + +import ( + "context" + "flag" + "testing" + "time" + + "go.uber.org/zap" + + client "github.com/milvus-io/milvus/client/v2/milvusclient" + "github.com/milvus-io/milvus/pkg/v2/log" + "github.com/milvus-io/milvus/tests/go_client/base" + "github.com/milvus-io/milvus/tests/go_client/common" +) + +var ( + addr = flag.String("addr", "localhost:19530", "server host and port") + logLevel = flag.String("log.level", "info", "log level for test") + defaultClientConfig *client.ClientConfig +) + +func setDefaultClientConfig(cfg *client.ClientConfig) { + defaultClientConfig = cfg +} + +func GetDefaultClientConfig() *client.ClientConfig { + return defaultClientConfig +} + +func GetAddr() string { + return *addr +} + +func parseLogConfig() { + log.Info("Parser Log Level", zap.String("logLevel", *logLevel)) + switch *logLevel { + case "debug", "DEBUG", "Debug": + log.SetLevel(zap.DebugLevel) + case "info", "INFO", "Info": + log.SetLevel(zap.InfoLevel) + case "warn", "WARN", "Warn": + log.SetLevel(zap.WarnLevel) + case "error", "ERROR", "Error": + log.SetLevel(zap.ErrorLevel) + default: + log.SetLevel(zap.InfoLevel) + } +} + +func setup() { + log.Info("Start to setup all......") + flag.Parse() + parseLogConfig() + log.Info("Parser Milvus address", zap.String("address", *addr)) + + // set default milvus client config + setDefaultClientConfig(&client.ClientConfig{Address: *addr}) +} + +// Teardown teardown +func teardown() { + log.Info("Start to tear down all.....") + ctx, cancel := context.WithTimeout(context.Background(), time.Second*common.DefaultTimeout) + defer cancel() + mc, err := base.NewMilvusClient(ctx, defaultClientConfig) + if err != nil { + log.Error("teardown failed to connect milvus with error", zap.Error(err)) + } + defer mc.Close(ctx) + + // clear dbs + dbs, _ := mc.ListDatabase(ctx, client.NewListDatabaseOption()) + for _, db := range dbs { + if db != common.DefaultDb { + _ = mc.UseDatabase(ctx, client.NewUseDatabaseOption(db)) + collections, _ := mc.ListCollections(ctx, client.NewListCollectionOption()) + for _, coll := range collections { + _ = mc.DropCollection(ctx, client.NewDropCollectionOption(coll)) + } + _ = mc.DropDatabase(ctx, client.NewDropDatabaseOption(db)) + } + } +} + +func RunTests(m *testing.M) int { + setup() + code := m.Run() + if code != 0 { + log.Error("Tests failed and exited", zap.Int("code", code)) + } + teardown() + return code +} diff --git a/tests/go_client/testcases/hybrid_search_test.go b/tests/go_client/testcases/hybrid_search_test.go index 49cef96fb6..5438c8cd14 100644 --- a/tests/go_client/testcases/hybrid_search_test.go +++ b/tests/go_client/testcases/hybrid_search_test.go @@ -19,7 +19,7 @@ import ( func TestHybridSearchDefault(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert [0, 3000) -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -57,7 +57,7 @@ func TestHybridSearchDefault(t *testing.T) { func TestHybridSearchTemplateParam(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert [0, 3000) -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -88,7 +88,7 @@ func TestHybridSearchTemplateParam(t *testing.T) { // hybrid search default -> verify success func TestHybridSearchMultiVectorsDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, enableDynamic := range []bool{false, true} { // create -> insert [0, 3000) -> flush -> index -> load @@ -175,7 +175,7 @@ func TestHybridSearchMultiVectorsDefault(t *testing.T) { func TestHybridSearchInvalidParams(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -230,7 +230,7 @@ func TestHybridSearchInvalidParams(t *testing.T) { // vector dim mismatch func TestHybridSearchInvalidVectors(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) @@ -252,7 +252,7 @@ func TestHybridSearchInvalidVectors(t *testing.T) { // hybrid search Pagination -> verify success func TestHybridSearchMultiVectorsPagination(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) @@ -309,7 +309,7 @@ func TestHybridSearchMultiVectorsPagination(t *testing.T) { func TestHybridSearchMultiVectorsRangeSearch(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert [0, 3000) -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -351,7 +351,7 @@ func TestHybridSearchSparseVector(t *testing.T) { for _, idx := range []index.Index{idxInverted, idxWand} { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert [0, 3000) -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), @@ -387,7 +387,7 @@ func TestHybridSearchSparseVector(t *testing.T) { func TestHybridSearchGroupBy(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption()) diff --git a/tests/go_client/testcases/index_test.go b/tests/go_client/testcases/index_test.go index 1e216506b1..ee4523af65 100644 --- a/tests/go_client/testcases/index_test.go +++ b/tests/go_client/testcases/index_test.go @@ -18,7 +18,7 @@ import ( func TestIndexVectorDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64MultiVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -50,7 +50,7 @@ func TestIndexVectorDefault(t *testing.T) { func TestIndexVectorIP(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64MultiVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -83,7 +83,7 @@ func TestIndexVectorIP(t *testing.T) { func TestIndexVectorCosine(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64MultiVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -116,7 +116,7 @@ func TestIndexVectorCosine(t *testing.T) { func TestIndexAutoFloatVector(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -152,7 +152,7 @@ func TestIndexAutoFloatVector(t *testing.T) { func TestIndexAutoBinaryVector(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.VarcharBinary) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -192,7 +192,7 @@ func TestIndexAutoBinaryVector(t *testing.T) { func TestIndexAutoSparseVector(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -229,7 +229,7 @@ func TestIndexAutoSparseVector(t *testing.T) { // test create auto index on all vector and scalar index func TestCreateAutoIndexAllFields(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.AllFields) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -275,7 +275,7 @@ func TestCreateAutoIndexAllFields(t *testing.T) { func TestIndexBinaryFlat(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.VarcharBinary) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -306,7 +306,7 @@ func TestIndexBinaryFlat(t *testing.T) { func TestIndexBinaryIvfFlat(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.VarcharBinary) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -338,7 +338,7 @@ func TestIndexBinaryIvfFlat(t *testing.T) { // test create binary index with unsupported metrics type func TestCreateBinaryIndexNotSupportedMetricType(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.VarcharBinary) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -382,7 +382,7 @@ func TestCreateBinaryIndexNotSupportedMetricType(t *testing.T) { func TestIndexInvalidMetricType(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -403,7 +403,7 @@ func TestIndexInvalidMetricType(t *testing.T) { // Trie scalar Trie index only supported on varchar func TestCreateTrieScalarIndex(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -439,7 +439,7 @@ func TestCreateTrieScalarIndex(t *testing.T) { // Sort scalar index only supported on numeric field func TestCreateSortedScalarIndex(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -489,7 +489,7 @@ func TestCreateSortedScalarIndex(t *testing.T) { // create Inverted index for all scalar fields func TestCreateInvertedScalarIndex(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -532,7 +532,7 @@ func TestCreateInvertedScalarIndex(t *testing.T) { // test create index on vector field -> error func TestCreateScalarIndexVectorField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64MultiVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -556,7 +556,7 @@ func TestCreateScalarIndexVectorField(t *testing.T) { // test create scalar index with vector field name func TestCreateIndexWithOtherFieldName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.VarcharBinary) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -588,7 +588,7 @@ func TestCreateIndexWithOtherFieldName(t *testing.T) { // create all scalar index on json field -> error func TestCreateIndexJsonField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VecJSON) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -621,7 +621,7 @@ func TestCreateIndexJsonField(t *testing.T) { // array field on supported array field func TestCreateUnsupportedIndexArrayField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VecArray) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -659,7 +659,7 @@ func TestCreateUnsupportedIndexArrayField(t *testing.T) { // create inverted index on array field func TestCreateInvertedIndexArrayField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VecArray) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -697,7 +697,7 @@ func TestCreateInvertedIndexArrayField(t *testing.T) { // test create index without specify index name: default index name is field name func TestCreateIndexWithoutName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -724,7 +724,7 @@ func TestCreateIndexWithoutName(t *testing.T) { // test create index on same field twice func TestCreateIndexDup(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -756,7 +756,7 @@ func TestCreateIndexSparseVectorGeneric(t *testing.T) { for _, idx := range []index.Index{idxInverted, idxWand} { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -783,7 +783,7 @@ func TestCreateIndexSparseVector(t *testing.T) { idxWand1 := index.NewSparseWANDIndex(entity.IP, 0.3) for _, idx := range []index.Index{idxInverted1, idxWand1} { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -806,7 +806,7 @@ func TestCreateIndexSparseVector(t *testing.T) { func TestCreateSparseIndexInvalidParams(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -842,7 +842,7 @@ func TestCreateSparseIndexInvalidParams(t *testing.T) { // create sparse unsupported index: other vector index and scalar index and auto index func TestCreateSparseUnsupportedIndex(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -872,7 +872,7 @@ func TestCreateSparseUnsupportedIndex(t *testing.T) { // test new index by Generic index func TestCreateIndexGeneric(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -899,7 +899,7 @@ func TestCreateIndexGeneric(t *testing.T) { // test create index with not exist index name and not exist field name func TestIndexNotExistName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create index with not exist collection idx := index.NewHNSWIndex(entity.L2, 8, 96) @@ -924,7 +924,7 @@ func TestIndexNotExistName(t *testing.T) { // test create float / binary / sparse vector index on non-vector field func TestCreateVectorIndexScalarField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VecAllScalar) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -959,7 +959,7 @@ func TestCreateVectorIndexScalarField(t *testing.T) { // test create index with invalid params func TestCreateIndexInvalidParams(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -1016,7 +1016,7 @@ func TestCreateIndexInvalidParams(t *testing.T) { func TestCreateIndexNil(t *testing.T) { t.Skip("Issue: https://github.com/milvus-io/milvus-sdk-go/issues/358") ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -1029,7 +1029,7 @@ func TestCreateIndexNil(t *testing.T) { func TestCreateIndexAsync(t *testing.T) { t.Log("wait GetIndexState") ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -1051,7 +1051,7 @@ func TestCreateIndexAsync(t *testing.T) { // create same index name on different vector field func TestIndexMultiVectorDupName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64MultiVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -1079,7 +1079,7 @@ func TestIndexMultiVectorDupName(t *testing.T) { func TestDropIndex(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64MultiVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -1123,7 +1123,7 @@ func TestDropIndex(t *testing.T) { func TestDropIndexCreateIndexWithIndexName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64MultiVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) diff --git a/tests/go_client/testcases/insert_test.go b/tests/go_client/testcases/insert_test.go index fc7e9c2592..1acb3feb77 100644 --- a/tests/go_client/testcases/insert_test.go +++ b/tests/go_client/testcases/insert_test.go @@ -20,7 +20,7 @@ import ( func TestInsertDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, autoID := range [2]bool{false, true} { // create collection cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -44,7 +44,7 @@ func TestInsertDefault(t *testing.T) { func TestInsertDefaultPartition(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, autoID := range [2]bool{false, true} { // create collection cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -73,7 +73,7 @@ func TestInsertDefaultPartition(t *testing.T) { func TestInsertVarcharPkDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, autoID := range [2]bool{false, true} { // create collection cp := hp.NewCreateCollectionParams(hp.VarcharBinary) @@ -99,7 +99,7 @@ func TestInsertVarcharPkDefault(t *testing.T) { func TestInsertAllFieldsData(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, dynamic := range [2]bool{false, true} { // create collection cp := hp.NewCreateCollectionParams(hp.AllFields) @@ -138,7 +138,7 @@ func TestInsertAllFieldsData(t *testing.T) { // test insert dynamic data with column func TestInsertDynamicExtraColumn(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -191,7 +191,7 @@ func TestInsertDynamicExtraColumn(t *testing.T) { func TestInsertFp16OrBf16VectorsWithFp32Vector(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) fp16VecField := entity.NewField().WithName(common.DefaultFloat16VecFieldName).WithDataType(entity.FieldTypeFloat16Vector).WithDim(common.DefaultDim) @@ -214,7 +214,7 @@ func TestInsertFp16OrBf16VectorsWithFp32Vector(t *testing.T) { // test insert array column with empty data func TestInsertEmptyArray(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VecArray) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -236,7 +236,7 @@ func TestInsertEmptyArray(t *testing.T) { func TestInsertArrayDataTypeNotMatch(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // share field and data int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) @@ -267,7 +267,7 @@ func TestInsertArrayDataTypeNotMatch(t *testing.T) { func TestInsertArrayDataCapacityExceed(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // share field and data int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) @@ -294,7 +294,7 @@ func TestInsertArrayDataCapacityExceed(t *testing.T) { // test insert not exist collection or not exist partition func TestInsertNotExist(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // insert data into not exist collection intColumn := hp.GenColumnData(common.DefaultNb, entity.FieldTypeInt64, *hp.TNewDataOption()) @@ -313,7 +313,7 @@ func TestInsertNotExist(t *testing.T) { // test insert data columns len, order mismatch fields func TestInsertColumnsMismatchFields(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -347,7 +347,7 @@ func TestInsertColumnsMismatchFields(t *testing.T) { // test insert with columns which has different len func TestInsertColumnsDifferentLen(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -364,7 +364,7 @@ func TestInsertColumnsDifferentLen(t *testing.T) { func TestInsertAutoIdPkData(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -383,7 +383,7 @@ func TestInsertAutoIdPkData(t *testing.T) { // test insert invalid column: empty column or dim not match func TestInsertInvalidColumn(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -409,7 +409,7 @@ func TestInsertInvalidColumn(t *testing.T) { // test insert invalid column: empty column or dim not match func TestInsertColumnVarcharExceedLen(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection varcharMaxLen := 10 cp := hp.NewCreateCollectionParams(hp.VarcharBinary) @@ -431,7 +431,7 @@ func TestInsertColumnVarcharExceedLen(t *testing.T) { // test insert sparse vector func TestInsertSparseData(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -451,7 +451,7 @@ func TestInsertSparseData(t *testing.T) { func TestInsertSparseDataMaxDim(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -477,7 +477,7 @@ func TestInsertSparseDataMaxDim(t *testing.T) { func TestInsertReadSparseEmptyVector(t *testing.T) { // invalid sparse vector: positions >= uint32 ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -516,7 +516,7 @@ func TestInsertSparseInvalidVector(t *testing.T) { // invalid sparse vector: positions >= uint32 ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -540,7 +540,7 @@ func TestInsertSparseInvalidVector(t *testing.T) { func TestInsertSparseVectorSamePosition(t *testing.T) { // invalid sparse vector: positions >= uint32 ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -567,7 +567,7 @@ func TestInsertSparseVectorSamePosition(t *testing.T) { func TestInsertDefaultRows(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, autoId := range []bool{false, true} { cp := hp.NewCreateCollectionParams(hp.Int64Vec) @@ -606,7 +606,7 @@ func TestInsertAllFieldsRows(t *testing.T) { t.Skip("https://github.com/milvus-io/milvus/issues/33459") t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, enableDynamicField := range [2]bool{true, false} { cp := hp.NewCreateCollectionParams(hp.AllFields) @@ -639,7 +639,7 @@ func TestInsertVarcharRows(t *testing.T) { t.Skip("https://github.com/milvus-io/milvus/issues/33457") t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, autoId := range []bool{true} { cp := hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec) @@ -667,7 +667,7 @@ func TestInsertVarcharRows(t *testing.T) { func TestInsertSparseRows(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) int64Field := entity.NewField().WithName(common.DefaultInt64FieldName).WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) sparseField := entity.NewField().WithName(common.DefaultSparseVecFieldName).WithDataType(entity.FieldTypeSparseVector) @@ -708,7 +708,7 @@ func TestInsertSparseRows(t *testing.T) { // test field name: pk, row json name: int64 func TestInsertRowFieldNameNotMatch(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection with pk name: pk vecField := entity.NewField().WithName(common.DefaultFloatVecFieldName).WithDataType(entity.FieldTypeFloatVector).WithDim(common.DefaultDim) @@ -727,7 +727,7 @@ func TestInsertRowFieldNameNotMatch(t *testing.T) { // test field name: pk, row json name: int64 func TestInsertRowMismatchFields(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption().TWithDim(8), hp.TNewSchemaOption()) @@ -782,7 +782,7 @@ func TestInsertDisableAutoIDRow(t *testing.T) { */ t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption().TWithAutoID(false), hp.TNewSchemaOption().TWithAutoID(false)) @@ -817,7 +817,7 @@ func TestInsertEnableAutoIDRow(t *testing.T) { */ t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption().TWithAutoID(true), hp.TNewSchemaOption().TWithAutoID(true)) @@ -850,7 +850,7 @@ func TestInsertEnableAutoIDRow(t *testing.T) { func TestFlushRate(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection cp := hp.NewCreateCollectionParams(hp.Int64Vec) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, cp, hp.TNewFieldsOption().TWithAutoID(true), hp.TNewSchemaOption()) diff --git a/tests/go_client/testcases/load_release_test.go b/tests/go_client/testcases/load_release_test.go index 44dcf957bc..04a5a3d285 100644 --- a/tests/go_client/testcases/load_release_test.go +++ b/tests/go_client/testcases/load_release_test.go @@ -19,7 +19,7 @@ import ( // test load collection func TestLoadCollection(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -49,7 +49,7 @@ func TestLoadCollection(t *testing.T) { func TestLoadCollectionNotExist(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) // connect - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // Load collection _, errLoad := mc.LoadCollection(ctx, clientv2.NewLoadCollectionOption("collName")) @@ -59,7 +59,7 @@ func TestLoadCollectionNotExist(t *testing.T) { // test load collection async func TestLoadCollectionAsync(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -81,7 +81,7 @@ func TestLoadCollectionAsync(t *testing.T) { // load collection without index func TestLoadCollectionWithoutIndex(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -99,7 +99,7 @@ func TestLoadCollectionWithoutIndex(t *testing.T) { // load collection with multi partitions func TestLoadCollectionMultiPartitions(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) parName := common.GenRandomString("p", 4) @@ -157,7 +157,7 @@ func TestLoadCollectionMultiPartitions(t *testing.T) { // test load repeated partition names func TestLoadPartitionsRepeatedly(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) parName := common.GenRandomString("p", 4) @@ -191,7 +191,7 @@ func TestLoadPartitionsRepeatedly(t *testing.T) { func TestLoadMultiVectorsIndex(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection -> insert -> flush -> index _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -210,7 +210,7 @@ func TestLoadMultiVectorsIndex(t *testing.T) { func TestLoadCollectionAllFields(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection -> insert -> flush -> index prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -233,7 +233,7 @@ func TestLoadCollectionAllFields(t *testing.T) { func TestLoadCollectionSparse(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection -> insert -> flush -> index prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -262,7 +262,7 @@ func TestLoadPartialFields(t *testing.T) { */ // create collection -> insert -> flush -> index ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) @@ -310,7 +310,7 @@ func TestLoadSkipDynamicField(t *testing.T) { */ // create collection -> insert -> flush -> index ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -347,7 +347,7 @@ func TestLoadPartialVectorFields(t *testing.T) { */ // create collection -> insert -> flush -> index ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection -> insert -> flush -> index prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -371,7 +371,7 @@ func TestLoadPartialFieldsPartitions(t *testing.T) { */ // no [pk, clustering, part dynamic fields] field, not all fields ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) parName := common.GenRandomString("p", 4) @@ -423,7 +423,7 @@ func TestLoadPartialFieldsWithoutPartitionKey(t *testing.T) { not index: error */ ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // define fields & schema pkField := entity.NewField().WithName("pk").WithDataType(entity.FieldTypeInt64).WithIsPrimaryKey(true) @@ -460,7 +460,7 @@ func TestLoadPartialFieldsRepeated(t *testing.T) { 1. repeated Load with different LoadFields -> error */ ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecArray), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -480,7 +480,7 @@ func TestLoadPartialFieldsRepeated(t *testing.T) { func TestReleaseCollection(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -501,7 +501,7 @@ func TestReleaseCollection(t *testing.T) { func TestReleaseCollectionNotExist(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) // connect - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // Load collection errLoad := mc.ReleaseCollection(ctx, clientv2.NewReleaseCollectionOption("collName")) @@ -510,7 +510,7 @@ func TestReleaseCollectionNotExist(t *testing.T) { func TestReleasePartitions(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) parName := common.GenRandomString("p", 4) nb := 100 @@ -541,7 +541,7 @@ func TestReleasePartitions(t *testing.T) { func TestReleasePartitionsNotExist(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) // connect - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // Load collection _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) diff --git a/tests/go_client/testcases/main_test.go b/tests/go_client/testcases/main_test.go index 65c99e7efe..63865d06ba 100644 --- a/tests/go_client/testcases/main_test.go +++ b/tests/go_client/testcases/main_test.go @@ -1,112 +1,12 @@ package testcases import ( - "context" - "flag" "os" "testing" - "time" - "go.uber.org/zap" - - clientv2 "github.com/milvus-io/milvus/client/v2/milvusclient" - "github.com/milvus-io/milvus/pkg/v2/log" - "github.com/milvus-io/milvus/tests/go_client/base" - "github.com/milvus-io/milvus/tests/go_client/common" + "github.com/milvus-io/milvus/tests/go_client/testcases/helper" ) -var ( - addr = flag.String("addr", "localhost:19530", "server host and port") - logLevel = flag.String("log.level", "info", "log level for test") - defaultCfg clientv2.ClientConfig -) - -// teardown -func teardown() { - log.Info("Start to tear down all.....") - ctx, cancel := context.WithTimeout(context.Background(), time.Second*common.DefaultTimeout) - defer cancel() - mc, err := base.NewMilvusClient(ctx, &defaultCfg) - if err != nil { - log.Error("teardown failed to connect milvus with error", zap.Error(err)) - } - defer mc.Close(ctx) - - // clear dbs - dbs, _ := mc.ListDatabase(ctx, clientv2.NewListDatabaseOption()) - for _, db := range dbs { - if db != common.DefaultDb { - _ = mc.UseDatabase(ctx, clientv2.NewUseDatabaseOption(db)) - collections, _ := mc.ListCollections(ctx, clientv2.NewListCollectionOption()) - for _, coll := range collections { - _ = mc.DropCollection(ctx, clientv2.NewDropCollectionOption(coll)) - } - _ = mc.DropDatabase(ctx, clientv2.NewDropDatabaseOption(db)) - } - } -} - -// create connect -func createDefaultMilvusClient(ctx context.Context, t *testing.T) *base.MilvusClient { - t.Helper() - - var ( - mc *base.MilvusClient - err error - ) - mc, err = base.NewMilvusClient(ctx, &defaultCfg) - common.CheckErr(t, err, true) - - t.Cleanup(func() { - mc.Close(ctx) - }) - - return mc -} - -// create connect -func createMilvusClient(ctx context.Context, t *testing.T, cfg *clientv2.ClientConfig) *base.MilvusClient { - t.Helper() - - var ( - mc *base.MilvusClient - err error - ) - mc, err = base.NewMilvusClient(ctx, cfg) - common.CheckErr(t, err, true) - - t.Cleanup(func() { - mc.Close(ctx) - }) - - return mc -} - -func parseLogConfig() { - log.Info("Parser Log Level", zap.String("logLevel", *logLevel)) - switch *logLevel { - case "debug", "DEBUG", "Debug": - log.SetLevel(zap.DebugLevel) - case "info", "INFO", "Info": - log.SetLevel(zap.InfoLevel) - case "warn", "WARN", "Warn": - log.SetLevel(zap.WarnLevel) - case "error", "ERROR", "Error": - log.SetLevel(zap.ErrorLevel) - default: - log.SetLevel(zap.InfoLevel) - } -} - func TestMain(m *testing.M) { - flag.Parse() - parseLogConfig() - log.Info("Parser Milvus address", zap.String("address", *addr)) - defaultCfg = clientv2.ClientConfig{Address: *addr} - code := m.Run() - if code != 0 { - log.Error("Tests failed and exited", zap.Int("code", code)) - } - teardown() - os.Exit(code) + os.Exit(helper.RunTests(m)) } diff --git a/tests/go_client/testcases/partition_test.go b/tests/go_client/testcases/partition_test.go index f170578c18..ce9c5cf803 100644 --- a/tests/go_client/testcases/partition_test.go +++ b/tests/go_client/testcases/partition_test.go @@ -17,7 +17,7 @@ import ( func TestPartitionsDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -62,7 +62,7 @@ func TestPartitionsDefault(t *testing.T) { func TestCreatePartitionInvalid(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -108,7 +108,7 @@ func TestCreatePartitionInvalid(t *testing.T) { func TestPartitionsNumExceedsMax(t *testing.T) { // 120 seconds may timeout for 1024 partitions ctx := hp.CreateContext(t, time.Second*300) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -132,7 +132,7 @@ func TestPartitionsNumExceedsMax(t *testing.T) { func TestDropPartitionInvalid(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) errDrop := mc.DropPartition(ctx, client.NewDropPartitionOption("aaa", "aaa")) @@ -152,7 +152,7 @@ func TestDropPartitionInvalid(t *testing.T) { func TestListHasPartitionInvalid(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // list partitions _, errList := mc.ListPartitions(ctx, client.NewListPartitionOption("aaa")) @@ -165,7 +165,7 @@ func TestListHasPartitionInvalid(t *testing.T) { func TestDropPartitionData(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) diff --git a/tests/go_client/testcases/query_test.go b/tests/go_client/testcases/query_test.go index 5f564c299b..c18a5e7297 100644 --- a/tests/go_client/testcases/query_test.go +++ b/tests/go_client/testcases/query_test.go @@ -20,7 +20,7 @@ import ( // test query from default partition func TestQueryDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -53,7 +53,7 @@ func TestQueryDefault(t *testing.T) { // test query with varchar field filter func TestQueryVarcharPkDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -80,7 +80,7 @@ func TestQueryVarcharPkDefault(t *testing.T) { // test get with invalid ids func TestGetInvalid(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -113,7 +113,7 @@ func TestGetInvalid(t *testing.T) { // query from not existed collection name and partition name func TestQueryNotExistName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // query with not existed collection expr := fmt.Sprintf("%s < %d", common.DefaultInt64FieldName, 100) @@ -133,7 +133,7 @@ func TestQueryNotExistName(t *testing.T) { // test query with invalid partition name func TestQueryInvalidPartitionName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and partition _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -150,7 +150,7 @@ func TestQueryPartition(t *testing.T) { parName := "p1" ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and partition prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -198,7 +198,7 @@ func TestQueryPartition(t *testing.T) { // test query with invalid partition name func TestQueryWithoutExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection and partition _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -220,7 +220,7 @@ func TestQueryWithoutExpr(t *testing.T) { func TestQueryOutputFields(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, enableDynamic := range [2]bool{true, false} { // create -> insert -> flush -> index -> load @@ -292,7 +292,7 @@ func TestQueryOutputFields(t *testing.T) { // test query output all fields and verify data func TestQueryOutputAllFieldsColumn(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection for _, isDynamic := range [2]bool{true, false} { @@ -348,7 +348,7 @@ func TestQueryOutputAllFieldsColumn(t *testing.T) { func TestQueryOutputAllFieldsRows(t *testing.T) { t.Skip("https://github.com/milvus-io/milvus/issues/33459") ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), @@ -378,7 +378,7 @@ func TestQueryOutputAllFieldsRows(t *testing.T) { // test query output varchar and binaryVector fields func TestQueryOutputBinaryAndVarchar(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) @@ -415,7 +415,7 @@ func TestQueryOutputSparse(t *testing.T) { t.Skip("https://github.com/milvus-io/milvus-sdk-go/issues/769") t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) @@ -449,7 +449,7 @@ func TestQueryOutputSparse(t *testing.T) { // test query different array rows has different element length func TestQueryArrayDifferentLenBetweenRows(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecAllScalar), hp.TNewFieldsOption().TWithMaxCapacity(common.TestCapacity*2), hp.TNewSchemaOption()) @@ -496,7 +496,7 @@ func TestQueryArrayDifferentLenBetweenRows(t *testing.T) { // test query with expr and verify output dynamic field data func TestQueryJsonDynamicExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -529,7 +529,7 @@ func TestQueryJsonDynamicExpr(t *testing.T) { // test query with invalid expr func TestQueryInvalidExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -546,7 +546,7 @@ func TestQueryInvalidExpr(t *testing.T) { // Test query json and dynamic collection with string expr func TestQueryCountJsonDynamicExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -624,7 +624,7 @@ func TestQueryCountJsonDynamicExpr(t *testing.T) { func TestQueryNestedJsonExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) prepare.Load(ctx, t, mc, hp.NewLoadParams(schema.CollectionName)) @@ -669,7 +669,7 @@ func TestQueryNestedJsonExpr(t *testing.T) { // test query with all kinds of array expr func TestQueryArrayFieldExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -716,7 +716,7 @@ func TestQueryOutputInvalidOutputFieldCount(t *testing.T) { errMsg string } ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(false)) @@ -742,7 +742,7 @@ func TestQueryOutputInvalidOutputFieldCount(t *testing.T) { func TestQueryWithTemplateParam(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -811,7 +811,7 @@ func TestQueryWithTemplateParam(t *testing.T) { func TestQueryWithTemplateParamInvalid(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) diff --git a/tests/go_client/testcases/search_test.go b/tests/go_client/testcases/search_test.go index e75cdb3802..3c9e97426f 100644 --- a/tests/go_client/testcases/search_test.go +++ b/tests/go_client/testcases/search_test.go @@ -22,7 +22,7 @@ import ( func TestSearchDefault(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -40,7 +40,7 @@ func TestSearchDefault(t *testing.T) { func TestSearchDefaultGrowing(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> index -> load -> insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -58,7 +58,7 @@ func TestSearchDefaultGrowing(t *testing.T) { // test search collection and partition name not exist func TestSearchInvalidCollectionPartitionName(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // search with not exist collection vectors := hp.GenSearchVectors(common.DefaultNq, common.DefaultDim, entity.FieldTypeFloatVector) @@ -84,7 +84,7 @@ func TestSearchInvalidCollectionPartitionName(t *testing.T) { func TestSearchEmptyCollection(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, enableDynamicField := range []bool{true, false} { // create -> index -> load @@ -113,7 +113,7 @@ func TestSearchEmptyCollection(t *testing.T) { func TestSearchEmptySparseCollection(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -131,7 +131,7 @@ func TestSearchEmptySparseCollection(t *testing.T) { // test search with partition names []string{}, specify partitions func TestSearchPartitions(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) parName := common.GenRandomString("p", 4) // create collection and partition @@ -186,7 +186,7 @@ func TestSearchPartitions(t *testing.T) { func TestSearchEmptyOutputFields(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, dynamic := range []bool{true, false} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(dynamic)) @@ -216,7 +216,7 @@ func TestSearchEmptyOutputFields(t *testing.T) { func TestSearchNotExistOutputFields(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, enableDynamic := range []bool{false, true} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(enableDynamic)) @@ -259,7 +259,7 @@ func TestSearchNotExistOutputFields(t *testing.T) { func TestSearchOutputAllFields(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) @@ -287,7 +287,7 @@ func TestSearchOutputAllFields(t *testing.T) { func TestSearchOutputBinaryPk(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) @@ -313,7 +313,7 @@ func TestSearchOutputBinaryPk(t *testing.T) { func TestSearchOutputSparse(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) @@ -339,7 +339,7 @@ func TestSearchOutputSparse(t *testing.T) { // test search with invalid vector field name: not exist; non-vector field, empty fiend name, json and dynamic field -> error func TestSearchInvalidVectorField(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) @@ -381,7 +381,7 @@ func TestSearchInvalidVectorField(t *testing.T) { func TestSearchInvalidVectors(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) @@ -423,7 +423,7 @@ func TestSearchEmptyInvalidVectors(t *testing.T) { t.Log("https://github.com/milvus-io/milvus/issues/33637") t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.CreateIndex(ctx, t, mc, hp.TNewIndexParams(schema)) @@ -456,7 +456,7 @@ func TestSearchEmptyInvalidVectors(t *testing.T) { // test search metric type isn't the same with index metric type func TestSearchNotMatchMetricType(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) @@ -473,7 +473,7 @@ func TestSearchNotMatchMetricType(t *testing.T) { // test search with invalid topK -> error func TestSearchInvalidTopK(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) @@ -491,7 +491,7 @@ func TestSearchInvalidTopK(t *testing.T) { // test search with invalid topK -> error func TestSearchInvalidOffset(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) @@ -509,7 +509,7 @@ func TestSearchInvalidOffset(t *testing.T) { // test search with invalid search params func TestSearchInvalidSearchParams(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) @@ -543,7 +543,7 @@ func TestSearchInvalidSearchParams(t *testing.T) { // search with index scann search param ef < topK -> error func TestSearchInvalidScannReorderK(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption().TWithNb(500)) @@ -579,7 +579,7 @@ func TestSearchScannAllMetricsWithRawData(t *testing.T) { <-ch }() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -614,7 +614,7 @@ func TestSearchScannAllMetricsWithRawData(t *testing.T) { // test search with valid expression func TestSearchExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) @@ -657,7 +657,7 @@ func TestSearchInvalidExpr(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) prepare.InsertData(ctx, t, mc, hp.NewInsertParams(schema), hp.TNewDataOption()) @@ -679,7 +679,7 @@ func TestSearchJsonFieldExpr(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) exprs := []string{ "", @@ -725,7 +725,7 @@ func TestSearchJsonFieldExpr(t *testing.T) { func TestSearchDynamicFieldExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) @@ -786,7 +786,7 @@ func TestSearchDynamicFieldExpr(t *testing.T) { func TestSearchArrayFieldExpr(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create collection prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecArray), hp.TNewFieldsOption(), hp.TNewSchemaOption(). @@ -837,7 +837,7 @@ func TestSearchNotExistedExpr(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, isDynamic := range [2]bool{true, false} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). @@ -864,7 +864,7 @@ func TestSearchNotExistedExpr(t *testing.T) { // test search with fp16/ bf16 /binary vector func TestSearchMultiVectors(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64MultiVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) @@ -934,7 +934,7 @@ func TestSearchSparseVector(t *testing.T) { idxInverted := index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.2", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_INVERTED_INDEX"}) idxWand := index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.3", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_WAND"}) ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, idx := range []index.Index{idxInverted, idxWand} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). @@ -968,7 +968,7 @@ func TestSearchInvalidSparseVector(t *testing.T) { idxInverted := index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.2", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_INVERTED_INDEX"}) idxWand := index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.3", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_WAND"}) ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, idx := range []index.Index{idxInverted, idxWand} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). @@ -999,7 +999,7 @@ func TestSearchWithEmptySparseVector(t *testing.T) { idxInverted := index.NewSparseInvertedIndex(entity.IP, 0.1) idxWand := index.NewSparseWANDIndex(entity.IP, 0.1) ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, idx := range []index.Index{idxInverted, idxWand} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). @@ -1022,7 +1022,7 @@ func TestSearchWithEmptySparseVector(t *testing.T) { func TestSearchFromEmptySparseVector(t *testing.T) { idxInverted := index.NewSparseInvertedIndex(entity.IP, 0.1) ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, idx := range []index.Index{idxInverted} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). @@ -1068,7 +1068,7 @@ func TestSearchSparseVectorPagination(t *testing.T) { idxInverted := index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.2", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_INVERTED_INDEX"}) idxWand := index.NewGenericIndex(common.DefaultSparseVecFieldName, map[string]string{"drop_ratio_build": "0.3", index.MetricTypeKey: "IP", index.IndexTypeKey: "SPARSE_WAND"}) ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) for _, idx := range []index.Index{idxInverted, idxWand} { prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). @@ -1104,7 +1104,7 @@ func TestSearchSparseVectorNotSupported(t *testing.T) { func TestRangeSearchSparseVector(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VarcharSparseVec), hp.TNewFieldsOption(), hp.TNewSchemaOption(). TWithEnableDynamicField(true)) diff --git a/tests/go_client/testcases/upsert_test.go b/tests/go_client/testcases/upsert_test.go index 55a33cfebe..35a411c143 100644 --- a/tests/go_client/testcases/upsert_test.go +++ b/tests/go_client/testcases/upsert_test.go @@ -28,7 +28,7 @@ func TestUpsertAllFields(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) // connect - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert [0, 3000) -> flush -> index -> load // create -> insert -> flush -> index -> load @@ -98,7 +98,7 @@ func TestUpsertSparse(t *testing.T) { t.Parallel() ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) // connect - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert [0, 3000) -> flush -> index -> load // create -> insert -> flush -> index -> load @@ -163,7 +163,7 @@ func TestUpsertVarcharPk(t *testing.T) { upsert "a" -> " a " -> actually new insert */ ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert [0, 3000) -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.VarcharBinary), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -212,7 +212,7 @@ func TestUpsertVarcharPk(t *testing.T) { // test upsert with partition func TestUpsertMultiPartitions(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) parName := common.GenRandomString("p", 4) err := mc.CreatePartition(ctx, client.NewCreatePartitionOption(schema.CollectionName, parName)) @@ -247,7 +247,7 @@ func TestUpsertSamePksManyTimes(t *testing.T) { // query -> gets last upsert entities ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout*2) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.AllFields), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -286,7 +286,7 @@ func TestUpsertAutoID(t *testing.T) { upsert exist pk -> error ? autoID not supported upsert */ ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) nb := 100 prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption().TWithAutoID(true), hp.TNewSchemaOption()) @@ -335,7 +335,7 @@ func TestUpsertAutoID(t *testing.T) { // test upsert with invalid collection / partition name func TestUpsertNotExistCollectionPartition(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // upsert not exist collection _, errUpsert := mc.Upsert(ctx, client.NewColumnBasedInsertOption("aaa")) @@ -357,7 +357,7 @@ func TestUpsertNotExistCollectionPartition(t *testing.T) { // test upsert with invalid column data func TestUpsertInvalidColumnData(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create and insert _, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption()) @@ -408,7 +408,7 @@ func TestUpsertInvalidColumnData(t *testing.T) { func TestUpsertDynamicField(t *testing.T) { // enable dynamic field and insert dynamic column ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create -> insert [0, 3000) -> flush -> index -> load prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64Vec), hp.TNewFieldsOption(), hp.TNewSchemaOption().TWithEnableDynamicField(true)) @@ -451,7 +451,7 @@ func TestUpsertDynamicField(t *testing.T) { func TestUpsertWithoutLoading(t *testing.T) { ctx := hp.CreateContext(t, time.Second*common.DefaultTimeout) - mc := createDefaultMilvusClient(ctx, t) + mc := hp.CreateDefaultMilvusClient(ctx, t) // create and insert prepare, schema := hp.CollPrepare.CreateCollection(ctx, t, mc, hp.NewCreateCollectionParams(hp.Int64VecJSON), hp.TNewFieldsOption(), hp.TNewSchemaOption())