2021-05-11 17:59:29 +08:00
|
|
|
import sys
|
|
|
|
|
|
|
|
sys.path.append("..")
|
|
|
|
from check.param_check import *
|
|
|
|
from check.func_check import *
|
2021-06-07 12:15:35 +08:00
|
|
|
from utils.api_request import api_request
|
2021-07-26 15:51:20 +08:00
|
|
|
from utils.util_log import test_log as log
|
|
|
|
|
2021-07-28 19:35:22 +08:00
|
|
|
TIMEOUT = 20
|
|
|
|
#keep small timeout for stability tests
|
|
|
|
#TIMEOUT = 5
|
2021-07-26 15:51:20 +08:00
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
class ApiCollectionWrapper:
|
2021-05-11 17:59:29 +08:00
|
|
|
collection = None
|
|
|
|
|
2021-06-16 19:49:59 +08:00
|
|
|
def init_collection(self, name, schema=None, check_task=None, check_items=None, **kwargs):
|
2021-05-11 17:59:29 +08:00
|
|
|
""" In order to distinguish the same name of collection """
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 19:49:59 +08:00
|
|
|
res, is_succ = api_request([Collection, name, schema], **kwargs)
|
2021-06-07 12:15:35 +08:00
|
|
|
self.collection = res if is_succ else None
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, is_succ,
|
2021-06-16 19:49:59 +08:00
|
|
|
name=name, schema=schema, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def schema(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.schema
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def description(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.description
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def name(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.name
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def is_empty(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.is_empty
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def num_entities(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.num_entities
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def primary_field(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.primary_field
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-17 17:27:59 +08:00
|
|
|
def construct_from_dataframe(self, name, dataframe, check_task=None, check_items=None, **kwargs):
|
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, is_succ = api_request([Collection.construct_from_dataframe, name, dataframe], **kwargs)
|
2021-06-25 10:38:11 +08:00
|
|
|
self.collection = res[0] if is_succ else None
|
2021-06-17 17:27:59 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, is_succ,
|
|
|
|
name=name, dataframe=dataframe, **kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def drop(self, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-05 10:25:34 +08:00
|
|
|
res, check = api_request([self.collection.drop], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def load(self, partition_names=None, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.load, partition_names], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
2021-06-05 10:25:34 +08:00
|
|
|
partition_names=partition_names, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def release(self, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-05 10:25:34 +08:00
|
|
|
res, check = api_request([self.collection.release], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task,
|
|
|
|
check_items, check, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def insert(self, data, partition_name=None, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-05 10:25:34 +08:00
|
|
|
res, check = api_request([self.collection.insert, data, partition_name], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
2021-06-05 10:25:34 +08:00
|
|
|
dat=data, partition_name=partition_name,
|
|
|
|
**kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-17 17:27:59 +08:00
|
|
|
def search(self, data, anns_field, param, limit, expr=None,
|
2021-06-05 10:25:34 +08:00
|
|
|
partition_names=None, output_fields=None, timeout=None,
|
2021-06-07 16:41:35 +08:00
|
|
|
check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-18 19:12:09 +08:00
|
|
|
res, check = api_request([self.collection.search, data, anns_field, param, limit,
|
|
|
|
expr, partition_names, output_fields, timeout], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
2021-06-05 10:25:34 +08:00
|
|
|
data=data, anns_field=anns_field, param=param, limit=limit,
|
2021-06-17 17:27:59 +08:00
|
|
|
expr=expr, partition_names=partition_names,
|
2021-06-05 10:25:34 +08:00
|
|
|
output_fields=output_fields,
|
|
|
|
timeout=timeout, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-17 13:43:57 +08:00
|
|
|
def query(self, expr, output_fields=None, partition_names=None, timeout=None, check_task=None, check_items=None,
|
|
|
|
**kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = TIMEOUT if timeout is None else timeout
|
|
|
|
|
2021-06-17 13:43:57 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
|
|
|
res, check = api_request([self.collection.query, expr, output_fields, partition_names, timeout])
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
|
|
|
expression=expr, partition_names=partition_names,
|
|
|
|
output_fields=output_fields,
|
|
|
|
timeout=timeout, **kwargs).run()
|
|
|
|
return res, check_result
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def partitions(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.partitions
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def partition(self, partition_name, check_task=None, check_items=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.collection.partition, partition_name])
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items,
|
2021-06-07 12:15:35 +08:00
|
|
|
succ, partition_name=partition_name).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def has_partition(self, partition_name, check_task=None, check_items=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-07 12:15:35 +08:00
|
|
|
res, succ = api_request([self.collection.has_partition, partition_name])
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items,
|
2021-06-07 12:15:35 +08:00
|
|
|
succ, partition_name=partition_name).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-07 16:41:35 +08:00
|
|
|
def drop_partition(self, partition_name, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-05 10:25:34 +08:00
|
|
|
res, check = api_request([self.collection.drop_partition, partition_name], **kwargs)
|
2021-06-07 16:41:35 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, partition_name=partition_name, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-07-26 15:51:20 +08:00
|
|
|
def create_partition(self, partition_name, check_task=None, check_items=None, description=""):
|
2021-06-10 11:46:49 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-07-26 15:51:20 +08:00
|
|
|
res, check = api_request([self.collection.create_partition, partition_name, description])
|
2021-06-10 11:46:49 +08:00
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
2021-07-26 15:51:20 +08:00
|
|
|
partition_name=partition_name).run()
|
2021-06-10 11:46:49 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-04 09:35:34 +08:00
|
|
|
@property
|
2021-06-17 11:49:57 +08:00
|
|
|
def indexes(self):
|
2021-06-04 09:35:34 +08:00
|
|
|
return self.collection.indexes
|
2021-05-11 17:59:29 +08:00
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def index(self, check_task=None, check_items=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.index])
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def create_index(self, field_name, index_params, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.create_index, field_name, index_params], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check,
|
|
|
|
field_name=field_name, index_params=index_params, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def has_index(self, check_task=None, check_items=None):
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.has_index])
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|
|
|
|
|
2021-06-16 11:29:55 +08:00
|
|
|
def drop_index(self, check_task=None, check_items=None, **kwargs):
|
2021-07-26 15:51:20 +08:00
|
|
|
timeout = kwargs.get("timeout", TIMEOUT)
|
|
|
|
kwargs.update({"timeout": timeout})
|
|
|
|
|
2021-05-11 17:59:29 +08:00
|
|
|
func_name = sys._getframe().f_code.co_name
|
2021-06-16 11:29:55 +08:00
|
|
|
res, check = api_request([self.collection.drop_index], **kwargs)
|
|
|
|
check_result = ResponseChecker(res, func_name, check_task, check_items, check, **kwargs).run()
|
2021-05-11 17:59:29 +08:00
|
|
|
return res, check_result
|