Skip to content

Commit

Permalink
Add structure cases (milvus-io#1675)
Browse files Browse the repository at this point in the history
* enable nsg case

Signed-off-by: zhenwu <zw@zilliz.com>

* enable sub/superstructure

Signed-off-by: zhenwu <zw@zilliz.com>
  • Loading branch information
del-zhenwu authored Mar 16, 2020
1 parent 59dab6c commit 21c7b8f
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 2 deletions.
43 changes: 43 additions & 0 deletions tests/milvus_python_test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,48 @@ def teardown():
connect.drop_collection(collection_name)

request.addfinalizer(teardown)
return collection_name

@pytest.fixture(scope="function")
def substructure_collection(request, connect):
ori_collection_name = getattr(request.module, "collection_id", "test")
collection_name = gen_unique_str(ori_collection_name)
dim = getattr(request.module, "dim", "128")
param = {'collection_name': collection_name,
'dimension': dim,
'index_file_size': index_file_size,
'metric_type': MetricType.SUBSTRUCTURE}
status = connect.create_collection(param)
# logging.getLogger().info(status)
if not status.OK():
pytest.exit("collection can not be created, exit pytest ...")

def teardown():
status, collection_names = connect.show_collections()
for collection_name in collection_names:
connect.drop_collection(collection_name)

request.addfinalizer(teardown)
return collection_name

@pytest.fixture(scope="function")
def superstructure_collection(request, connect):
ori_collection_name = getattr(request.module, "collection_id", "test")
collection_name = gen_unique_str(ori_collection_name)
dim = getattr(request.module, "dim", "128")
param = {'collection_name': collection_name,
'dimension': dim,
'index_file_size': index_file_size,
'metric_type': MetricType.SUPERSTRUCTURE}
status = connect.create_collection(param)
# logging.getLogger().info(status)
if not status.OK():
pytest.exit("collection can not be created, exit pytest ...")

def teardown():
status, collection_names = connect.show_collections()
for collection_name in collection_names:
connect.drop_collection(collection_name)

request.addfinalizer(teardown)
return collection_name
92 changes: 92 additions & 0 deletions tests/milvus_python_test/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ def test_create_collection_hamming(self, connect):
status = connect.create_collection(param)
assert status.OK()

def test_create_collection_substructure(self, connect):
'''
target: test create normal collection
method: create collection with corrent params
expected: create status return ok
'''
collection_name = gen_unique_str("test_collection")
param = {'collection_name': collection_name,
'dimension': dim,
'index_file_size': index_file_size,
'metric_type': MetricType.SUBSTRUCTURE}
status = connect.create_collection(param)
assert status.OK()

def test_create_collection_superstructure(self, connect):
'''
target: test create normal collection
method: create collection with corrent params
expected: create status return ok
'''
collection_name = gen_unique_str("test_collection")
param = {'collection_name': collection_name,
'dimension': dim,
'index_file_size': index_file_size,
'metric_type': MetricType.SUPERSTRUCTURE}
status = connect.create_collection(param)
assert status.OK()

@pytest.mark.level(2)
def test_create_collection_without_connection(self, dis_connect):
'''
Expand Down Expand Up @@ -253,6 +281,38 @@ def test_collection_describe_collection_name_hamming(self, connect):
assert res.collection_name == collection_name
assert res.metric_type == MetricType.HAMMING

def test_collection_describe_collection_name_substructure(self, connect):
'''
target: test describe collection created with correct params
method: create collection, assert the value returned by describe method
expected: collection_name equals with the collection name created
'''
collection_name = gen_unique_str("test_collection")
param = {'collection_name': collection_name,
'dimension': dim,
'index_file_size': index_file_size,
'metric_type': MetricType.SUBSTRUCTURE}
connect.create_collection(param)
status, res = connect.describe_collection(collection_name)
assert res.collection_name == collection_name
assert res.metric_type == MetricType.SUBSTRUCTURE

def test_collection_describe_collection_name_superstructure(self, connect):
'''
target: test describe collection created with correct params
method: create collection, assert the value returned by describe method
expected: collection_name equals with the collection name created
'''
collection_name = gen_unique_str("test_collection")
param = {'collection_name': collection_name,
'dimension': dim,
'index_file_size': index_file_size,
'metric_type': MetricType.SUPERSTRUCTURE}
connect.create_collection(param)
status, res = connect.describe_collection(collection_name)
assert res.collection_name == collection_name
assert res.metric_type == MetricType.SUPERSTRUCTURE

# TODO: enable
@pytest.mark.level(2)
def _test_collection_describe_collection_name_multiprocessing(self, connect, args):
Expand Down Expand Up @@ -658,6 +718,38 @@ def test_show_collections_hamming(self, connect):
assert status.OK()
assert collection_name in result

def test_show_collections_substructure(self, connect):
'''
target: test show collections is correct or not, if collection created
method: create collection, assert the value returned by show_collections method is equal to 0
expected: collection_name in show collections
'''
collection_name = gen_unique_str("test_collection")
param = {'collection_name': collection_name,
'dimension': dim,
'index_file_size': index_file_size,
'metric_type': MetricType.SUBSTRUCTURE}
connect.create_collection(param)
status, result = connect.show_collections()
assert status.OK()
assert collection_name in result

def test_show_collections_superstructure(self, connect):
'''
target: test show collections is correct or not, if collection created
method: create collection, assert the value returned by show_collections method is equal to 0
expected: collection_name in show collections
'''
collection_name = gen_unique_str("test_collection")
param = {'collection_name': collection_name,
'dimension': dim,
'index_file_size': index_file_size,
'metric_type': MetricType.SUPERSTRUCTURE}
connect.create_collection(param)
status, result = connect.show_collections()
assert status.OK()
assert collection_name in result

@pytest.mark.level(2)
def test_show_collections_without_connection(self, dis_connect):
'''
Expand Down
84 changes: 83 additions & 1 deletion tests/milvus_python_test/test_collection_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def test_collection_rows_count_multi_collections(self, connect):
assert status.OK()
assert res == nq

class TestCollectionCountHAM:
class TestCollectionCountBinary:
"""
params means different nb, the nb value may trigger merge, or not
"""
Expand Down Expand Up @@ -516,6 +516,28 @@ def get_hamming_index(self, request, connect):
else:
pytest.skip("Skip index Temporary")

@pytest.fixture(
scope="function",
params=gen_simple_index()
)
def get_substructure_index(self, request, connect):
logging.getLogger().info(request.param)
if request.param["index_type"] == IndexType.FLAT:
return request.param
else:
pytest.skip("Skip index Temporary")

@pytest.fixture(
scope="function",
params=gen_simple_index()
)
def get_superstructure_index(self, request, connect):
logging.getLogger().info(request.param)
if request.param["index_type"] == IndexType.FLAT:
return request.param
else:
pytest.skip("Skip index Temporary")

def test_collection_rows_count(self, connect, ham_collection, add_vectors_nb):
'''
target: test collection rows_count is correct or not
Expand All @@ -530,6 +552,34 @@ def test_collection_rows_count(self, connect, ham_collection, add_vectors_nb):
status, res = connect.count_collection(ham_collection)
assert res == nb

def test_collection_rows_count_substructure(self, connect, substructure_collection, add_vectors_nb):
'''
target: test collection rows_count is correct or not
method: create collection and add vectors in it,
assert the value returned by count_collection method is equal to length of vectors
expected: the count is equal to the length of vectors
'''
nb = add_vectors_nb
tmp, vectors = gen_binary_vectors(nb, dim)
res = connect.add_vectors(collection_name=substructure_collection, records=vectors)
connect.flush([substructure_collection])
status, res = connect.count_collection(substructure_collection)
assert res == nb

def test_collection_rows_count_superstructure(self, connect, superstructure_collection, add_vectors_nb):
'''
target: test collection rows_count is correct or not
method: create collection and add vectors in it,
assert the value returned by count_collection method is equal to length of vectors
expected: the count is equal to the length of vectors
'''
nb = add_vectors_nb
tmp, vectors = gen_binary_vectors(nb, dim)
res = connect.add_vectors(collection_name=superstructure_collection, records=vectors)
connect.flush([superstructure_collection])
status, res = connect.count_collection(superstructure_collection)
assert res == nb

def test_collection_rows_count_after_index_created(self, connect, ham_collection, get_hamming_index):
'''
target: test count_collection, after index have been created
Expand All @@ -546,6 +596,38 @@ def test_collection_rows_count_after_index_created(self, connect, ham_collection
status, res = connect.count_collection(ham_collection)
assert res == nb

def test_collection_rows_count_after_index_created_substructure(self, connect, substructure_collection, get_substructure_index):
'''
target: test count_collection, after index have been created
method: add vectors in db, and create index, then calling count_collection with correct params
expected: count_collection raise exception
'''
nb = 100
index_type = get_substructure_index["index_type"]
index_param = get_substructure_index["index_param"]
tmp, vectors = gen_binary_vectors(nb, dim)
res = connect.add_vectors(collection_name=substructure_collection, records=vectors)
connect.flush([substructure_collection])
connect.create_index(substructure_collection, index_type, index_param)
status, res = connect.count_collection(substructure_collection)
assert res == nb

def test_collection_rows_count_after_index_created_superstructure(self, connect, superstructure_collection, get_superstructure_index):
'''
target: test count_collection, after index have been created
method: add vectors in db, and create index, then calling count_collection with correct params
expected: count_collection raise exception
'''
nb = 100
index_type = get_superstructure_index["index_type"]
index_param = get_superstructure_index["index_param"]
tmp, vectors = gen_binary_vectors(nb, dim)
res = connect.add_vectors(collection_name=superstructure_collection, records=vectors)
connect.flush([superstructure_collection])
connect.create_index(superstructure_collection, index_type, index_param)
status, res = connect.count_collection(superstructure_collection)
assert res == nb

@pytest.mark.level(2)
def test_count_without_connection(self, ham_collection, dis_connect):
'''
Expand Down
Loading

0 comments on commit 21c7b8f

Please sign in to comment.