2021-05-11 17:59:29 +08:00
|
|
|
import pytest
|
|
|
|
import sys
|
2021-06-10 19:19:49 +08:00
|
|
|
from pymilvus_orm.default_config import DefaultConfig
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
sys.path.append("..")
|
2021-06-04 09:35:34 +08:00
|
|
|
from base.connections_wrapper import ApiConnectionsWrapper
|
|
|
|
from base.collection_wrapper import ApiCollectionWrapper
|
|
|
|
from base.partition_wrapper import ApiPartitionWrapper
|
|
|
|
from base.index_wrapper import ApiIndexWrapper
|
|
|
|
from base.utility_wrapper import ApiUtilityWrapper
|
2021-06-09 09:21:35 +08:00
|
|
|
from base.schema_wrapper import ApiCollectionSchemaWrapper, ApiFieldSchemaWrapper
|
2021-05-20 11:03:45 +08:00
|
|
|
from utils.util_log import test_log as log
|
|
|
|
from common import common_func as cf
|
2021-05-27 10:26:35 +08:00
|
|
|
from common import common_type as ct
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ParamInfo:
|
|
|
|
def __init__(self):
|
2021-05-13 12:17:15 +08:00
|
|
|
self.param_host = ""
|
2021-05-11 17:59:29 +08:00
|
|
|
self.param_port = ""
|
|
|
|
self.param_handler = ""
|
|
|
|
|
2021-05-13 12:17:15 +08:00
|
|
|
def prepare_param_info(self, host, port, handler):
|
|
|
|
self.param_host = host
|
2021-05-11 17:59:29 +08:00
|
|
|
self.param_port = port
|
|
|
|
self.param_handler = handler
|
|
|
|
|
|
|
|
|
|
|
|
param_info = ParamInfo()
|
|
|
|
|
|
|
|
|
|
|
|
class Base:
|
|
|
|
""" Initialize class object """
|
2021-06-04 09:35:34 +08:00
|
|
|
connection_wrap = None
|
|
|
|
collection_wrap = None
|
|
|
|
partition_wrap = None
|
|
|
|
index_wrap = None
|
|
|
|
utility_wrap = None
|
2021-06-09 09:21:35 +08:00
|
|
|
collection_schema_wrap = None
|
|
|
|
field_schema_wrap = None
|
2021-06-28 15:54:11 +08:00
|
|
|
collection_object_list = []
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
def setup_class(self):
|
|
|
|
log.info("[setup_class] Start setup class...")
|
|
|
|
|
|
|
|
def teardown_class(self):
|
2021-07-02 15:24:17 +08:00
|
|
|
log.info("[teardown_class] Start teardown class...")
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-07-12 13:11:53 +08:00
|
|
|
def setup_method(self, method):
|
2021-06-02 19:21:33 +08:00
|
|
|
log.info(("*" * 35) + " setup " + ("*" * 35))
|
2021-07-15 15:03:54 +08:00
|
|
|
log.info("[setup_method] Start setup test case %s." % method.__name__)
|
2021-06-04 09:35:34 +08:00
|
|
|
self.connection_wrap = ApiConnectionsWrapper()
|
2021-07-02 15:24:17 +08:00
|
|
|
self.utility_wrap = ApiUtilityWrapper()
|
2021-06-04 09:35:34 +08:00
|
|
|
self.collection_wrap = ApiCollectionWrapper()
|
|
|
|
self.partition_wrap = ApiPartitionWrapper()
|
|
|
|
self.index_wrap = ApiIndexWrapper()
|
2021-06-09 09:21:35 +08:00
|
|
|
self.collection_schema_wrap = ApiCollectionSchemaWrapper()
|
|
|
|
self.field_schema_wrap = ApiFieldSchemaWrapper()
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-07-12 13:11:53 +08:00
|
|
|
def teardown_method(self, method):
|
2021-06-04 09:35:34 +08:00
|
|
|
log.info(("*" * 35) + " teardown " + ("*" * 35))
|
2021-07-12 13:11:53 +08:00
|
|
|
log.info("[teardown_method] Start teardown test case %s..." % method.__name__)
|
2021-06-04 09:35:34 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
""" Drop collection before disconnect """
|
2021-06-28 15:54:11 +08:00
|
|
|
if self.connection_wrap.get_connection(alias=DefaultConfig.DEFAULT_USING)[0] is None:
|
|
|
|
self.connection_wrap.connect(alias=DefaultConfig.DEFAULT_USING, host=param_info.param_host,
|
|
|
|
port=param_info.param_port)
|
2021-07-05 19:14:03 +08:00
|
|
|
|
2021-07-02 15:24:17 +08:00
|
|
|
if self.collection_wrap.collection is not None:
|
2021-07-05 19:14:03 +08:00
|
|
|
self.collection_wrap.drop(check_task=ct.CheckTasks.check_nothing)
|
2021-06-28 15:54:11 +08:00
|
|
|
|
2021-07-15 15:03:54 +08:00
|
|
|
collection_list = self.utility_wrap.list_collections()[0]
|
2021-06-28 15:54:11 +08:00
|
|
|
for collection_object in self.collection_object_list:
|
2021-07-15 15:03:54 +08:00
|
|
|
if collection_object.collection is not None and collection_object.name in collection_list:
|
2021-07-05 19:14:03 +08:00
|
|
|
collection_object.drop(check_task=ct.CheckTasks.check_nothing)
|
2021-07-02 15:24:17 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
except Exception as e:
|
2021-07-02 15:24:17 +08:00
|
|
|
log.debug(str(e))
|
2021-06-04 09:35:34 +08:00
|
|
|
|
2021-06-01 18:49:31 +08:00
|
|
|
try:
|
|
|
|
""" Delete connection and reset configuration"""
|
2021-06-04 09:35:34 +08:00
|
|
|
res = self.connection_wrap.list_connections()
|
2021-06-02 19:21:33 +08:00
|
|
|
for i in res[0]:
|
2021-06-04 09:35:34 +08:00
|
|
|
self.connection_wrap.remove_connection(i[0])
|
2021-06-10 19:19:49 +08:00
|
|
|
|
|
|
|
# because the connection is in singleton mode, it needs to be restored to the original state after teardown
|
|
|
|
self.connection_wrap.add_connection(default={"host": DefaultConfig.DEFAULT_HOST,
|
|
|
|
"port": DefaultConfig.DEFAULT_PORT})
|
2021-06-01 18:49:31 +08:00
|
|
|
except Exception as e:
|
2021-07-02 15:24:17 +08:00
|
|
|
log.debug(str(e))
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
2021-06-05 10:25:34 +08:00
|
|
|
class TestcaseBase(Base):
|
2021-05-11 17:59:29 +08:00
|
|
|
"""
|
|
|
|
Additional methods;
|
|
|
|
Public methods that can be used to add cases.
|
|
|
|
"""
|
|
|
|
|
2021-05-13 12:17:15 +08:00
|
|
|
def _connect(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
""" Add an connection and create the connect """
|
2021-06-25 10:46:09 +08:00
|
|
|
res, is_succ = self.connection_wrap.connect(alias=DefaultConfig.DEFAULT_USING, host=param_info.param_host,
|
|
|
|
port=param_info.param_port)
|
2021-05-13 12:17:15 +08:00
|
|
|
return res
|
2021-06-08 10:35:35 +08:00
|
|
|
|
2021-06-25 10:46:09 +08:00
|
|
|
def init_collection_wrap(self, name=None, schema=None, check_task=None, check_items=None, **kwargs):
|
2021-06-07 12:15:35 +08:00
|
|
|
name = cf.gen_unique_str('coll_') if name is None else name
|
|
|
|
schema = cf.gen_default_collection_schema() if schema is None else schema
|
2021-06-25 10:46:09 +08:00
|
|
|
if self.connection_wrap.get_connection(alias=DefaultConfig.DEFAULT_USING)[0] is None:
|
2021-06-07 12:15:35 +08:00
|
|
|
self._connect()
|
|
|
|
collection_w = ApiCollectionWrapper()
|
2021-06-25 10:46:09 +08:00
|
|
|
collection_w.init_collection(name=name, schema=schema, check_task=check_task, check_items=check_items, **kwargs)
|
2021-07-02 15:24:17 +08:00
|
|
|
self.collection_object_list.append(collection_w)
|
2021-06-07 12:15:35 +08:00
|
|
|
return collection_w
|
|
|
|
|
2021-07-22 14:42:15 +08:00
|
|
|
def init_multi_fields_collection_wrap(self, name=cf.gen_unique_str()):
|
|
|
|
vec_fields = [cf.gen_float_vec_field(ct.another_float_vec_field_name)]
|
|
|
|
schema = cf.gen_schema_multi_vector_fields(vec_fields)
|
|
|
|
collection_w = self.init_collection_wrap(name=name, schema=schema)
|
|
|
|
df = cf.gen_dataframe_multi_vec_fields(vec_fields=vec_fields)
|
|
|
|
collection_w.insert(df)
|
|
|
|
assert collection_w.num_entities == ct.default_nb
|
|
|
|
return collection_w, df
|
|
|
|
|
2021-06-08 10:35:35 +08:00
|
|
|
def init_partition_wrap(self, collection_wrap=None, name=None, description=None,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_task=None, check_items=None, **kwargs):
|
2021-05-27 10:26:35 +08:00
|
|
|
name = cf.gen_unique_str("partition_") if name is None else name
|
2021-06-07 12:15:35 +08:00
|
|
|
description = cf.gen_unique_str("partition_des_") if description is None else description
|
|
|
|
collection_wrap = self.init_collection_wrap() if collection_wrap is None else collection_wrap
|
|
|
|
partition_wrap = ApiPartitionWrapper()
|
2021-06-07 16:41:35 +08:00
|
|
|
partition_wrap.init_partition(collection_wrap.collection, name, description,
|
|
|
|
check_task=check_task, check_items=check_items,
|
|
|
|
**kwargs)
|
2021-06-07 12:15:35 +08:00
|
|
|
return partition_wrap
|
2021-06-10 11:46:49 +08:00
|
|
|
|
2021-07-22 11:49:44 +08:00
|
|
|
def init_collection_general(self, prefix, insert_data=False, nb=ct.default_nb,
|
|
|
|
partition_num=0, is_binary=False, is_all_data_type=False,
|
|
|
|
auto_id=False, dim=ct.default_dim, is_index=False):
|
2021-06-10 11:46:49 +08:00
|
|
|
"""
|
|
|
|
target: create specified collections
|
|
|
|
method: 1. create collections (binary/non-binary)
|
|
|
|
2. create partitions if specified
|
|
|
|
3. insert specified binary/non-binary data
|
|
|
|
into each partition if any
|
|
|
|
expected: return collection and raw data
|
|
|
|
"""
|
|
|
|
log.info("Test case of search interface: initialize before test case")
|
2021-07-02 09:48:12 +08:00
|
|
|
self._connect()
|
2021-06-10 11:46:49 +08:00
|
|
|
collection_name = cf.gen_unique_str(prefix)
|
|
|
|
vectors = []
|
|
|
|
binary_raw_vectors = []
|
2021-07-07 17:50:00 +08:00
|
|
|
insert_ids = []
|
2021-06-10 11:46:49 +08:00
|
|
|
# 1 create collection
|
2021-07-20 22:29:53 +08:00
|
|
|
default_schema = cf.gen_default_collection_schema(auto_id=auto_id, dim=dim)
|
2021-06-10 11:46:49 +08:00
|
|
|
if is_binary:
|
2021-07-20 22:29:53 +08:00
|
|
|
default_schema = cf.gen_default_binary_collection_schema(auto_id=auto_id, dim=dim)
|
2021-06-24 20:40:09 +08:00
|
|
|
if is_all_data_type:
|
2021-07-20 22:29:53 +08:00
|
|
|
default_schema = cf.gen_collection_schema_all_datatype(auto_id=auto_id, dim=dim)
|
2021-06-15 15:11:57 +08:00
|
|
|
log.info("init_collection_general: collection creation")
|
2021-06-10 11:46:49 +08:00
|
|
|
collection_w = self.init_collection_wrap(name=collection_name,
|
|
|
|
schema=default_schema)
|
|
|
|
# 2 add extra partitions if specified (default is 1 partition named "_default")
|
|
|
|
if partition_num > 0:
|
|
|
|
cf.gen_partitions(collection_w, partition_num)
|
|
|
|
# 3 insert data if specified
|
|
|
|
if insert_data:
|
2021-07-07 17:50:00 +08:00
|
|
|
collection_w, vectors, binary_raw_vectors, insert_ids = \
|
2021-07-20 22:29:53 +08:00
|
|
|
cf.insert_data(collection_w, nb, is_binary, is_all_data_type,
|
|
|
|
auto_id=auto_id, dim=dim)
|
2021-06-28 15:54:11 +08:00
|
|
|
assert collection_w.is_empty is False
|
2021-06-24 20:40:09 +08:00
|
|
|
assert collection_w.num_entities == nb
|
2021-07-22 11:49:44 +08:00
|
|
|
# This condition will be removed after auto index feature
|
|
|
|
if not is_index:
|
|
|
|
collection_w.load()
|
2021-06-10 11:46:49 +08:00
|
|
|
|
2021-07-07 17:50:00 +08:00
|
|
|
return collection_w, vectors, binary_raw_vectors, insert_ids
|
2021-07-15 15:03:54 +08:00
|
|
|
|
|
|
|
def insert_entities_into_two_partitions_in_half(self, half, prefix='query'):
|
|
|
|
"""
|
|
|
|
insert default entities into two partitions(partition_w and _default) in half(int64 and float fields values)
|
|
|
|
:param half: half of nb
|
|
|
|
:return: collection wrap and partition wrap
|
|
|
|
"""
|
|
|
|
conn = self._connect()
|
|
|
|
collection_w = self.init_collection_wrap(name=cf.gen_unique_str(prefix))
|
|
|
|
partition_w = self.init_partition_wrap(collection_wrap=collection_w)
|
|
|
|
# insert [0, half) into partition_w
|
|
|
|
df_partition = cf.gen_default_dataframe_data(nb=half, start=0)
|
|
|
|
partition_w.insert(df_partition)
|
|
|
|
# insert [half, nb) into _default
|
|
|
|
df_default = cf.gen_default_dataframe_data(nb=half, start=half)
|
|
|
|
collection_w.insert(df_default)
|
|
|
|
conn.flush([collection_w.name])
|
|
|
|
collection_w.load()
|
|
|
|
return collection_w, partition_w, df_partition, df_default
|