test_collection_count.py 25.6 KB
Newer Older
X
Xiaohai Xu 已提交
1
import pdb
2
import copy
X
Xiaohai Xu 已提交
3 4 5 6 7
import logging
import itertools
from time import sleep
import threading
from multiprocessing import Process
8 9 10
import sklearn.preprocessing

import pytest
X
Xiaohai Xu 已提交
11 12 13
from utils import *

nb = 6000
14 15 16 17 18 19 20 21 22 23 24
dim = 128
tag = "tag"
collection_id = "count_collection"
add_interval_time = 3
segment_size = 10
default_fields = gen_default_fields() 
entities = gen_entities(nb)
raw_vectors, binary_entities = gen_binary_entities(nb)
field_name = "fload_vector"
index_name = "index_name"

X
Xiaohai Xu 已提交
25 26 27 28 29 30 31 32 33 34

class TestCollectionCount:
    """
    params means different nb, the nb value may trigger merge, or not
    """
    @pytest.fixture(
        scope="function",
        params=[
            1,
            5000,
35
            6001
X
Xiaohai Xu 已提交
36 37
        ],
    )
38
    def insert_count(self, request):
X
Xiaohai Xu 已提交
39 40 41 42 43 44 45 46 47 48 49
        yield request.param

    """
    generate valid create_index params
    """
    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
    def get_simple_index(self, request, connect):
        if str(connect._cmd("mode")[1]) == "CPU":
50
            if request.param["index_type"] in index_cpu_not_support():
X
Xiaohai Xu 已提交
51 52 53
                pytest.skip("sq8h not support in cpu mode")
        return request.param

54
    def test_collection_count(self, connect, collection, insert_count):
X
Xiaohai Xu 已提交
55 56 57
        '''
        target: test collection rows_count is correct or not
        method: create collection and add vectors in it,
D
del-zhenwu 已提交
58
            assert the value returned by count_entities method is equal to length of vectors
X
Xiaohai Xu 已提交
59 60
        expected: the count is equal to the length of vectors
        '''
61 62
        entities = gen_entities(insert_count)
        res = connect.insert(collection, entities)
X
Xiaohai Xu 已提交
63
        connect.flush([collection])
64 65
        res = connect.count_entities(collection)
        assert res == insert_count
X
Xiaohai Xu 已提交
66

67
    def test_collection_count_partition(self, connect, collection, insert_count):
X
Xiaohai Xu 已提交
68 69 70
        '''
        target: test collection rows_count is correct or not
        method: create collection, create partition and add vectors in it,
D
del-zhenwu 已提交
71
            assert the value returned by count_entities method is equal to length of vectors
X
Xiaohai Xu 已提交
72 73
        expected: the count is equal to the length of vectors
        '''
74 75 76
        entities = gen_entities(insert_count)
        connect.create_partition(collection, tag)
        res_ids = connect.insert(collection, entities, partition_tag=tag)
X
Xiaohai Xu 已提交
77
        connect.flush([collection])
78 79
        res = connect.count_entities(collection)
        assert res == insert_count
X
Xiaohai Xu 已提交
80

81
    def test_collection_count_multi_partitions_A(self, connect, collection, insert_count):
X
Xiaohai Xu 已提交
82 83
        '''
        target: test collection rows_count is correct or not
84 85 86
        method: create collection, create partitions and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
X
Xiaohai Xu 已提交
87 88
        '''
        new_tag = "new_tag"
89 90 91 92
        entities = gen_entities(insert_count)
        connect.create_partition(collection, tag)
        connect.create_partition(collection, new_tag)
        res_ids = connect.insert(collection, entities)
X
Xiaohai Xu 已提交
93
        connect.flush([collection])
94 95
        res = connect.count_entities(collection)
        assert res == insert_count
X
Xiaohai Xu 已提交
96

97
    def test_collection_count_multi_partitions_B(self, connect, collection, insert_count):
