Example #1
0
    def result(self, timeout):
        """Analogous to `grpc.Future.result`. Returns the value or exception.

        This method will wait until the full set of gRPC requests is complete
        and then act as `grpc.Future.result` for the single gRPC invocation
        corresponding to the first successful call or final failure, as
        appropriate.

        Args:
          timeout: How long to wait in seconds before giving up and raising.

        Returns:
          The result of the future corresponding to the single gRPC
          corresponding to the successful call.

        Raises:
          * `grpc.FutureTimeoutError` if timeout seconds elapse before the gRPC
          calls could complete, including waits and retries.
          * The exception corresponding to the last non-retryable gRPC request
          in the case that a successful gRPC request was not made.
        """
        if not self._completion_event.wait(timeout):
            raise grpc.FutureTimeoutError(
                f"AsyncCallFuture timed out after {timeout} seconds"
            )
        with self._active_grpc_future_lock:
            if self._active_grpc_future is None:
                raise RuntimeError("AsyncFuture never had an active future set")
            return self._active_grpc_future.result()
    def test_create_collection_exception(self, connect, hvcollection, dim):
        vectors = records_factory(dim, 1)
        integers = integer_factory(1)

        entities = [{
            "name": "Vec",
            "values": vectors
        }, {
            "name": "Int",
            "values": integers
        }]

        mock_grpc_timeout = mock.MagicMock(
            side_effect=grpc.FutureTimeoutError())
        with mock.patch.object(Uum, 'future', mock_grpc_timeout):
            with pytest.raises(grpc.FutureTimeoutError):
                connect.bulk_insert(hvcollection, entities)

        mock_grpc_error = mock.MagicMock(side_effect=MockGrpcError())
        with mock.patch.object(Uum, 'future', mock_grpc_error):
            with pytest.raises(grpc.RpcError):
                connect.bulk_insert(hvcollection, entities)

        mock_exception = mock.MagicMock(side_effect=Exception("error"))
        with mock.patch.object(Uum, 'future', mock_exception):
            with pytest.raises(Exception):
                connect.bulk_insert(hvcollection, entities)
Example #3
0
    def test_create_collection_exception(self, connect):
        collection_name = collection_name_factory()
        collection_param = {
            "fields": [{
                "name": "v",
                "type": DataType.FLOAT_VECTOR,
                "params": {
                    "dim": 128
                }
            }],
            "segment_row_limit":
            10000,
            "auto_id":
            False
        }

        mock_grpc_timeout = mock.MagicMock(
            side_effect=grpc.FutureTimeoutError())
        with mock.patch.object(Uum, 'future', mock_grpc_timeout):
            with pytest.raises(grpc.FutureTimeoutError):
                connect.create_collection(collection_name, collection_param)

        mock_grpc_error = mock.MagicMock(side_effect=MockGrpcError())
        with mock.patch.object(Uum, 'future', mock_grpc_error):
            with pytest.raises(grpc.RpcError):
                connect.create_collection(collection_name, collection_param)

        mock_exception = mock.MagicMock(side_effect=Exception("error"))
        with mock.patch.object(Uum, 'future', mock_exception):
            with pytest.raises(Exception):
                connect.create_collection(collection_name, collection_param)
Example #4
0
def _wait_once_until(condition, until):
    if until is None:
        condition.wait()
    else:
        remaining = until - time.time()
        if remaining < 0:
            raise grpc.FutureTimeoutError()
        else:
            condition.wait(timeout=remaining)
Example #5
0
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()
Example #6
0
 def _block(self, timeout):
     until = None if timeout is None else time.time() + timeout
     with self._condition:
         while True:
             if self._cancelled:
                 raise grpc.FutureCancelledError()
             elif self._matured:
                 return
             else:
                 if until is None:
                     self._condition.wait()
                 else:
                     remaining = until - time.time()
                     if remaining < 0:
                         raise grpc.FutureTimeoutError()
                     else:
                         self._condition.wait(timeout=remaining)
Example #7
0
    def exception(self, timeout=None):
        """Return the exception raised by the computation.

        See grpc.Future.exception for the full API contract.
        """
        with self._state.condition:
            timed_out = _common.wait(
                self._state.condition.wait, self._is_complete, timeout=timeout)
            if timed_out:
                raise grpc.FutureTimeoutError()
            else:
                if self._state.code is grpc.StatusCode.OK:
                    return None
                elif self._state.cancelled:
                    raise grpc.FutureCancelledError()
                else:
                    return self
Example #8
0
    def result(self, timeout=None):
        """Returns the result of the computation or raises its exception.

        See grpc.Future.result for the full API contract.
        """
        with self._state.condition:
            timed_out = _common.wait(
                self._state.condition.wait, self._is_complete, timeout=timeout)
            if timed_out:
                raise grpc.FutureTimeoutError()
            else:
                if self._state.code is grpc.StatusCode.OK:
                    return self._state.response
                elif self._state.cancelled:
                    raise grpc.FutureCancelledError()
                else:
                    raise self
Example #9
0
    def test_insert_with_exception(self, connect, hvcollection, dim):
        insert_entities = [{"Int": 10, "Vec": records_factory(dim, 1)[0]}]

        mock_grpc_timeout = mock.MagicMock(side_effect=grpc.FutureTimeoutError())
        with mock.patch.object(Uum, 'future', mock_grpc_timeout):
            with pytest.raises(grpc.FutureTimeoutError):
                connect.insert(hvcollection, insert_entities)

        mock_grpc_error = mock.MagicMock(side_effect=MockGrpcError())
        with mock.patch.object(Uum, 'future', mock_grpc_error):
            with pytest.raises(grpc.RpcError):
                connect.insert(hvcollection, insert_entities)

        mock_exception = mock.MagicMock(side_effect=Exception("error"))
        with mock.patch.object(Uum, 'future', mock_exception):
            with pytest.raises(Exception):
                connect.insert(hvcollection, insert_entities)
Example #10
0
    def traceback(self, timeout=None):
        """Access the traceback of the exception raised by the computation.

        See grpc.future.traceback for the full API contract.
        """
        with self._state.condition:
            timed_out = _common.wait(
                self._state.condition.wait, self._is_complete, timeout=timeout)
            if timed_out:
                raise grpc.FutureTimeoutError()
            else:
                if self._state.code is grpc.StatusCode.OK:
                    return None
                elif self._state.cancelled:
                    raise grpc.FutureCancelledError()
                else:
                    try:
                        raise self
                    except grpc.RpcError:
                        return sys.exc_info()[2]
Example #11
0
    def test_create_collection_exception(self, gcon):
        collection_param = {
            "collection_name": "test_create_collection_exceptions",
            "dimension": 128,
            "metric_type": MetricType.L2,
            "index_file_size": 10
        }

        mock_grpc_timeout = mock.MagicMock(side_effect=grpc.FutureTimeoutError())
        with mock.patch.object(Uum, 'future', mock_grpc_timeout):
            status = gcon.create_collection(collection_param)
            assert not status.OK()

        mock_grpc_error = mock.MagicMock(side_effect=MockGrpcError())
        with mock.patch.object(Uum, 'future', mock_grpc_error):
            status = gcon.create_collection(collection_param)
            assert not status.OK()

        mock_exception = mock.MagicMock(side_effect=Exception("error"))
        with mock.patch.object(Uum, 'future', mock_exception):
            status = gcon.create_collection(collection_param)
            assert not status.OK()