Пример #1
0
    def check_merge_compact_plan(compaction_plans, func_name, check_items):
        """
        Verify that the merge type compaction plan

        :param: compaction_plans: A compaction plan
        :type: CompactionPlans

        :param func_name: get_compaction_plans API name
        :type func_name: str

        :param check_items: which items you wish to check
                            segment_num represent how many segments are expected to be merged, default is 2
        :type: dict
        """
        to_check_func = 'get_compaction_plans'
        if func_name != to_check_func:
            log.warning("The function name is {} rather than {}".format(
                func_name, to_check_func))
        if not isinstance(compaction_plans, CompactionPlans):
            raise Exception(
                "The compaction_plans result to check isn't CompactionPlans type object"
            )

        segment_num = check_items.get("segment_num", 2)
        assert len(compaction_plans.plans) == 1
        assert len(compaction_plans.plans[0].sources) == segment_num
        assert compaction_plans.plans[0].target not in compaction_plans.plans[
            0].sources
Пример #2
0
    def check_query_results(query_res, func_name, check_items):
        """
        According to the check_items to check actual query result, which return from func_name.

        :param: query_res: A list that contains all results
        :type: list

        :param func_name: Query API name
        :type func_name: str

        :param check_items: The items expected to be checked, including exp_res, with_vec
                            The type of exp_res value is as same as query_res
                            The type of with_vec value is bool, True value means check vector field, False otherwise
        :type check_items: dict
        """
        if func_name != 'query':
            log.warning("The function name is {} rather than {}".format(
                func_name, "query"))
        if not isinstance(query_res, list):
            raise Exception("The query result to check isn't list type object")
        if len(check_items) == 0:
            raise Exception("No expect values found in the check task")
        exp_res = check_items.get("exp_res", None)
        with_vec = check_items.get("with_vec", False)
        if exp_res and isinstance(query_res, list):
            assert pc.equal_entities_list(exp=exp_res,
                                          actual=query_res,
                                          with_vec=with_vec)
Пример #3
0
 def check_collection_property(res, func_name, check_items):
     exp_func_name = "init_collection"
     exp_func_name_2 = "construct_from_dataframe"
     if func_name != exp_func_name and func_name != exp_func_name_2:
         log.warning("The function name is {} rather than {}".format(func_name, exp_func_name))
     if isinstance(res, Collection):
         collection = res
     elif isinstance(res, tuple):
         collection = res[0]
         log.debug(collection.schema)
     else:
         raise Exception("The result to check isn't collection type object")
     if len(check_items) == 0:
         raise Exception("No expect values found in the check task")
     if check_items.get("name", None):
         assert collection.name == check_items.get("name")
     if check_items.get("schema", None):
         assert collection.schema == check_items.get("schema")
     if check_items.get("num_entities", None):
         if check_items.get("num_entities") == 0:
             assert collection.is_empty
         assert collection.num_entities == check_items.get("num_entities")
     if check_items.get("primary", None):
         assert collection.primary_field.name == check_items.get("primary")
     return True
Пример #4
0
    def check_delete_compact_plan(compaction_plans, func_name, check_items):
        """
        Verify that the delete type compaction plan

        :param: compaction_plans: A compaction plan
        :type: CompactionPlans

        :param func_name: get_compaction_plans API name
        :type func_name: str

        :param check_items: which items you wish to check
                            plans_num represent the delete compact plans number
        :type: dict
        """
        to_check_func = 'get_compaction_plans'
        if func_name != to_check_func:
            log.warning("The function name is {} rather than {}".format(
                func_name, to_check_func))
        if not isinstance(compaction_plans, CompactionPlans):
            raise Exception(
                "The compaction_plans result to check isn't CompactionPlans type object"
            )

        plans_num = check_items.get("plans_num", 1)
        assert len(compaction_plans.plans) == plans_num
        for plan in compaction_plans.plans:
            assert len(plan.sources) == 1
            assert plan.sources[0] != plan.target
Пример #5
0
 def check_query_results(query_res, func_name, check_items):
     if func_name != 'query':
         log.warning("The function name is {} rather than {}".format(func_name, "query"))
     if not isinstance(query_res, list):
         raise Exception("The query result to check isn't list type object")
     if len(check_items) == 0:
         raise Exception("No expect values found in the check task")
     exp_res = check_items.get("exp_res", None)
     with_vec = check_items.get("with_vec", False)
     if exp_res and isinstance(query_res, list):
         assert pc.equal_entities_list(exp=exp_res, actual=query_res, with_vec=with_vec)
Пример #6
0
def get_milvus_chart_env_var(var=constants.MILVUS_CHART_ENV):
    """ get log path for testing """
    try:
        milvus_helm_chart = os.environ[var]
        return str(milvus_helm_chart)
    except Exception as e:
        milvus_helm_chart = constants.MILVUS_CHART_PATH
        log.warning(
            f"Failed to get environment variables: {var}, use default: {constants.MILVUS_CHART_PATH}, {str(e)}")
    if not os.path.exists(milvus_helm_chart):
        raise Exception(f'milvus_helm_chart: {milvus_helm_chart} not exist')
    return milvus_helm_chart
Пример #7
0
 def req_collection_property_check(collection, func_name, params):
     '''
     :param collection
     :return:
     '''
     exp_func_name = "collection_init"
     if func_name != exp_func_name:
         log.warning("The function name is {} rather than {}".format(
             func_name, exp_func_name))
     if not isinstance(collection, Collection):
         raise Exception("The result to check isn't collection type object")
     assert collection.name == params["name"]
     assert collection.description == params["schema"].description
     assert collection.schema == params["schema"]