X
Xiaohai Xu 已提交
98 99
        '''
        target: test collection rows_count is correct or not
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
        '''
        new_tag = "new_tag"
        entities = gen_entities(insert_count)
        connect.create_partition(collection, tag)
        connect.create_partition(collection, new_tag)
        res_ids = connect.insert(collection, entities, partition_tag=tag)
        connect.flush([collection])
        res = connect.count_entities(collection)
        assert res == insert_count

    def test_collection_count_multi_partitions_C(self, connect, collection, insert_count):
        '''
        target: test collection rows_count is correct or not
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
X
Xiaohai Xu 已提交
118 119 120
        expected: the count is equal to the length of vectors
        '''
        new_tag = "new_tag"
121 122 123 124 125
        entities = gen_entities(insert_count)
        connect.create_partition(collection, tag)
        connect.create_partition(collection, new_tag)
        res_ids = connect.insert(collection, entities)
        res_ids_2 = connect.insert(collection, entities, partition_tag=tag)
X
Xiaohai Xu 已提交
126
        connect.flush([collection])
127 128
        res = connect.count_entities(collection)
        assert res == insert_count * 2
X
Xiaohai Xu 已提交
129

130
    def test_collection_count_multi_partitions_D(self, connect, collection, insert_count):
X
Xiaohai Xu 已提交
131 132
        '''
        target: test collection rows_count is correct or not
133 134 135
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
        expected: the collection count is equal to the length of entities
X
Xiaohai Xu 已提交
136 137
        '''
        new_tag = "new_tag"
138 139 140 141 142
        entities = gen_entities(insert_count)
        connect.create_partition(collection, tag)
        connect.create_partition(collection, new_tag)
        res_ids = connect.insert(collection, entities, partition_tag=tag)
        res_ids2 = connect.insert(collection, entities, partition_tag=new_tag)
X
Xiaohai Xu 已提交
143
        connect.flush([collection])
144 145
        res = connect.count_entities(collection)
        assert res == insert_count * 2
X
Xiaohai Xu 已提交
146

147
    def _test_collection_count_after_index_created(self, connect, collection, get_simple_index, insert_count):
X
Xiaohai Xu 已提交
148
        '''
D
del-zhenwu 已提交
149 150 151
        target: test count_entities, after index have been created
        method: add vectors in db, and create index, then calling count_entities with correct params 
        expected: count_entities raise exception
X
Xiaohai Xu 已提交
152
        '''
153 154
        entities = gen_entities(insert_count)
        res = connect.insert(collection, entities)
X
Xiaohai Xu 已提交
155
        connect.flush([collection])
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
        connect.create_index(collection, field_name, index_name, get_simple_index)
        res = connect.count_entities(collection)
        assert res == insert_count

    @pytest.mark.level(2)
    def test_count_without_connection(self, collection, dis_connect):
        '''
        target: test count_entities, without connection
        method: calling count_entities with correct params, with a disconnected instance
        expected: count_entities raise exception
        '''
        with pytest.raises(Exception) as e:
            dis_connect.count_entities(collection)

    def test_collection_count_no_vectors(self, connect, collection):
X
Xiaohai Xu 已提交
171 172 173
        '''
        target: test collection rows_count is correct or not, if collection is empty
        method: create collection and no vectors in it,
D
del-zhenwu 已提交
174
            assert the value returned by count_entities method is equal to 0
X
Xiaohai Xu 已提交
175
        expected: the count is equal to 0
176 177
        '''    
        res = connect.count_entities(collection)
X
Xiaohai Xu 已提交
178 179 180 181 182 183 184 185 186 187 188 189
        assert res == 0


class TestCollectionCountIP:
    """
    params means different nb, the nb value may trigger merge, or not
    """
    @pytest.fixture(
        scope="function",
        params=[
            1,
            5000,
190
            6001
X
Xiaohai Xu 已提交
191 192
        ],
    )
193
    def insert_count(self, request):
X
Xiaohai Xu 已提交
194 195 196 197 198 199 200 201 202 203 204
        yield request.param

    """
    generate valid create_index params
    """
    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
    def get_simple_index(self, request, connect):
        if str(connect._cmd("mode")[1]) == "CPU":
205 206
            if request.param["index_type"] in index_cpu_not_support():
                pytest.skip("sq8h not support in cpu mode")
X
Xiaohai Xu 已提交
207 208
        return request.param

209
    def test_collection_count(self, connect, ip_collection, insert_count):
