Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add testcase of empty vector insert #2850

Merged
merged 2 commits into from
Jul 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 75 additions & 28 deletions tests/milvus_python_test/entity/test_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
collection_id = "test_add"
ADD_TIMEOUT = 60
tag = "1970-01-01"
add_interval_time = 5
add_interval_time = 5
nb = 6000


Expand Down Expand Up @@ -61,6 +61,26 @@ def test_add_vector_has_collection(self, connect, collection):
status, ids = connect.insert(collection, vector)
assert assert_has_collection(connect, collection)

def test_add_vector_with_empty_vector(self, connect, collection):
'''
target: test add vectors with empty vectors list
method: set empty vectors list as add method params
expected: raises a Exception
'''
vector = []
with pytest.raises(Exception) as e:
status, ids = connect.insert(collection, vector)

def test_add_vector_with_None(self, connect, collection):
'''
target: test add vectors with None
method: set None as add method params
expected: raises a Exception
'''
vector = None
with pytest.raises(Exception) as e:
status, ids = connect.insert(collection, vector)

@pytest.mark.timeout(ADD_TIMEOUT)
def test_drop_collection_add_vector(self, connect, collection):
'''
Expand Down Expand Up @@ -215,7 +235,8 @@ def test_add_vector_create_index_another(self, connect, collection, get_simple_i
status = connect.create_collection(param)
vector = gen_single_vector(dim)
status, ids = connect.insert(collection, vector)
status = connect.create_index(param['collection_name'], index_type, index_param)
status = connect.create_index(
param['collection_name'], index_type, index_param)
assert status.OK()

@pytest.mark.timeout(ADD_TIMEOUT)
Expand Down Expand Up @@ -250,7 +271,8 @@ def test_add_vector_sleep_create_index_another(self, connect, collection, get_si
vector = gen_single_vector(dim)
status, ids = connect.insert(collection, vector)
connect.flush([collection])
status = connect.create_index(param['collection_name'], index_type, index_param)
status = connect.create_index(
param['collection_name'], index_type, index_param)
assert status.OK()

@pytest.mark.timeout(ADD_TIMEOUT)
Expand Down Expand Up @@ -357,14 +379,16 @@ def test_insert_ids(self, connect, collection):
method: create collection and add vectors in it, check the ids returned and the collection length after vectors added
expected: the length of ids and the collection row count
'''
nq = 5; top_k = 1;
nq = 5
top_k = 1
vectors = gen_vectors(nq, dim)
ids = [i for i in range(nq)]
status, ids = connect.insert(collection, vectors, ids)
connect.flush([collection])
assert status.OK()
assert len(ids) == nq
status, result = connect.search(collection, top_k, query_records=vectors)
status, result = connect.search(
collection, top_k, query_records=vectors)
logging.getLogger().info(result)
assert len(result) == nq
for i in range(nq):
Expand All @@ -377,7 +401,8 @@ def test_insert_twice_ids_no_ids(self, connect, collection):
method: test add vectors twice, use customize ids first, and then use no ids
expected: status not OK
'''
nq = 5; top_k = 1;
nq = 5
top_k = 1
vectors = gen_vectors(nq, dim)
ids = [i for i in range(nq)]
status, ids = connect.insert(collection, vectors, ids)
Expand All @@ -394,7 +419,8 @@ def test_insert_twice_not_ids_ids(self, connect, collection):
method: test add vectors twice, use not ids first, and then use customize ids
expected: status not OK
'''
nq = 5; top_k = 1;
nq = 5
top_k = 1
vectors = gen_vectors(nq, dim)
ids = [i for i in range(nq)]
status, ids = connect.insert(collection, vectors)
Expand Down Expand Up @@ -502,7 +528,8 @@ def test_insert_tag_not_existed_A(self, connect, collection):
vectors = gen_vectors(nq, dim)
new_tag = "new_tag"
status = connect.create_partition(collection, tag)
status, ids = connect.insert(collection, vectors, partition_tag=new_tag)
status, ids = connect.insert(
collection, vectors, partition_tag=new_tag)
assert not status.OK()

