def test_disconnected(self, gip): cnn = GrpcMilvus() cnn.connect(*gip) assert cnn.disconnect().OK() assert not cnn.connected() cnn.connect(*gip) assert cnn.connected()
class TestSearchVectorsInFilesException: client = GrpcMilvus() table_name = "aaa" records = [[random.random() for _ in range(16)] for _ in range(10)] @mock.patch.object(GrpcMilvus, "connected") def test_search_vectors_in_files_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.search_vectors_in_files(self.table_name, ["1"], self.records, 1) @mock.patch.object(FC, "__call__") def test_search_vectors_rpcerror_exp(self, mock_callable, gip): mock_callable.side_effect = RpcTestError() self.client.connect(*gip) status, _ = \ self.client.search_vectors_in_files(self.table_name, ["1"], self.records, 1, async_=True) assert not status.OK()
class TestHastableException: client = GrpcMilvus() @mock.patch.object(GrpcMilvus, "connected") def test_has_table_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.has_table("aaa") @mock.patch.object(FC, "future") def test_has_table_timeout_exp(self, mock_callable, gip): mock_callable.side_effect = FError() self.client.connect(*gip) status, _ = self.client.has_table("a123") assert not status.OK() @mock.patch.object(FC, "future") def test_has_table_rpcerror_exp(self, mock_callable, gip): mock_callable.side_effect = RpcTestError() self.client.connect(*gip) status, _ = self.client.has_table("a123") assert not status.OK()
class TestChannel: client = GrpcMilvus() def test_channel_host_port(self): try: self.client.set_channel(host="localhost", port="19530") self.client.set_channel(host="www.milvus.io", port="19530") except Exception: assert False def test_channel_uri(self): try: self.client.set_channel(uri="tcp://192.168.1.1:9999") except Exception: assert False def test_channel_host_non_port(self): try: self.client.set_channel(host="localhost") except Exception: assert False def test_channel_only_port(self): with pytest.raises(ParamError): self.client.set_channel(port=9999)
class TestCreateIndexException: client = GrpcMilvus() def test_create_index_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client.create_index("aaa") def test_create_index_timeout_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.CreateIndex = future self.client._stub = stub status = self.client.create_index("a123", timeout=10) assert not status.OK() def test_create_index_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.CreateIndex = future self.client._stub = stub status = self.client.create_index("a123", timeout=10) assert not status.OK()
class TestDropTableException: client = GrpcMilvus() def test_drop_table_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client.drop_table("aaa") def test_drop_table_timeout_exp(self, gip): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.DropTable = future self.client._stub = stub status = self.client.drop_table("a123") assert not status.OK() def test_drop_table_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.DropTable = future self.client._stub = stub status = self.client.drop_table("a123") assert not status.OK()
class TestDeleteByRangeException: client = GrpcMilvus() table_name = "test_table_name" def test_delete_by_range_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client._GrpcMilvus__delete_vectors_by_range( self.table_name, start_date="2010-01-01", end_date="2099-12-31") def test_delete_by_range_timeout_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.DeleteByDate = future self.client._stub = stub status = self.client._GrpcMilvus__delete_vectors_by_range( self.table_name, start_date="2010-01-01", end_date="2099-12-31") assert not status.OK() def test_delete_by_range_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.DeleteByDate = future self.client._stub = stub status = self.client._GrpcMilvus__delete_vectors_by_range( self.table_name, start_date="2010-01-01", end_date="2099-12-31") assert not status.OK()
class TestAddVectorsException: client = GrpcMilvus() table_name = "aaa" records = [[random.random() for _ in range(16)] for _ in range(10)] @mock.patch.object(GrpcMilvus, "connected") def test_add_vectors_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.add_vectors(self.table_name, self.records) @mock.patch.object(FC, "future") def test_add_vectors_timeout_exp(self, mock_callable, gip): mock_callable.side_effect = FError() self.client.connect(*gip) status, _ = self.client.add_vectors(self.table_name, self.records) assert not status.OK() @mock.patch.object(FC, "future") def test_add_vectors_rpcerror_exp(self, mock_callable, gip): mock_callable.side_effect = RpcTestError() self.client.connect(*gip) status, _ = self.client.add_vectors(self.table_name, self.records) assert not status.OK()
class TestCreateTableException: client = GrpcMilvus() table_param = {"table_name": "test001", "dimension": 16} @mock.patch.object(GrpcMilvus, "connected") def test_create_table_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.create_table({}) def test_create_table_timeout_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.CreateTable = future self.client._stub = stub status = self.client.create_table(self.table_param) assert not status.OK() def test_create_table_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.CreateTable = future self.client._stub = stub status = self.client.create_table(self.table_param) assert not status.OK()
class TestGetTableRowCountException: client = GrpcMilvus() table_name = "test_table_name" @mock.patch.object(GrpcMilvus, "connected") def test_get_table_row_count_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.get_table_row_count(self.table_name) @mock.patch.object(FC, "future") def test_get_table_row_count_timeout_exp(self, mock_callable, gip): mock_callable.side_effect = FError() self.client.connect(*gip) status, _ = self.client.get_table_row_count(self.table_name) assert not status.OK() @mock.patch.object(FC, "future") def test_sget_table_row_count_rpcerror_exp(self, mock_callable, gip): mock_callable.side_effect = RpcTestError() self.client.connect(*gip) status, _ = self.client.get_table_row_count(self.table_name) assert not status.OK()
class TestCmdException: client = GrpcMilvus() cmd_str = "OK" @mock.patch.object(GrpcMilvus, "connected") def test__cmd_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client._cmd(self.cmd_str) @mock.patch.object(FC, "future") def test__cmd_count_timeout_exp(self, mock_callable, gip): mock_callable.side_effect = FError() self.client.connect(*gip) status, _ = self.client._cmd(self.cmd_str) assert not status.OK() @mock.patch.object(FC, "future") def test__cmd_rpcerror_exp(self, mock_callable, gip): mock_callable.side_effect = RpcTestError() self.client.connect(*gip) status, _ = self.client._cmd(self.cmd_str) assert not status.OK()
class TestCreateIndexException: client = GrpcMilvus() @mock.patch.object(GrpcMilvus, "connected") def test_create_index_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.create_index("aaa") @mock.patch.object(FC, "future") def test_create_index_timeout_exp(self, mock_callable, gip): mock_callable.side_effect = FError() self.client.connect(*gip) status = self.client.create_index("a123", timeout=10) assert not status.OK() @mock.patch.object(FC, "future") def test_create_index_rpcerror_exp(self, mock_callable, gip): mock_callable.side_effect = RpcTestError() self.client.connect(*gip) status = self.client.create_index("a123", timeout=10) assert not status.OK()
class TestDropIndexException: client = GrpcMilvus() table_name = "test_table_name" @mock.patch.object(GrpcMilvus, "connected") def test_drop_index_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.drop_index(self.table_name) @mock.patch.object(FC, "future") def test_drop_index_timeout_exp(self, mock_callable, gip): mock_callable.side_effect = FError() self.client.connect(*gip) status = self.client.drop_index(self.table_name) assert not status.OK() @mock.patch.object(FC, "future") def test_drop_index_rpcerror_exp(self, mock_callable, gip): mock_callable.side_effect = RpcTestError() self.client.connect(*gip) status = self.client.drop_index(self.table_name) assert not status.OK()
class TestDropPartitionException: client = GrpcMilvus() table_name = "test_table_name" def test_drop_partition_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client.drop_partition(self.table_name, "tag") def test_drop_partition_timeout_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.DropPartition = future self.client._stub = stub status = self.client.drop_partition(self.table_name, 'tag') assert not status.OK() def test_drop_partition_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.DropPartition = future self.client._stub = stub status = self.client.drop_partition(self.table_name, "tag") assert not status.OK()
class TestDescribeIndexException: client = GrpcMilvus() table_name = "test_table_name" def test_describe_index_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client.describe_index(self.table_name) def test_desribe_index_timeout_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.DescribeIndex = future self.client._stub = stub status, _ = self.client.describe_index(self.table_name) assert not status.OK() def test_describe_index_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.DescribeIndex = future self.client._stub = stub status, _ = self.client.describe_index(self.table_name) assert not status.OK()
class TestPreloadTableException: client = GrpcMilvus() table_name = "test_table_name" def test_preload_table_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client.preload_table(self.table_name) def test_preload_table_timeout_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.PreloadTable = future self.client._stub = stub status = self.client.preload_table(self.table_name) assert not status.OK() def test_preload_table_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.PreloadTable = future self.client._stub = stub status = self.client.preload_table(self.table_name) assert not status.OK()
class TestCmdException: client = GrpcMilvus() cmd_str = "OK" def test__cmd_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client._cmd(self.cmd_str) def test__cmd_count_timeout_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.Cmd = future self.client._stub = stub status, _ = self.client._cmd(self.cmd_str) assert not status.OK() def test__cmd_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.Cmd = future self.client._stub = stub status, _ = self.client._cmd(self.cmd_str) assert not status.OK()
class TestDisconnectException: client = GrpcMilvus() @mock.patch.object(GrpcMilvus, "connected") def test_disconnect_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.disconnect()
def test_true_connect(self, gip): cnn = GrpcMilvus() cnn.connect(*gip) assert cnn.status.OK assert cnn.connected() # Repeating connect _ = cnn.connect(*gip) status = cnn.connect() assert status == Status.CONNECT_FAILED
class TestConnectException: client = GrpcMilvus() @mock.patch("grpc.channel_ready_future", side_effect=grpc.FutureTimeoutError()) def test_connect_timeout_exp(self, _): with pytest.raises(NotConnectError): self.client.connect() @mock.patch("grpc.channel_ready_future", side_effect=grpc.RpcError()) def test_connect_grpc_exp(self, _): with pytest.raises(NotConnectError): self.client.connect()
def test_false_connect(self): cnn = GrpcMilvus() with pytest.raises(NotConnectError): cnn.connect(uri='tcp://127.0.0.1:7987', timeout=2) LOGGER.error(cnn.status) assert not cnn.status.OK() with pytest.raises(NotConnectError): cnn.connect(uri='tcp://123.0.0.1:19530', timeout=2) LOGGER.error(cnn.status) assert not cnn.status.OK()
class TestSearchVectorsException: client = GrpcMilvus() table_name = "aaa" records = [[random.random() for _ in range(16)] for _ in range(10)] def test_search_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client.search(self.table_name, 1, 1, self.records) def test_search_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() stub.Search = mock.Mock(side_effect=RpcTestError()) self.client._stub = stub status, _ = self.client.search(self.table_name, 1, 1, self.records) assert not status.OK()
class TestCreateTableException: client = GrpcMilvus() table_param = {"table_name": "test001", "dimension": 16} @mock.patch.object(GrpcMilvus, "connected") def test_create_table_not_connect_exp(self, mock_client): mock_client.return_value = False with pytest.raises(NotConnectError): self.client.disconnect() @mock.patch.object(FC, "future") def test_create_table_rpcerror_exp(self, mock_callable, gip): mock_callable.side_effect = RpcTestError() self.client.connect(*gip) status = self.client.create_table(self.table_param) assert not status.OK()
class TestInsertException: client = GrpcMilvus() table_name = "aaa" records = [[random.random() for _ in range(16)] for _ in range(10)] def test_insert_not_connect_exp(self): self.client.connected = mock.Mock(return_value=False) with pytest.raises(NotConnectError): self.client.insert(self.table_name, self.records) def test_insert_timeout_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=FError()) stub.Insert = future self.client._stub = stub status, _ = self.client.insert(self.table_name, self.records, timeout=1) assert not status.OK() def test_insert_rpcerror_exp(self): self.client.connected = mock.Mock(return_value=True) stub = FakeStub() future = FakeFuture() future.future = mock.Mock(side_effect=RpcTestError()) stub.Insert = future self.client._stub = stub status, _ = self.client.insert(self.table_name, self.records, timeout=1) assert not status.OK()
def test_uri_error(self, url): with pytest.raises(Exception): cnn = GrpcMilvus() cnn.connect(uri=url)
class TestConnectedException: client = GrpcMilvus() @mock.patch("grpc.channel_ready_future", side_effect=grpc.RpcError()) def test_connected_exp(self, mock_channel): assert not self.client.connected()
def test_uri(self, gip): cnn = GrpcMilvus() uri = 'tcp://{}:{}'.format(gip[0], gip[1]) cnn.connect(uri=uri) assert cnn.status.OK()
def test_host_port_error(self, h, p): with pytest.raises(Exception): GrpcMilvus().connect(host=h, port=p)
def test_disconnected_error(self): cnn = GrpcMilvus() with pytest.raises(NotConnectError): cnn.disconnect()
def test_not_connect(self): client = GrpcMilvus() with pytest.raises(NotConnectError): client.create_table({}) with pytest.raises(NotConnectError): client.has_table("a") with pytest.raises(NotConnectError): client.describe_table("a") with pytest.raises(NotConnectError): client.drop_table("a") with pytest.raises(NotConnectError): client.create_index("a") with pytest.raises(NotConnectError): client.insert("a", [], None) with pytest.raises(NotConnectError): client.count_table("a") with pytest.raises(NotConnectError): client.show_tables() with pytest.raises(NotConnectError): client.search("a", 1, 2, []) with pytest.raises(NotConnectError): client.search_in_files("a", [], [], 2, 1) with pytest.raises(NotConnectError): client._cmd("") with pytest.raises(NotConnectError): client.preload_table("a") with pytest.raises(NotConnectError): client.describe_index("a") with pytest.raises(NotConnectError): client.drop_index("")