X
Xiaohai Xu 已提交
210 211
        '''
        target: test collection rows_count is correct or not
212 213 214
        method: create collection and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
X
Xiaohai Xu 已提交
215
        '''
216 217
        entities = gen_entities(insert_count)
        res = connect.insert(ip_collection, entities)
X
Xiaohai Xu 已提交
218
        connect.flush([ip_collection])
219 220
        res = connect.count_entities(ip_collection)
        assert res == insert_count
X
Xiaohai Xu 已提交
221

222
    def test_collection_count_partition(self, connect, ip_collection, insert_count):
X
Xiaohai Xu 已提交
223
        '''
224 225 226 227
        target: test collection rows_count is correct or not
        method: create collection, create partition and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
X
Xiaohai Xu 已提交
228
        '''
229 230 231
        entities = gen_entities(insert_count)
        connect.create_partition(ip_collection, tag)
        res_ids = connect.insert(ip_collection, entities, partition_tag=tag)
X
Xiaohai Xu 已提交
232
        connect.flush([ip_collection])
233 234 235 236
        res = connect.count_entities(ip_collection)
        assert res == insert_count

    def test_collection_count_multi_partitions_A(self, connect, ip_collection, insert_count):
X
Xiaohai Xu 已提交
237
        '''
238 239 240 241
        target: test collection rows_count is correct or not
        method: create collection, create partitions and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
X
Xiaohai Xu 已提交
242
        '''
243 244 245 246 247 248 249 250
        new_tag = "new_tag"
        entities = gen_entities(insert_count)
        connect.create_partition(ip_collection, tag)
        connect.create_partition(ip_collection, new_tag)
        res_ids = connect.insert(ip_collection, entities)
        connect.flush([ip_collection])
        res = connect.count_entities(ip_collection)
        assert res == insert_count
X
Xiaohai Xu 已提交
251

252
    def test_collection_count_multi_partitions_B(self, connect, ip_collection, insert_count):
X
Xiaohai Xu 已提交
253
        '''
254 255 256 257
        target: test collection rows_count is correct or not
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
X
Xiaohai Xu 已提交
258
        '''
259 260 261 262 263 264 265 266
        new_tag = "new_tag"
        entities = gen_entities(insert_count)
        connect.create_partition(ip_collection, tag)
        connect.create_partition(ip_collection, new_tag)
        res_ids = connect.insert(ip_collection, entities, partition_tag=tag)
        connect.flush([ip_collection])
        res = connect.count_entities(ip_collection)
        assert res == insert_count
X
Xiaohai Xu 已提交
267

268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
    def test_collection_count_multi_partitions_C(self, connect, ip_collection, insert_count):
        '''
        target: test collection rows_count is correct or not
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
        '''
        new_tag = "new_tag"
        entities = gen_entities(insert_count)
        connect.create_partition(ip_collection, tag)
        connect.create_partition(ip_collection, new_tag)
        res_ids = connect.insert(ip_collection, entities)
        res_ids_2 = connect.insert(ip_collection, entities, partition_tag=tag)
        connect.flush([ip_collection])
        res = connect.count_entities(ip_collection)
        assert res == insert_count * 2
X
Xiaohai Xu 已提交
284

285
    def test_collection_count_multi_partitions_D(self, connect, ip_collection, insert_count):
X
Xiaohai Xu 已提交
286 287
        '''
        target: test collection rows_count is correct or not
288 289 290
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
        expected: the collection count is equal to the length of entities
X
Xiaohai Xu 已提交
291
        '''
292 293 294 295 296 297 298 299 300
        new_tag = "new_tag"
        entities = gen_entities(insert_count)
        connect.create_partition(ip_collection, tag)
        connect.create_partition(ip_collection, new_tag)
        res_ids = connect.insert(ip_collection, entities, partition_tag=tag)
        res_ids2 = connect.insert(ip_collection, entities, partition_tag=new_tag)
        connect.flush([ip_collection])
        res = connect.count_entities(ip_collection)
        assert res == insert_count * 2
X
Xiaohai Xu 已提交
301

302
    def _test_collection_count_after_index_created(self, connect, ip_collection, get_simple_index, insert_count):