Пример #8
0
    def check_query_empty(query_res, func_name):
        """
        Verify that the query result is empty

        :param: query_res: A list that contains all results
        :type: list

        :param func_name: Query API name
        :type func_name: str
        """
        if func_name != 'query':
            log.warning("The function name is {} rather than {}".format(func_name, "query"))
        if not isinstance(query_res, list):
            raise Exception("The query result to check isn't list type object")
        assert len(query_res) == 0, "Query result is not empty"
Пример #9
0
    def check_distance(distance_res, func_name, check_items):
        if func_name != 'calc_distance':
            log.warning("The function name is {} rather than {}".format(func_name, "calc_distance"))
        if not isinstance(distance_res, list):
            raise Exception("The distance result to check isn't list type object")
        if len(check_items) == 0:
            raise Exception("No expect values found in the check task")
        vectors_l = check_items["vectors_l"]
        vectors_r = check_items["vectors_r"]
        metric = check_items.get("metric", "L2")
        sqrt = check_items.get("sqrt", False)
        cf.compare_distance_2d_vector(vectors_l, vectors_r,
                                      distance_res,
                                      metric, sqrt)

        return True
Пример #10
0
 def check_search_results(search_res, func_name, check_items):
     """
     target: check the search results
     method: 1. check the query number
             2. check the limit(topK) and ids
             3. check the distance
     expected: check the search is ok
     """
     log.info("search_results_check: checking the searching results")
     if func_name != 'search':
         log.warning("The function name is {} rather than {}".format(
             func_name, "search"))
     if len(check_items) == 0:
         raise Exception("No expect values found in the check task")
     if check_items.get("_async", None):
         if check_items["_async"]:
             search_res.done()
             search_res = search_res.result()
     if len(search_res) != check_items["nq"]:
         log.error("search_results_check: Numbers of query searched (%d) "
                   "is not equal with expected (%d)" %
                   (len(search_res), check_items["nq"]))
         assert len(search_res) == check_items["nq"]
     else:
         log.info(
             "search_results_check: Numbers of query searched is correct")
     for hits in search_res:
         if (len(hits) != check_items["limit"]) \
                 or (len(hits.ids) != check_items["limit"]):
             log.error("search_results_check: limit(topK) searched (%d) "
                       "is not equal with expected (%d)" %
                       (len(hits), check_items["limit"]))
             assert len(hits) == check_items["limit"]
             assert len(hits.ids) == check_items["limit"]
         else:
             if check_items.get("ids", None) is not None:
                 ids_match = pc.list_contain_check(list(hits.ids),
                                                   list(check_items["ids"]))
                 if not ids_match:
                     log.error(
                         "search_results_check: ids searched not match")
                     assert ids_match
             else:
                 pass  # just check nq and topk, not specific ids need check
     log.info("search_results_check: limit (topK) and "
              "ids searched for %d queries are correct" % len(search_res))
     return True
Пример #11
0
 def check_partition_property(partition, func_name, check_items):
     exp_func_name = "init_partition"
     if func_name != exp_func_name:
         log.warning("The function name is {} rather than {}".format(func_name, exp_func_name))
     if not isinstance(partition, Partition):
         raise Exception("The result to check isn't partition type object")
     if len(check_items) == 0:
         raise Exception("No expect values found in the check task")
     if check_items.get("name", None):
         assert partition.name == check_items["name"]
     if check_items.get("description", None):
         assert partition.description == check_items["description"]
     if check_items.get("is_empty", None):
         assert partition.is_empty == check_items["is_empty"]
     if check_items.get("num_entities", None):
         assert partition.num_entities == check_items["num_entities"]
     return True
Пример #12
0
    def check_collection_property(res, func_name, check_items):
        """
        According to the check_items to check collection properties of res, which return from func_name
        :param res: actual response of init collection
        :type res: Collection

        :param func_name: init collection API
        :type func_name: str

        :param check_items: which items expected to be checked, including name, schema, num_entities, primary
        :type check_items: dict, {check_key: expected_value}
        """
        exp_func_name = "init_collection"
        exp_func_name_2 = "construct_from_dataframe"
        if func_name != exp_func_name and func_name != exp_func_name_2:
            log.warning("The function name is {} rather than {}".format(
                func_name, exp_func_name))
        if isinstance(res, Collection):
            collection = res
        elif isinstance(res, tuple):
            collection = res[0]
            log.debug(collection.schema)
        else:
            raise Exception("The result to check isn't collection type object")
        if len(check_items) == 0:
            raise Exception("No expect values found in the check task")
        if check_items.get("name", None):
            assert collection.name == check_items.get("name")
        if check_items.get("schema", None):
            assert collection.schema == check_items.get("schema")
        if check_items.get("num_entities", None):
            if check_items.get("num_entities") == 0:
                assert collection.is_empty
            assert collection.num_entities == check_items.get("num_entities")
        if check_items.get("primary", None):
            assert collection.primary_field.name == check_items.get("primary")
        if check_items.get("shards_num", None):
            assert collection._shards_num == check_items.get("shards_num")
        return True
Пример #13
0
 def check_collection_property(collection, func_name, check_items):
     exp_func_name = "init_collection"
     if func_name != exp_func_name:
         log.warning("The function name is {} rather than {}".format(
             func_name, exp_func_name))
     if not isinstance(collection, Collection):
         raise Exception("The result to check isn't collection type object")
     if len(check_items) == 0:
         raise Exception("No expect values found in the check task")
     name = check_items.get("name", None)
     schema = check_items.get("schema", None)
     num_entities = check_items.get("num_entities", 0)
     primary = check_items.get("primary", None)
     if name:
         assert collection.name == name
     if schema:
         assert collection.schema == schema
     if num_entities == 0:
         assert collection.is_empty
     assert collection.num_entities == num_entities
     assert collection.primary_field == primary
     return True