2021-05-11 17:59:29 +08:00
|
|
|
import pytest
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-06-05 10:25:34 +08:00
|
|
|
from base.client_base import TestcaseBase
|
2021-06-04 09:35:34 +08:00
|
|
|
from base.index_wrapper import ApiIndexWrapper
|
2021-05-13 12:17:15 +08:00
|
|
|
from utils.util_log import test_log as log
|
2021-05-25 19:09:31 +08:00
|
|
|
from common import common_func as cf
|
|
|
|
from common import common_type as ct
|
2021-06-09 14:23:48 +08:00
|
|
|
from common.common_type import CaseLabel, CheckTasks
|
2021-07-15 15:03:54 +08:00
|
|
|
from common.code_mapping import CollectionErrorMessage as clem
|
|
|
|
from common.code_mapping import IndexErrorMessage as iem
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-12-22 17:07:48 +08:00
|
|
|
from utils.util_pymilvus import *
|
2021-08-31 18:49:59 +08:00
|
|
|
from common.constants import *
|
|
|
|
|
2021-05-25 19:09:31 +08:00
|
|
|
prefix = "index"
|
|
|
|
default_schema = cf.gen_default_collection_schema()
|
|
|
|
default_field_name = ct.default_float_vec_field_name
|
|
|
|
default_index_params = {"index_type": "IVF_SQ8", "metric_type": "L2", "params": {"nlist": 64}}
|
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
# copied from pymilvus
|
|
|
|
uid = "test_index"
|
2022-01-06 09:35:30 +08:00
|
|
|
# BUILD_TIMEOUT = 300
|
2021-08-31 18:49:59 +08:00
|
|
|
field_name = default_float_vec_field_name
|
|
|
|
binary_field_name = default_binary_vec_field_name
|
2021-10-11 15:32:55 +08:00
|
|
|
# query = gen_search_vectors_params(field_name, default_entities, default_top_k, 1)
|
2021-08-31 18:49:59 +08:00
|
|
|
default_index = {"index_type": "IVF_FLAT", "params": {"nlist": 128}, "metric_type": "L2"}
|
|
|
|
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-06-05 10:25:34 +08:00
|
|
|
class TestIndexParams(TestcaseBase):
|
2021-05-25 19:09:31 +08:00
|
|
|
""" Test case of index interface """
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.parametrize("collection", [None, "coll"])
|
|
|
|
def test_index_non_collection(self, collection):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
2021-05-27 16:58:11 +08:00
|
|
|
target: test index with None collection
|
|
|
|
method: input none collection object
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
self._connect()
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection, default_field_name, default_index_params, check_task=CheckTasks.err_res,
|
2021-07-15 15:03:54 +08:00
|
|
|
check_items={ct.err_code: 0, ct.err_msg: clem.CollectionType})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-07-15 15:03:54 +08:00
|
|
|
@pytest.mark.parametrize("field_name", ct.get_invalid_strs)
|
|
|
|
def test_index_field_name_invalid(self, field_name):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with error field name
|
|
|
|
method: input field name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2021-07-15 15:03:54 +08:00
|
|
|
collection_name = cf.gen_unique_str(prefix)
|
|
|
|
|
|
|
|
collection_w = self.init_collection_wrap(name=collection_name)
|
|
|
|
|
2021-09-16 17:21:49 +08:00
|
|
|
log.error(iem.WrongFieldName % str(field_name))
|
2021-07-15 15:03:54 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, field_name, default_index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1,
|
2021-09-16 17:21:49 +08:00
|
|
|
ct.err_msg: iem.WrongFieldName % str(field_name)})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_field_name_not_existed(self):
|
|
|
|
"""
|
|
|
|
target: test index with error field name
|
|
|
|
method: input field name not created
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
f_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-06-23 16:50:07 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, f_name, default_index_params, check_task=CheckTasks.err_res,
|
2021-09-16 17:21:49 +08:00
|
|
|
check_items={ct.err_code: 1,
|
|
|
|
ct.err_msg: f"cannot create index on non-existed field: {f_name}"})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-09-17 11:59:49 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
# TODO (reason="pymilvus issue #677", raises=TypeError)
|
|
|
|
@pytest.mark.parametrize("index_type", ct.get_invalid_strs)
|
|
|
|
def test_index_type_invalid(self, index_type):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with error index type
|
|
|
|
method: input invalid index type
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-05-25 19:09:31 +08:00
|
|
|
index_params = copy.deepcopy(default_index_params)
|
2021-08-31 18:49:59 +08:00
|
|
|
index_params["index_type"] = index_type
|
2021-06-23 16:50:07 +08:00
|
|
|
if not isinstance(index_params["index_type"], str):
|
|
|
|
msg = "must be str"
|
|
|
|
else:
|
|
|
|
msg = "Invalid index_type"
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: msg})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_type_not_supported(self):
|
|
|
|
"""
|
|
|
|
target: test index with error index type
|
|
|
|
method: input unsupported index type
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-05-25 19:09:31 +08:00
|
|
|
index_params = copy.deepcopy(default_index_params)
|
|
|
|
index_params["index_type"] = "IVFFFFFFF"
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: ""})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_params_invalid(self, get_invalid_index_params):
|
|
|
|
"""
|
|
|
|
target: test index with error index params
|
|
|
|
method: input invalid index params
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-05-25 19:09:31 +08:00
|
|
|
index_params = get_invalid_index_params
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: ""})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-06-09 14:23:48 +08:00
|
|
|
# TODO: not supported
|
2021-05-25 19:09:31 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_name_invalid(self, get_invalid_index_name):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with error index name
|
|
|
|
method: input invalid index name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
index_name = get_invalid_index_name
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: ""})
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
class TestIndexOperation(TestcaseBase):
|
2021-05-11 17:59:29 +08:00
|
|
|
""" Test case of index interface """
|
|
|
|
|
2021-11-10 15:07:37 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_create_with_different_indexes(self):
|
|
|
|
"""
|
|
|
|
target: test create index on one field, with two different type of index
|
|
|
|
method: create two different indexes
|
|
|
|
expected: only latest index can be created for a collection
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index)
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2021-11-10 15:07:37 +08:00
|
|
|
assert len(collection_w.indexes) == 1
|
|
|
|
assert collection_w.indexes[0].params["index_type"] == default_index["index_type"]
|
|
|
|
|
2021-05-25 19:09:31 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_collection_empty(self):
|
|
|
|
"""
|
|
|
|
target: test index with empty collection
|
|
|
|
method: Index on empty collection
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-06-23 16:50:07 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2021-05-25 19:09:31 +08:00
|
|
|
# TODO: assert index
|
2021-06-09 14:23:48 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.collection.indexes[0])
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-07-15 15:03:54 +08:00
|
|
|
@pytest.mark.parametrize("index_param", [default_index_params])
|
|
|
|
def test_index_params(self, index_param):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with all index type/params
|
|
|
|
method: input valid params
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-12-07 14:19:32 +08:00
|
|
|
data = cf.gen_default_list_data()
|
2021-06-23 16:50:07 +08:00
|
|
|
collection_w.insert(data=data)
|
2021-07-15 15:03:54 +08:00
|
|
|
index_params = index_param
|
2021-06-23 16:50:07 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, index_params)
|
|
|
|
# TODO: assert index
|
|
|
|
cf.assert_equal_index(index, collection_w.collection.indexes[0])
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
|
|
|
def test_index_params_flush(self):
|
|
|
|
"""
|
|
|
|
target: test index with all index type/params
|
|
|
|
method: input valid params
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-12-07 14:19:32 +08:00
|
|
|
data = cf.gen_default_list_data()
|
2021-06-23 16:50:07 +08:00
|
|
|
collection_w.insert(data=data)
|
2022-01-14 12:55:34 +08:00
|
|
|
# flush
|
|
|
|
collection_w.num_entities
|
2021-06-23 16:50:07 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2021-05-25 19:09:31 +08:00
|
|
|
# TODO: assert index
|
2021-06-09 14:23:48 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.collection.indexes[0])
|
2021-06-23 16:50:07 +08:00
|
|
|
assert collection_w.num_entities == ct.default_nb
|
2021-05-25 19:09:31 +08:00
|
|
|
|
2021-06-09 14:23:48 +08:00
|
|
|
# TODO: not support
|
2021-05-25 19:09:31 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_name_dup(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index with duplicate index name
|
|
|
|
method: create index with existed index name create by `collection.create_index`
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
2021-06-09 14:23:48 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-05-25 19:09:31 +08:00
|
|
|
index_name = ct.default_index_name
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
|
|
|
collection_w.collection.create_index(default_field_name, default_index_params, index_name=index_name)
|
2021-08-31 18:49:59 +08:00
|
|
|
self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params,
|
|
|
|
check_task=CheckTasks.err_res,
|
|
|
|
check_items={ct.err_code: 1, ct.err_msg: ""})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_field_names(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on one field, with two indexes
|
|
|
|
method: create index with two different indexes
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_fields(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on two fields, with the same name
|
|
|
|
method: create the same index name with two different fields
|
|
|
|
expected: exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_fields_B(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on two fields, with the different name
|
|
|
|
method: create the different index with two different fields
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_field_names_eq_maximum(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on one field, with the different names, num of the names equal to the maximum num supported
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create the different indexes
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
# TODO: server not supported
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='not supported')
|
|
|
|
def test_index_field_names_more_maximum(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index on one field, with the different names, num of the names more than the maximum num supported
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create the different indexes
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: exception raised
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_index_drop_index(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index.drop
|
|
|
|
method: create index by `index`, and then drop it
|
|
|
|
expected: no exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-06-23 16:50:07 +08:00
|
|
|
index, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2021-06-09 14:23:48 +08:00
|
|
|
cf.assert_equal_index(index, collection_w.collection.indexes[0])
|
2021-06-04 09:35:34 +08:00
|
|
|
self.index_wrap.drop()
|
2021-06-09 14:23:48 +08:00
|
|
|
assert len(collection_w.collection.indexes) == 0
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L1)
|
2021-08-31 18:49:59 +08:00
|
|
|
# TODO #7372
|
|
|
|
def test_index_drop_repeatedly(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index.drop
|
|
|
|
method: create index by `index`, and then drop it twice
|
|
|
|
expected: exception raised
|
|
|
|
"""
|
2021-08-31 18:49:59 +08:00
|
|
|
c_name = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=c_name)
|
2021-06-23 16:50:07 +08:00
|
|
|
_, _ = self.index_wrap.init_index(collection_w.collection, default_field_name, default_index_params)
|
2021-06-09 14:23:48 +08:00
|
|
|
self.index_wrap.drop()
|
|
|
|
self.index_wrap.drop(check_task=CheckTasks.err_res,
|
2021-08-31 18:49:59 +08:00
|
|
|
check_items={ct.err_code: 1, ct.err_msg: "Index doesn't exist"})
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
|
2021-06-05 10:25:34 +08:00
|
|
|
class TestIndexAdvanced(TestcaseBase):
|
2021-05-25 19:09:31 +08:00
|
|
|
""" Test case of index interface """
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_index_drop_multi_collections(self):
|
|
|
|
"""
|
|
|
|
target: test index.drop
|
|
|
|
method: create indexes by `index`, and then drop it, assert there is one index left
|
|
|
|
expected: exception raised
|
|
|
|
"""
|
|
|
|
c_name = cf.gen_unique_str(prefix)
|
|
|
|
c_name_2 = cf.gen_unique_str(prefix)
|
2021-06-09 14:23:48 +08:00
|
|
|
cw = self.init_collection_wrap(name=c_name)
|
|
|
|
cw2 = self.init_collection_wrap(name=c_name_2)
|
|
|
|
iw_2 = ApiIndexWrapper()
|
2021-06-23 16:50:07 +08:00
|
|
|
self.index_wrap.init_index(cw.collection, default_field_name, default_index_params)
|
|
|
|
index_2, _ = iw_2.init_index(cw2.collection, default_field_name, default_index_params)
|
2021-06-04 09:35:34 +08:00
|
|
|
self.index_wrap.drop()
|
2021-06-09 14:23:48 +08:00
|
|
|
assert cf.assert_equal_index(index_2, cw2.collection.indexes[0])
|
|
|
|
assert len(cw.collection.indexes) == 0
|
2021-05-25 19:09:31 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='TODO')
|
|
|
|
def test_index_drop_during_inserting(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index.drop during inserting
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create indexes by `index`, and then drop it during inserting entities, make sure async insert
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: no exception raised, insert success
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='TODO')
|
|
|
|
def test_index_drop_during_searching(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index.drop during searching
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create indexes by `index`, and then drop it during searching, make sure async search
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: no exception raised, search success
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2021-07-02 15:24:17 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='TODO')
|
|
|
|
def test_index_recovery_after_restart(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: test index still existed after server restart
|
2021-08-31 18:49:59 +08:00
|
|
|
method: create index by `index`, and then restart server, assert index existed
|
2021-05-25 19:09:31 +08:00
|
|
|
expected: index in collection.indexes
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
2021-07-02 15:24:17 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason='TODO')
|
|
|
|
def test_index_building_after_restart(self):
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
target: index can still build if not finished before server restart
|
|
|
|
method: create index by `index`, and then restart server, assert server is indexing
|
2021-09-09 17:18:00 +08:00
|
|
|
expected: index build finished after server restart
|
2021-05-25 19:09:31 +08:00
|
|
|
"""
|
|
|
|
pass
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following classes are copied from pymilvus test
|
|
|
|
******************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class TestIndexBase:
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_simple_index()
|
|
|
|
)
|
|
|
|
def get_simple_index(self, request, connect):
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(request.param)
|
2021-08-31 18:49:59 +08:00
|
|
|
# if str(connect._cmd("mode")) == "CPU":
|
|
|
|
# if request.param["index_type"] in index_cpu_not_support():
|
|
|
|
# pytest.skip("sq8h not support in CPU mode")
|
|
|
|
return copy.deepcopy(request.param)
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=[
|
|
|
|
1,
|
|
|
|
10,
|
|
|
|
1111
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def get_nq(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `create_index` function
|
|
|
|
******************************************************************
|
|
|
|
"""
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-04 19:37:28 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
2022-01-04 19:37:28 +08:00
|
|
|
connect.insert(collection, default_entities)
|
2021-08-31 18:49:59 +08:00
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip(reason="Repeat with test_index_field_name_not_existed")
|
|
|
|
def test_create_index_on_field_not_existed(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index on field not existed
|
|
|
|
expected: error raised
|
|
|
|
"""
|
|
|
|
tmp_field_name = gen_unique_str()
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.create_index(collection, tmp_field_name, get_simple_index)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_on_field(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index on other field
|
|
|
|
expected: error raised
|
|
|
|
"""
|
|
|
|
tmp_field_name = "int64"
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.create_index(collection, tmp_field_name, get_simple_index)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_no_vectors(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_partition(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
connect.create_partition(collection, default_tag)
|
|
|
|
result = connect.insert(collection, default_entities, partition_name=default_tag)
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_partition_flush(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
connect.create_partition(collection, default_tag)
|
|
|
|
result = connect.insert(collection, default_entities, partition_name=default_tag)
|
|
|
|
connect.flush([collection])
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_without_connect(self, dis_connect, collection):
|
|
|
|
"""
|
|
|
|
target: test create index without connection
|
|
|
|
method: create collection and add entities in it, check if added successfully
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
with pytest.raises(Exception) as e:
|
2021-10-01 06:19:35 +08:00
|
|
|
dis_connect.create_index(collection, field_name, default_index)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_search_with_query_vectors(self, connect, collection, get_simple_index, get_nq):
|
|
|
|
"""
|
|
|
|
target: test create index interface, search with more query vectors
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.flush([collection])
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(connect.describe_index(collection, ""))
|
2021-08-31 18:49:59 +08:00
|
|
|
nq = get_nq
|
|
|
|
index_type = get_simple_index["index_type"]
|
|
|
|
search_param = get_search_param(index_type)
|
2021-12-07 14:19:32 +08:00
|
|
|
params, _ = gen_search_vectors_params(field_name, default_entities, default_top_k, nq,
|
|
|
|
search_params=search_param)
|
2021-08-31 18:49:59 +08:00
|
|
|
connect.load_collection(collection)
|
2021-10-11 15:32:55 +08:00
|
|
|
res = connect.search(collection, **params)
|
2021-08-31 18:49:59 +08:00
|
|
|
assert len(res) == nq
|
|
|
|
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_multithread(self, connect, collection, args):
|
|
|
|
"""
|
|
|
|
target: test create index interface with multiprocess
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
connect.insert(collection, default_entities)
|
|
|
|
|
|
|
|
def build(connect):
|
|
|
|
connect.create_index(collection, field_name, default_index)
|
|
|
|
if default_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(default_index, field_name)
|
|
|
|
assert index == default_index
|
|
|
|
|
|
|
|
threads_num = 8
|
|
|
|
threads = []
|
|
|
|
for i in range(threads_num):
|
|
|
|
m = get_milvus(host=args["ip"], port=args["port"], handler=args["handler"])
|
|
|
|
t = MyThread(target=build, args=(m,))
|
|
|
|
threads.append(t)
|
|
|
|
t.start()
|
|
|
|
time.sleep(0.2)
|
|
|
|
for t in threads:
|
|
|
|
t.join()
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_collection_not_existed(self, connect):
|
|
|
|
"""
|
|
|
|
target: test create index interface when collection name not existed
|
2021-10-30 11:34:42 +08:00
|
|
|
method: create collection and add entities in it, create index,
|
|
|
|
make sure the collection name not in index
|
2021-08-31 18:49:59 +08:00
|
|
|
expected: create index failed
|
|
|
|
"""
|
|
|
|
collection_name = gen_unique_str(uid)
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.create_index(collection_name, field_name, default_index)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_insert_flush(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index
|
|
|
|
method: create collection and create index, add entities in it
|
|
|
|
expected: create index ok, and count correct
|
|
|
|
"""
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.flush([collection])
|
|
|
|
stats = connect.get_collection_stats(collection)
|
|
|
|
assert stats["row_count"] == default_nb
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_same_index_repeatedly(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the same create_index params
|
|
|
|
method: create index after index have been built
|
|
|
|
expected: return code success, and search ok
|
|
|
|
"""
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_different_index_repeatedly(self, connect, collection):
|
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the different create_index params
|
|
|
|
method: create another index with different index_params after index have been built
|
|
|
|
expected: return code 0, and describe index result equals with the second index params
|
|
|
|
"""
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.flush([collection])
|
2021-12-07 14:19:32 +08:00
|
|
|
indexs = [default_index, {"metric_type": "L2", "index_type": "FLAT", "params": {"nlist": 1024}}]
|
2021-08-31 18:49:59 +08:00
|
|
|
for index in indexs:
|
|
|
|
connect.create_index(collection, field_name, index)
|
|
|
|
connect.release_collection(collection)
|
|
|
|
connect.load_collection(collection)
|
|
|
|
index = connect.describe_index(collection, "")
|
2021-12-07 14:19:32 +08:00
|
|
|
assert not index # FLAT is the last index_type, drop all indexes in server
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_different_index_repeatedly_B(self, connect, collection):
|
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the different create_index params
|
|
|
|
method: create another index with different index_params after index have been built
|
|
|
|
expected: return code 0, and describe index result equals with the second index params
|
|
|
|
"""
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.flush([collection])
|
|
|
|
indexs = [default_index, {"metric_type": "L2", "index_type": "IVF_SQ8", "params": {"nlist": 1024}}]
|
|
|
|
for index in indexs:
|
|
|
|
connect.create_index(collection, field_name, index)
|
|
|
|
connect.release_collection(collection)
|
|
|
|
connect.load_collection(collection)
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(indexs[-1], field_name)
|
|
|
|
assert index == indexs[-1]
|
|
|
|
# assert not index # FLAT is the last index_type, drop all indexes in server
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_ip(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_no_vectors_ip(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_partition_ip(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
connect.create_partition(collection, default_tag)
|
|
|
|
result = connect.insert(collection, default_entities, partition_name=default_tag)
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_partition_flush_ip(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
connect.create_partition(collection, default_tag)
|
|
|
|
result = connect.insert(collection, default_entities, partition_name=default_tag)
|
|
|
|
connect.flush([collection])
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
if get_simple_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(get_simple_index, field_name)
|
|
|
|
assert index == get_simple_index
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_search_with_query_vectors_ip(self, connect, collection, get_simple_index, get_nq):
|
|
|
|
"""
|
|
|
|
target: test create index interface, search with more query vectors
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
metric_type = "IP"
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.flush([collection])
|
|
|
|
get_simple_index["metric_type"] = metric_type
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
connect.load_collection(collection)
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(connect.describe_index(collection, ""))
|
2021-08-31 18:49:59 +08:00
|
|
|
nq = get_nq
|
|
|
|
index_type = get_simple_index["index_type"]
|
|
|
|
search_param = get_search_param(index_type)
|
2021-10-11 15:32:55 +08:00
|
|
|
params, _ = gen_search_vectors_params(field_name, default_entities, default_top_k, nq,
|
|
|
|
metric_type=metric_type, search_params=search_param)
|
|
|
|
res = connect.search(collection, **params)
|
2021-08-31 18:49:59 +08:00
|
|
|
assert len(res) == nq
|
|
|
|
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_multithread_ip(self, connect, collection, args):
|
|
|
|
"""
|
|
|
|
target: test create index interface with multiprocess
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
connect.insert(collection, default_entities)
|
|
|
|
|
|
|
|
def build(connect):
|
|
|
|
default_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, default_index)
|
|
|
|
if default_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(default_index, field_name)
|
|
|
|
assert index == default_index
|
|
|
|
|
|
|
|
threads_num = 8
|
|
|
|
threads = []
|
|
|
|
for i in range(threads_num):
|
|
|
|
m = get_milvus(host=args["ip"], port=args["port"], handler=args["handler"])
|
|
|
|
t = MyThread(target=build, args=(m,))
|
|
|
|
threads.append(t)
|
|
|
|
t.start()
|
|
|
|
time.sleep(0.2)
|
|
|
|
for t in threads:
|
|
|
|
t.join()
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_collection_not_existed_ip(self, connect, collection):
|
|
|
|
"""
|
|
|
|
target: test create index interface when collection name not existed
|
2021-10-30 11:34:42 +08:00
|
|
|
method: create collection and add entities in it, create index,
|
|
|
|
make sure the collection name not in index
|
2021-08-31 18:49:59 +08:00
|
|
|
expected: return code not equals to 0, create index failed
|
|
|
|
"""
|
|
|
|
collection_name = gen_unique_str(uid)
|
|
|
|
default_index["metric_type"] = "IP"
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.create_index(collection_name, field_name, default_index)
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_no_vectors_insert_ip(self, connect, collection):
|
|
|
|
"""
|
2021-12-21 21:17:44 +08:00
|
|
|
target: test create index interface when there is no vectors in collection,
|
|
|
|
and does not affect the subsequent process
|
|
|
|
method: create collection and add no vectors in it, and then create index,
|
|
|
|
add entities in it
|
2021-08-31 18:49:59 +08:00
|
|
|
expected: return code equals to 0
|
|
|
|
"""
|
|
|
|
default_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, default_index)
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.flush([collection])
|
|
|
|
stats = connect.get_collection_stats(collection)
|
|
|
|
assert stats["row_count"] == default_nb
|
|
|
|
if default_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(default_index, field_name)
|
|
|
|
assert index == default_index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_same_index_repeatedly_ip(self, connect, collection):
|
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the same create_index params
|
|
|
|
method: create index after index have been built
|
|
|
|
expected: return code success, and search ok
|
|
|
|
"""
|
|
|
|
default_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, default_index)
|
|
|
|
connect.create_index(collection, field_name, default_index)
|
|
|
|
if default_index["index_type"] != "FLAT":
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(default_index, field_name)
|
|
|
|
assert index == default_index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_different_index_repeatedly_ip(self, connect, collection):
|
|
|
|
"""
|
|
|
|
target: check if index can be created repeatedly, with the different create_index params
|
|
|
|
method: create another index with different index_params after index have been built
|
|
|
|
expected: return code 0, and describe index result equals with the second index params
|
|
|
|
"""
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.flush([collection])
|
|
|
|
connect.load_collection(collection)
|
|
|
|
stats = connect.get_collection_stats(collection)
|
|
|
|
assert stats["row_count"] == default_nb
|
|
|
|
default_index["metric_type"] = "IP"
|
|
|
|
indexs = [default_index, {"index_type": "FLAT", "params": {"nlist": 1024}, "metric_type": "IP"}]
|
|
|
|
for index in indexs:
|
|
|
|
connect.create_index(collection, field_name, index)
|
|
|
|
connect.release_collection(collection)
|
|
|
|
connect.load_collection(collection)
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
# assert index == indexs[-1]
|
|
|
|
assert not index
|
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `drop_index` function
|
|
|
|
******************************************************************
|
|
|
|
"""
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_drop_index(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test drop index interface
|
|
|
|
method: create collection and add entities in it, create index, call drop index
|
|
|
|
expected: return code 0, and default index param
|
|
|
|
"""
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
assert not index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
# TODO #7372
|
|
|
|
def test_drop_index_repeatedly(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test drop index repeatedly
|
|
|
|
method: create index, call drop index, and drop again
|
|
|
|
expected: return code 0
|
|
|
|
"""
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
assert not index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index_without_connect(self, dis_connect, collection):
|
|
|
|
"""
|
|
|
|
target: test drop index without connection
|
|
|
|
method: drop index, and check if drop successfully
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
dis_connect.drop_index(collection, field_name)
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_drop_index_collection_not_existed(self, connect):
|
|
|
|
"""
|
|
|
|
target: test drop index interface when collection name not existed
|
2021-10-30 11:34:42 +08:00
|
|
|
method: create collection and add entities in it, create index,
|
|
|
|
make sure the collection name not in index, and then drop it
|
2021-08-31 18:49:59 +08:00
|
|
|
expected: return code not equals to 0, drop index failed
|
|
|
|
"""
|
|
|
|
collection_name = gen_unique_str(uid)
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.drop_index(collection_name, field_name)
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_drop_index_collection_not_create(self, connect, collection):
|
|
|
|
"""
|
|
|
|
target: test drop index interface when index not created
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return code not equals to 0, drop index failed
|
|
|
|
"""
|
|
|
|
# no create index
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_drop_index_repeatedly(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create / drop index repeatedly, use the same index params
|
|
|
|
method: create index, drop index, four times
|
|
|
|
expected: return code 0
|
|
|
|
"""
|
|
|
|
for i in range(4):
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index_ip(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test drop index interface
|
|
|
|
method: create collection and add entities in it, create index, call drop index
|
|
|
|
expected: return code 0, and default index param
|
|
|
|
"""
|
|
|
|
# result = connect.insert(collection, entities)
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
assert not index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index_repeatedly_ip(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test drop index repeatedly
|
|
|
|
method: create index, call drop index, and drop again
|
|
|
|
expected: return code 0
|
|
|
|
"""
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
assert not index
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index_without_connect_ip(self, dis_connect, collection):
|
|
|
|
"""
|
|
|
|
target: test drop index without connection
|
|
|
|
method: drop index, and check if drop successfully
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
dis_connect.drop_index(collection, field_name)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index_collection_not_create_ip(self, connect, collection):
|
|
|
|
"""
|
|
|
|
target: test drop index interface when index not created
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return code not equals to 0, drop index failed
|
|
|
|
"""
|
|
|
|
# result = connect.insert(collection, entities)
|
|
|
|
# no create index
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_drop_index_repeatedly_ip(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create / drop index repeatedly, use the same index params
|
|
|
|
method: create index, drop index, four times
|
|
|
|
expected: return code 0
|
|
|
|
"""
|
|
|
|
get_simple_index["metric_type"] = "IP"
|
|
|
|
for i in range(4):
|
|
|
|
connect.create_index(collection, field_name, get_simple_index)
|
|
|
|
connect.drop_index(collection, field_name)
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_PQ_without_nbits(self, connect, collection):
|
2021-09-17 14:05:54 +08:00
|
|
|
"""
|
|
|
|
target: test create PQ index
|
|
|
|
method: create PQ index without nbits
|
|
|
|
expected: create successfully
|
|
|
|
"""
|
2021-08-31 18:49:59 +08:00
|
|
|
PQ_index = {"index_type": "IVF_PQ", "params": {"nlist": 128, "m": 16}, "metric_type": "L2"}
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.create_index(collection, field_name, PQ_index)
|
|
|
|
index = connect.describe_index(collection, "")
|
|
|
|
create_target_index(PQ_index, field_name)
|
|
|
|
assert index == PQ_index
|
|
|
|
|
|
|
|
|
|
|
|
class TestIndexBinary:
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_simple_index()
|
|
|
|
)
|
|
|
|
def get_simple_index(self, request, connect):
|
|
|
|
# if str(connect._cmd("mode")) == "CPU":
|
|
|
|
# if request.param["index_type"] in index_cpu_not_support():
|
|
|
|
# pytest.skip("sq8h not support in CPU mode")
|
|
|
|
return copy.deepcopy(request.param)
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_binary_index()
|
|
|
|
)
|
|
|
|
def get_jaccard_index(self, request, connect):
|
|
|
|
if request.param["index_type"] in binary_support():
|
|
|
|
request.param["metric_type"] = "JACCARD"
|
|
|
|
return request.param
|
|
|
|
else:
|
|
|
|
pytest.skip("Skip index")
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_binary_index()
|
|
|
|
)
|
|
|
|
def get_l2_index(self, request, connect):
|
|
|
|
request.param["metric_type"] = "L2"
|
|
|
|
return request.param
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=[
|
|
|
|
1,
|
|
|
|
10,
|
|
|
|
1111
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def get_nq(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `create_index` function
|
|
|
|
******************************************************************
|
|
|
|
"""
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index(self, connect, binary_collection, get_jaccard_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
result = connect.insert(binary_collection, default_binary_entities)
|
|
|
|
connect.create_index(binary_collection, binary_field_name, get_jaccard_index)
|
|
|
|
binary_index = connect.describe_index(binary_collection, "")
|
|
|
|
create_target_index(get_jaccard_index, binary_field_name)
|
|
|
|
assert binary_index == get_jaccard_index
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_partition(self, connect, binary_collection, get_jaccard_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection, create partition, and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
connect.create_partition(binary_collection, default_tag)
|
|
|
|
result = connect.insert(binary_collection, default_binary_entities, partition_name=default_tag)
|
|
|
|
connect.create_index(binary_collection, binary_field_name, get_jaccard_index)
|
|
|
|
binary_index = connect.describe_index(binary_collection, "")
|
|
|
|
create_target_index(get_jaccard_index, binary_field_name)
|
|
|
|
assert binary_index == get_jaccard_index
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_search_with_query_vectors(self, connect, binary_collection, get_jaccard_index, get_nq):
|
|
|
|
"""
|
|
|
|
target: test create index interface, search with more query vectors
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
nq = get_nq
|
|
|
|
result = connect.insert(binary_collection, default_binary_entities)
|
|
|
|
connect.flush([binary_collection])
|
|
|
|
connect.create_index(binary_collection, binary_field_name, get_jaccard_index)
|
|
|
|
connect.load_collection(binary_collection)
|
|
|
|
search_param = get_search_param(get_jaccard_index["index_type"], metric_type="JACCARD")
|
2021-10-11 15:32:55 +08:00
|
|
|
params, _ = gen_search_vectors_params(binary_field_name, default_binary_entities, default_top_k, nq,
|
|
|
|
search_params=search_param, metric_type="JACCARD")
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(params)
|
2021-10-11 15:32:55 +08:00
|
|
|
res = connect.search(binary_collection, **params)
|
2021-08-31 18:49:59 +08:00
|
|
|
assert len(res) == nq
|
|
|
|
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_invalid_metric_type_binary(self, connect, binary_collection, get_l2_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface with invalid metric type
|
2021-09-22 16:35:59 +08:00
|
|
|
method: add entities into binary collection, flush, create index with L2 metric type.
|
2021-08-31 18:49:59 +08:00
|
|
|
expected: return create_index failure
|
|
|
|
"""
|
|
|
|
# insert 6000 vectors
|
|
|
|
result = connect.insert(binary_collection, default_binary_entities)
|
|
|
|
connect.flush([binary_collection])
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
res = connect.create_index(binary_collection, binary_field_name, get_l2_index)
|
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `describe_index` function
|
|
|
|
***************************************************************
|
|
|
|
"""
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.skip("repeat with test_create_index binary")
|
|
|
|
def _test_get_index_info(self, connect, binary_collection, get_jaccard_index):
|
|
|
|
"""
|
|
|
|
target: test describe index interface
|
|
|
|
method: create collection and add entities in it, create index, call describe index
|
|
|
|
expected: return code 0, and index instructure
|
|
|
|
"""
|
|
|
|
result = connect.insert(binary_collection, default_binary_entities)
|
|
|
|
connect.flush([binary_collection])
|
|
|
|
connect.create_index(binary_collection, binary_field_name, get_jaccard_index)
|
|
|
|
stats = connect.get_collection_stats(binary_collection)
|
|
|
|
assert stats["row_count"] == default_nb
|
|
|
|
for partition in stats["partitions"]:
|
|
|
|
segments = partition["segments"]
|
|
|
|
if segments:
|
|
|
|
for segment in segments:
|
|
|
|
for file in segment["files"]:
|
|
|
|
if "index_type" in file:
|
|
|
|
assert file["index_type"] == get_jaccard_index["index_type"]
|
|
|
|
|
|
|
|
@pytest.mark.skip("repeat with test_create_index_partition binary")
|
|
|
|
def _test_get_index_info_partition(self, connect, binary_collection, get_jaccard_index):
|
|
|
|
"""
|
|
|
|
target: test describe index interface
|
|
|
|
method: create collection, create partition and add entities in it, create index, call describe index
|
|
|
|
expected: return code 0, and index instructure
|
|
|
|
"""
|
|
|
|
connect.create_partition(binary_collection, default_tag)
|
|
|
|
result = connect.insert(binary_collection, default_binary_entities, partition_name=default_tag)
|
|
|
|
connect.flush([binary_collection])
|
|
|
|
connect.create_index(binary_collection, binary_field_name, get_jaccard_index)
|
|
|
|
stats = connect.get_collection_stats(binary_collection)
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(stats)
|
2021-08-31 18:49:59 +08:00
|
|
|
assert stats["row_count"] == default_nb
|
|
|
|
assert len(stats["partitions"]) == 2
|
|
|
|
for partition in stats["partitions"]:
|
|
|
|
segments = partition["segments"]
|
|
|
|
if segments:
|
|
|
|
for segment in segments:
|
|
|
|
for file in segment["files"]:
|
|
|
|
if "index_type" in file:
|
|
|
|
assert file["index_type"] == get_jaccard_index["index_type"]
|
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `drop_index` function
|
|
|
|
******************************************************************
|
|
|
|
"""
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2021-08-31 18:49:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index(self, connect, binary_collection, get_jaccard_index):
|
|
|
|
"""
|
|
|
|
target: test drop index interface
|
|
|
|
method: create collection and add entities in it, create index, call drop index
|
|
|
|
expected: return code 0, and default index param
|
|
|
|
"""
|
|
|
|
connect.create_index(binary_collection, binary_field_name, get_jaccard_index)
|
|
|
|
stats = connect.get_collection_stats(binary_collection)
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(stats)
|
2021-08-31 18:49:59 +08:00
|
|
|
connect.drop_index(binary_collection, binary_field_name)
|
|
|
|
binary_index = connect.describe_index(binary_collection, "")
|
|
|
|
assert not binary_index
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_drop_index_partition(self, connect, binary_collection, get_jaccard_index):
|
|
|
|
"""
|
|
|
|
target: test drop index interface
|
2021-10-29 21:46:51 +08:00
|
|
|
method: create collection, create partition and add entities in it,
|
|
|
|
create index on collection, call drop collection index
|
2021-08-31 18:49:59 +08:00
|
|
|
expected: return code 0, and default index param
|
|
|
|
"""
|
|
|
|
connect.create_partition(binary_collection, default_tag)
|
|
|
|
result = connect.insert(binary_collection, default_binary_entities, partition_name=default_tag)
|
|
|
|
connect.flush([binary_collection])
|
|
|
|
connect.create_index(binary_collection, binary_field_name, get_jaccard_index)
|
|
|
|
connect.drop_index(binary_collection, binary_field_name)
|
|
|
|
binary_index = connect.describe_index(binary_collection, "")
|
|
|
|
assert not binary_index
|
|
|
|
|
|
|
|
|
|
|
|
class TestIndexInvalid(object):
|
|
|
|
"""
|
|
|
|
Test create / describe / drop index interfaces with invalid collection names
|
|
|
|
"""
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_invalid_strs()
|
|
|
|
)
|
|
|
|
def get_collection_name(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_with_invalid_collection_name(self, connect, get_collection_name):
|
2021-09-16 17:37:49 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface for invalid scenario
|
|
|
|
method: create index with invalid collection name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2021-08-31 18:49:59 +08:00
|
|
|
collection_name = get_collection_name
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.create_index(collection_name, field_name, default_index)
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_drop_index_with_invalid_collection_name(self, connect, get_collection_name):
|
2021-09-16 18:55:49 +08:00
|
|
|
"""
|
|
|
|
target: test drop index interface for invalid scenario
|
|
|
|
method: drop index with invalid collection name
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2021-08-31 18:49:59 +08:00
|
|
|
collection_name = get_collection_name
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.drop_index(collection_name)
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_invalid_index()
|
|
|
|
)
|
|
|
|
def get_index(self, request):
|
|
|
|
yield request.param
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_with_invalid_index_params(self, connect, collection, get_index):
|
2021-09-18 11:01:50 +08:00
|
|
|
"""
|
|
|
|
target: test create index interface for invalid scenario
|
|
|
|
method: create index with invalid index params
|
|
|
|
expected: raise exception
|
|
|
|
"""
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(get_index)
|
2021-08-31 18:49:59 +08:00
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
connect.create_index(collection, field_name, get_index)
|
|
|
|
|
|
|
|
|
|
|
|
class TestIndexAsync:
|
|
|
|
@pytest.fixture(scope="function", autouse=True)
|
|
|
|
def skip_http_check(self, args):
|
|
|
|
if args["handler"] == "HTTP":
|
|
|
|
pytest.skip("skip in http mode")
|
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `create_index` function
|
|
|
|
******************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
@pytest.fixture(
|
|
|
|
scope="function",
|
|
|
|
params=gen_simple_index()
|
|
|
|
)
|
|
|
|
def get_simple_index(self, request, connect):
|
|
|
|
# if str(connect._cmd("mode")) == "CPU":
|
|
|
|
# if request.param["index_type"] in index_cpu_not_support():
|
|
|
|
# pytest.skip("sq8h not support in CPU mode")
|
|
|
|
return copy.deepcopy(request.param)
|
|
|
|
|
|
|
|
def check_result(self, res):
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info("In callback check search result")
|
|
|
|
log.info(res)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
******************************************************************
|
|
|
|
The following cases are used to test `create_index` function
|
|
|
|
******************************************************************
|
|
|
|
"""
|
2021-12-07 14:19:32 +08:00
|
|
|
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
result = connect.insert(collection, default_entities)
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info("start index")
|
2021-08-31 18:49:59 +08:00
|
|
|
future = connect.create_index(collection, field_name, get_simple_index, _async=True)
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info("before result")
|
2021-08-31 18:49:59 +08:00
|
|
|
res = future.result()
|
|
|
|
# TODO:
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(res)
|
2021-08-31 18:49:59 +08:00
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_drop(self, connect, collection):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
result = connect.insert(collection, default_entities)
|
|
|
|
connect.create_index(collection, field_name, default_index, _async=True)
|
|
|
|
connect.drop_collection(collection)
|
2021-11-22 16:01:14 +08:00
|
|
|
with pytest.raises(Exception, match=f'DescribeIndex failed: collection {collection} not found'):
|
2021-08-31 18:49:59 +08:00
|
|
|
connect.describe_index(collection, "")
|
|
|
|
|
|
|
|
@pytest.mark.tags(CaseLabel.L2)
|
|
|
|
def test_create_index_with_invalid_collection_name(self, connect):
|
|
|
|
collection_name = " "
|
|
|
|
with pytest.raises(Exception) as e:
|
|
|
|
future = connect.create_index(collection_name, field_name, default_index, _async=True)
|
|
|
|
res = future.result()
|
|
|
|
|
2021-09-01 19:43:59 +08:00
|
|
|
@pytest.mark.tags(CaseLabel.L0)
|
2022-01-06 09:35:30 +08:00
|
|
|
# @pytest.mark.timeout(BUILD_TIMEOUT)
|
2021-08-31 18:49:59 +08:00
|
|
|
def test_create_index_callback(self, connect, collection, get_simple_index):
|
|
|
|
"""
|
|
|
|
target: test create index interface
|
|
|
|
method: create collection and add entities in it, create index
|
|
|
|
expected: return search success
|
|
|
|
"""
|
|
|
|
result = connect.insert(collection, default_entities)
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info("start index")
|
2021-08-31 18:49:59 +08:00
|
|
|
future = connect.create_index(collection, field_name, get_simple_index, _async=True,
|
|
|
|
_callback=self.check_result)
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info("before result")
|
2021-08-31 18:49:59 +08:00
|
|
|
res = future.result()
|
|
|
|
# TODO:
|
2021-12-17 18:50:12 +08:00
|
|
|
log.info(res)
|