X
Xiaohai Xu 已提交
303
        '''
D
del-zhenwu 已提交
304
        target: test count_entities, after index have been created
305
        method: add vectors in db, and create index, then calling count_entities with correct params 
D
del-zhenwu 已提交
306
        expected: count_entities raise exception
X
Xiaohai Xu 已提交
307
        '''
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
        entities = gen_entities(insert_count)
        res = connect.insert(ip_collection, entities)
        connect.flush([ip_collection])
        connect.create_index(ip_collection, field_name, index_name, get_simple_index)
        res = connect.count_entities(ip_collection)
        assert res == insert_count

    @pytest.mark.level(2)
    def test_count_without_connection(self, ip_collection, dis_connect):
        '''
        target: test count_entities, without connection
        method: calling count_entities with correct params, with a disconnected instance
        expected: count_entities raise exception
        '''
        with pytest.raises(Exception) as e:
            dis_connect.count_entities(ip_collection)

    def test_collection_count_no_entities(self, connect, ip_collection):
X
Xiaohai Xu 已提交
326 327 328
        '''
        target: test collection rows_count is correct or not, if collection is empty
        method: create collection and no vectors in it,
D
del-zhenwu 已提交
329
            assert the value returned by count_entities method is equal to 0
X
Xiaohai Xu 已提交
330
        expected: the count is equal to 0
331 332
        '''    
        res = connect.count_entities(ip_collection)
X
Xiaohai Xu 已提交
333 334 335
        assert res == 0


D
del-zhenwu 已提交
336
class TestCollectionCountBinary:
X
Xiaohai Xu 已提交
337 338 339 340 341 342 343 344
    """
    params means different nb, the nb value may trigger merge, or not
    """
    @pytest.fixture(
        scope="function",
        params=[
            1,
            5000,
345
            6001
X
Xiaohai Xu 已提交
346 347
        ],
    )
348
    def insert_count(self, request):
X
Xiaohai Xu 已提交
349 350 351 352 353 354 355
        yield request.param

    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
    def get_hamming_index(self, request, connect):
356
        if request.param["index_type"] in binary_support():
X
Xiaohai Xu 已提交
357 358
            return request.param
        else:
359
            pytest.skip("Skip index")
X
Xiaohai Xu 已提交
360

D
del-zhenwu 已提交
361 362 363 364 365
    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
    def get_substructure_index(self, request, connect):
366
        if request.param["index_type"] == "FLAT":
D
del-zhenwu 已提交
367 368
            return request.param
        else:
369
            pytest.skip("Skip index")
D
del-zhenwu 已提交
370 371 372 373 374 375

    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
    def get_superstructure_index(self, request, connect):
376
        if request.param["index_type"] == "FLAT":
D
del-zhenwu 已提交
377 378
            return request.param
        else:
379
            pytest.skip("Skip index")
D
del-zhenwu 已提交
380

381
    def test_collection_count(self, connect, jac_collection, insert_count):
X
Xiaohai Xu 已提交
382 383
        '''
        target: test collection rows_count is correct or not
384 385 386
        method: create collection and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
X
Xiaohai Xu 已提交
387
        '''
388 389 390 391 392 393
        raw_vectors, entities = gen_binary_entities(insert_count)
        res = connect.insert(jac_collection, entities)
        logging.getLogger().info(len(res))
        connect.flush([jac_collection])
        res = connect.count_entities(jac_collection)
        assert res == insert_count
X
Xiaohai Xu 已提交
394

395
    def test_collection_count_partition(self, connect, jac_collection, insert_count):
D
del-zhenwu 已提交
396 397
        '''
        target: test collection rows_count is correct or not
398 399 400
        method: create collection, create partition and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
D
del-zhenwu 已提交
401
        '''
402 403 404 405 406 407
        raw_vectors, entities = gen_binary_entities(insert_count)
        connect.create_partition(jac_collection, tag)
        res_ids = connect.insert(jac_collection, entities, partition_tag=tag)
        connect.flush([jac_collection])
        res = connect.count_entities(jac_collection)
        assert res == insert_count
D
del-zhenwu 已提交
408