@pytest.mark.timeout(ADD_TIMEOUT)
Expand All @@ -517,7 +544,8 @@ def test_insert_tag_existed(self, connect, collection):
status = connect.create_partition(collection, tag)
status, ids = connect.insert(collection, vectors, partition_tag=tag)
for i in range(5):
status, ids = connect.insert(collection, vectors, partition_tag=tag)
status, ids = connect.insert(
collection, vectors, partition_tag=tag)
assert status.OK()
assert len(ids) == nq

Expand All @@ -541,7 +569,8 @@ def test_add_collection_not_existed(self, connect):
'''
nq = 5
vector = gen_single_vector(dim)
status, ids = connect.insert(gen_unique_str("not_exist_collection"), vector)
status, ids = connect.insert(
gen_unique_str("not_exist_collection"), vector)
assert not status.OK()
assert not ids

Expand Down Expand Up @@ -593,8 +622,10 @@ def test_collection_add_rows_count_multi_threading(self, args, collection):
pytest.skip("Skip test in http mode")
thread_num = 8
threads = []
milvus = get_milvus(host=args["ip"], port=args["port"], handler=args["handler"], try_connect=False)
milvus = get_milvus(
host=args["ip"], port=args["port"], handler=args["handler"], try_connect=False)
vectors = gen_vectors(nb, dim)

def add(thread_i):
logging.getLogger().info("In thread-%d" % thread_i)
# milvus = get_milvus(host=args["ip"], port=args["port"], handler=args["handler"])
Expand Down Expand Up @@ -622,7 +653,8 @@ def test_add_vector_multi_collections(self, connect):
vectors = gen_vectors(nq, dim)
collection_list = []
for i in range(20):
collection_name = gen_unique_str('test_add_vector_multi_collections')
collection_name = gen_unique_str(
'test_add_vector_multi_collections')
collection_list.append(collection_name)
param = {'collection_name': collection_name,
'dimension': dim,
Expand All @@ -631,9 +663,11 @@ def test_add_vector_multi_collections(self, connect):
connect.create_collection(param)
for j in range(5):
for i in range(20):
status, ids = connect.insert(collection_name=collection_list[i], records=vectors)
status, ids = connect.insert(
collection_name=collection_list[i], records=vectors)
assert status.OK()


class TestAddAsync:
@pytest.fixture(scope="function", autouse=True)
def skip_http_check(self, args):
Expand All @@ -658,7 +692,6 @@ def check_status_not_ok(self, status, result):
logging.getLogger().info("In callback check status")
assert not status.OK()


def test_insert_async(self, connect, collection, insert_count):
'''
target: test add vectors with different length of vectors
Expand Down Expand Up @@ -695,7 +728,8 @@ def test_insert_async_callback(self, connect, collection, insert_count):
'''
nb = insert_count
insert_vec_list = gen_vectors(nb, dim)
future = connect.insert(collection, insert_vec_list, _async=True, _callback=self.check_status)
future = connect.insert(
collection, insert_vec_list, _async=True, _callback=self.check_status)
future.done()

@pytest.mark.level(2)
Expand All @@ -707,10 +741,11 @@ def test_insert_async_long(self, connect, collection):
'''
nb = 50000
insert_vec_list = gen_vectors(nb, dim)
future = connect.insert(collection, insert_vec_list, _async=True, _callback=self.check_status)
future = connect.insert(
collection, insert_vec_list, _async=True, _callback=self.check_status)
status, result = future.result()
assert status.OK()
assert len(result) == nb
assert len(result) == nb
connect.flush([collection])
status, count = connect.count_entities(collection)
assert status.OK()
Expand All @@ -726,7 +761,8 @@ def test_insert_async_callback_timeout(self, connect, collection):
'''
nb = 100000
insert_vec_list = gen_vectors(nb, dim)
future = connect.insert(collection, insert_vec_list, _async=True, _callback=self.check_status, timeout=1)
future = connect.insert(collection, insert_vec_list,
_async=True, _callback=self.check_status, timeout=1)
future.done()

def test_insert_async_invalid_params(self, connect, collection):
Expand All @@ -751,7 +787,9 @@ def test_insert_async_invalid_params_raise_exception(self, connect, collection):
insert_vec_list = []
collection_new = gen_unique_str()
with pytest.raises(Exception) as e:
future = connect.insert(collection_new, insert_vec_list, _async=True)
future = connect.insert(
collection_new, insert_vec_list, _async=True)



class TestAddIP:
Expand Down Expand Up @@ -908,7 +946,7 @@ def test_create_index_add_vector_another(self, connect, ip_collection, get_simpl
expected: status ok
'''
index_param = get_simple_index["index_param"]
index_type = get_simple_index["index_type"]
index_type = get_simple_index["index_type"]
param = {'collection_name': gen_unique_str(),
'dimension': dim,
'index_file_size': index_file_size,
Expand Down Expand Up @@ -954,7 +992,8 @@ def test_add_vector_create_index_another(self, connect, ip_collection, get_simpl
status = connect.create_collection(param)
vector = gen_single_vector(dim)
status, ids = connect.insert(ip_collection, vector)
status = connect.create_index(param['collection_name'], index_type, index_param)
status = connect.create_index(
param['collection_name'], index_type, index_param)
assert status.OK()

@pytest.mark.timeout(ADD_TIMEOUT)
Expand Down Expand Up @@ -992,7 +1031,8 @@ def test_add_vector_sleep_create_index_another(self, connect, ip_collection, get
vector = gen_single_vector(dim)
status, ids = connect.insert(ip_collection, vector)
connect.flush([ip_collection])
status = connect.create_index(param['collection_name'], index_type, index_param)
status = connect.create_index(
param['collection_name'], index_type, index_param)
assert status.OK()

@pytest.mark.timeout(ADD_TIMEOUT)
Expand Down Expand Up @@ -1101,7 +1141,8 @@ def test_insert_ids(self, connect, ip_collection):
method: create collection and add vectors in it, check the ids returned and the collection length after vectors added
expected: the length of ids and the collection row count
'''
nq = 5; top_k = 1
nq = 5
top_k = 1
vectors = gen_vectors(nq, dim)
ids = [i for i in range(nq)]
status, ids = connect.insert(ip_collection, vectors, ids)
Expand All @@ -1122,7 +1163,8 @@ def test_insert_twice_ids_no_ids(self, connect, ip_collection):
method: test add vectors twice, use customize ids first, and then use no ids
expected: status not OK
'''
nq = 5; top_k = 1
nq = 5
top_k = 1
vectors = gen_vectors(nq, dim)
ids = [i for i in range(nq)]
status, ids = connect.insert(ip_collection, vectors, ids)
Expand All @@ -1139,7 +1181,8 @@ def test_insert_twice_not_ids_ids(self, connect, ip_collection):
method: test add vectors twice, use not ids first, and then use customize ids
expected: status not OK
'''
nq = 5; top_k = 1
nq = 5
top_k = 1
vectors = gen_vectors(nq, dim)
ids = [i for i in range(nq)]
status, ids = connect.insert(ip_collection, vectors)
Expand Down Expand Up @@ -1253,7 +1296,8 @@ def test_add_vector_multi_collections(self, connect):
vectors = gen_vectors(nq, dim)
collection_list = []
for i in range(20):
collection_name = gen_unique_str('test_add_vector_multi_collections')
collection_name = gen_unique_str(
'test_add_vector_multi_collections')
collection_list.append(collection_name)
param = {'collection_name': collection_name,
'dimension': dim,
Expand All @@ -1262,9 +1306,11 @@ def test_add_vector_multi_collections(self, connect):
connect.create_collection(param)
for j in range(10):
for i in range(20):
status, ids = connect.insert(collection_name=collection_list[i], records=vectors)
status, ids = connect.insert(
collection_name=collection_list[i], records=vectors)
assert status.OK()


class TestAddAdvance:
@pytest.fixture(
scope="function",
Expand Down Expand Up @@ -1368,7 +1414,8 @@ def test_insert_with_invalid_tag_name(self, connect, get_collection_name, get_ta
collection_name = get_collection_name
tag_name = get_tag_name
vectors = gen_vectors(1, dim)
status, result = connect.insert(collection_name, vectors, partition_tag=tag_name)
status, result = connect.insert(
collection_name, vectors, partition_tag=tag_name)
assert not status.OK()


Expand Down