409 410
    @pytest.mark.level(2)
    def test_collection_count_multi_partitions_A(self, connect, jac_collection, insert_count):
D
del-zhenwu 已提交
411 412
        '''
        target: test collection rows_count is correct or not
413 414 415
        method: create collection, create partitions and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
D
del-zhenwu 已提交
416
        '''
417 418 419 420 421 422 423 424
        new_tag = "new_tag"
        raw_vectors, entities = gen_binary_entities(insert_count)
        connect.create_partition(jac_collection, tag)
        connect.create_partition(jac_collection, new_tag)
        res_ids = connect.insert(jac_collection, entities)
        connect.flush([jac_collection])
        res = connect.count_entities(jac_collection)
        assert res == insert_count
D
del-zhenwu 已提交
425

426 427
    @pytest.mark.level(2)
    def test_collection_count_multi_partitions_B(self, connect, jac_collection, insert_count):
X
Xiaohai Xu 已提交
428
        '''
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
        target: test collection rows_count is correct or not
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
        '''
        new_tag = "new_tag"
        raw_vectors, entities = gen_binary_entities(insert_count)
        connect.create_partition(jac_collection, tag)
        connect.create_partition(jac_collection, new_tag)
        res_ids = connect.insert(jac_collection, entities, partition_tag=tag)
        connect.flush([jac_collection])
        res = connect.count_entities(jac_collection)
        assert res == insert_count

    def test_collection_count_multi_partitions_C(self, connect, jac_collection, insert_count):
X
Xiaohai Xu 已提交
444
        '''
445 446 447 448 449 450 451 452 453 454 455 456 457 458
        target: test collection rows_count is correct or not
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
        '''
        new_tag = "new_tag"
        raw_vectors, entities = gen_binary_entities(insert_count)
        connect.create_partition(jac_collection, tag)
        connect.create_partition(jac_collection, new_tag)
        res_ids = connect.insert(jac_collection, entities)
        res_ids_2 = connect.insert(jac_collection, entities, partition_tag=tag)
        connect.flush([jac_collection])
        res = connect.count_entities(jac_collection)
        assert res == insert_count * 2
X
Xiaohai Xu 已提交
459

460 461
    @pytest.mark.level(2)
    def test_collection_count_multi_partitions_D(self, connect, jac_collection, insert_count):
D
del-zhenwu 已提交
462
        '''
463 464 465 466
        target: test collection rows_count is correct or not
        method: create collection, create partitions and add entities in one of the partitions,
            assert the value returned by count_entities method is equal to length of entities
        expected: the collection count is equal to the length of entities
D
del-zhenwu 已提交
467
        '''
468 469 470 471 472 473 474 475 476
        new_tag = "new_tag"
        raw_vectors, entities = gen_binary_entities(insert_count)
        connect.create_partition(jac_collection, tag)
        connect.create_partition(jac_collection, new_tag)
        res_ids = connect.insert(jac_collection, entities, partition_tag=tag)
        res_ids2 = connect.insert(jac_collection, entities, partition_tag=new_tag)
        connect.flush([jac_collection])
        res = connect.count_entities(jac_collection)
        assert res == insert_count * 2
D
del-zhenwu 已提交
477

478
    def _test_collection_count_after_index_created(self, connect, jac_collection, get_simple_index, insert_count):
D
del-zhenwu 已提交
479
        '''
D
del-zhenwu 已提交
480
        target: test count_entities, after index have been created
481
        method: add vectors in db, and create index, then calling count_entities with correct params 
D
del-zhenwu 已提交
482
        expected: count_entities raise exception
D
del-zhenwu 已提交
483
        '''
484 485 486 487 488 489 490 491
        raw_vectors, entities = gen_binary_entities(insert_count)
        res = connect.insert(jac_collection, entities)
        connect.flush([jac_collection])
        connect.create_index(jac_collection, field_name, index_name, get_simple_index)
        res = connect.count_entities(jac_collection)
        assert res == insert_count

    def test_collection_count_no_entities(self, connect, jac_collection):
X
Xiaohai Xu 已提交
492 493 494
        '''
        target: test collection rows_count is correct or not, if collection is empty
        method: create collection and no vectors in it,
D
del-zhenwu 已提交
495
            assert the value returned by count_entities method is equal to 0
X
Xiaohai Xu 已提交
496
        expected: the count is equal to 0
497 498
        '''    
        res = connect.count_entities(jac_collection)
X
Xiaohai Xu 已提交
499 500 501
        assert res == 0


502
class TestCollectionMultiCollections:
X
Xiaohai Xu 已提交
503 504 505 506 507 508 509 510
    """
    params means different nb, the nb value may trigger merge, or not
    """
    @pytest.fixture(
        scope="function",
        params=[
            1,
            5000,
511
            6001
X
Xiaohai Xu 已提交
512 513
        ],
    )
514
    def insert_count(self, request):
X
Xiaohai Xu 已提交
515
        yield request.param
516 517 518 519 520 521 522 523 524 525
        
    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
    def get_hamming_index(self, request, connect):
        if request.param["index_type"] in binary_support():
            return request.param
        else:
            pytest.skip("Skip index")
X
Xiaohai Xu 已提交
526

527 528 529 530 531 532 533 534 535
    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
    def get_substructure_index(self, request, connect):
        if request.param["index_type"] == "FLAT":
            return request.param
        else:
            pytest.skip("Skip index")
X
Xiaohai Xu 已提交
536 537 538 539 540

    @pytest.fixture(
        scope="function",
        params=gen_simple_index()
    )
541 542
    def get_superstructure_index(self, request, connect):
        if request.param["index_type"] == "FLAT":
X
Xiaohai Xu 已提交
543 544
            return request.param
        else:
545
            pytest.skip("Skip index")
X
Xiaohai Xu 已提交
546

547
    def test_collection_count_multi_collections_l2(self, connect, insert_count):
X
Xiaohai Xu 已提交
548
        '''
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
        target: test collection rows_count is correct or not with multiple collections of L2
        method: create collection and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
        '''
        entities = gen_entities(insert_count)
        collection_list = []
        collection_num = 20
        for i in range(collection_num):
            collection_name = gen_unique_str(collection_id)
            collection_list.append(collection_name)
            connect.create_collection(collection_name, default_fields)
            res = connect.insert(collection_name, entities)
        connect.flush(collection_list)
        for i in range(collection_num):
            res = connect.count_entities(collection_list[i])
            assert res == insert_count

    def test_collection_count_multi_collections_binary(self, connect, jac_collection, insert_count):
X
Xiaohai Xu 已提交
568
        '''
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
        target: test collection rows_count is correct or not with multiple collections of JACCARD
        method: create collection and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
        '''
        raw_vectors, entities = gen_binary_entities(insert_count)
        res = connect.insert(jac_collection, entities)
        # logging.getLogger().info(entities)
        collection_list = []
        collection_num = 20
        for i in range(collection_num):
            collection_name = gen_unique_str(collection_id)
            collection_list.append(collection_name)
            fields = update_fields_metric_type(default_fields, "JACCARD")
            connect.create_collection(collection_name, fields)
            res = connect.insert(collection_name, entities)
        connect.flush(collection_list)
        for i in range(collection_num):
            res = connect.count_entities(collection_list[i])
            assert res == insert_count

    def test_collection_count_multi_collections_mix(self, connect):
        '''
        target: test collection rows_count is correct or not with multiple collections of JACCARD
        method: create collection and add entities in it,
            assert the value returned by count_entities method is equal to length of entities
        expected: the count is equal to the length of entities
        '''
        collection_list = []
        collection_num = 20
        for i in range(0, int(collection_num / 2)):
            collection_name = gen_unique_str(collection_id)
            collection_list.append(collection_name)
            connect.create_collection(collection_name, default_fields)
            res = connect.insert(collection_name, entities)
        for i in range(int(collection_num / 2), collection_num):
            collection_name = gen_unique_str(collection_id)
            collection_list.append(collection_name)
            fields = update_fields_metric_type(default_fields, "JACCARD")
            connect.create_collection(collection_name, fields)
            res = connect.insert(collection_name, binary_entities)
        connect.flush(collection_list)
        for i in range(collection_num):
            res = connect.count_entities(collection_list[i])
            assert res == nb