Ejemplo n.º 1
0
    def _blocking(self, request_iterator, timeout, metadata, credentials,
                  wait_for_ready, compression):
        deadline = _deadline(timeout)
        state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None)
        initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
            wait_for_ready)
        augmented_metadata = _compression.augment_metadata(
            metadata, compression)

        call = self._channel.segregated_call(
            cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method,
            None, _determine_deadline(deadline), augmented_metadata,
            None if credentials is None else credentials._credentials,
            _stream_unary_invocation_operationses_and_tags(
                augmented_metadata, initial_metadata_flags), self._context)
        _consume_request_iterator(request_iterator, state, call,
                                  self._request_serializer, None)
        while True:
            event = call.next_event()
            with state.condition:
                _handle_event(event, state, self._response_deserializer)
                state.condition.notify_all()
                if not state.due:
                    break
        return state, call
Ejemplo n.º 2
0
 def __call__(self,
              request_iterator,
              timeout=None,
              metadata=None,
              credentials=None,
              wait_for_ready=None,
              compression=None):
     deadline = _deadline(timeout)
     state = _RPCState(_STREAM_STREAM_INITIAL_DUE, None, None, None, None)
     initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
         wait_for_ready)
     augmented_metadata = _compression.augment_metadata(
         metadata, compression)
     operationses = (
         (
             cygrpc.SendInitialMetadataOperation(augmented_metadata,
                                                 initial_metadata_flags),
             cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),
         ),
         (cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS), ),
     )
     event_handler = _event_handler(state, self._response_deserializer)
     call = self._channel.managed_call(
         cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method,
         None, _determine_deadline(deadline), augmented_metadata,
         None if credentials is None else credentials._credentials,
         operationses, event_handler, self._context)
     _consume_request_iterator(request_iterator, state, call,
                               self._request_serializer, event_handler)
     return _MultiThreadedRendezvous(state, call,
                                     self._response_deserializer, deadline)
Ejemplo n.º 3
0
 def future(self,
            request_iterator,
            timeout=None,
            metadata=None,
            credentials=None,
            wait_for_ready=None,
            compression=None):
     deadline = _deadline(timeout)
     state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None)
     event_handler = _event_handler(state, self._response_deserializer)
     initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
         wait_for_ready)
     augmented_metadata = _compression.augment_metadata(
         metadata, compression)
     call = self._channel.managed_call(
         cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS, self._method,
         None, deadline, augmented_metadata,
         None if credentials is None else credentials._credentials,
         _stream_unary_invocation_operationses(metadata,
                                               initial_metadata_flags),
         event_handler, self._context)
     _consume_request_iterator(request_iterator, state, call,
                               self._request_serializer, event_handler)
     return _MultiThreadedRendezvous(state, call,
                                     self._response_deserializer, deadline)
Ejemplo n.º 4
0
    def _make_grpc_error(self, status_code):
        from grpc._channel import _Rendezvous
        from grpc._channel import _RPCState

        details = 'Some error details.'
        exc_state = _RPCState((), None, None, status_code, details)
        return _Rendezvous(exc_state, None, None, None)
Ejemplo n.º 5
0
    def _make_grpc_error(status_code, trailing=None):
        from grpc._channel import _RPCState
        from google.cloud.exceptions import GrpcRendezvous

        details = 'Some error details.'
        exc_state = _RPCState((), None, trailing, status_code, details)
        return GrpcRendezvous(exc_state, None, None, None)
Ejemplo n.º 6
0
    def _make_grpc_error(self, status_code):
        from grpc._channel import _Rendezvous
        from grpc._channel import _RPCState

        details = 'Some error details.'
        exc_state = _RPCState((), None, None, status_code, details)
        return _Rendezvous(exc_state, None, None, None)
Ejemplo n.º 7
0
 def __call__(self,
              request_iterator,
              timeout=None,
              metadata=None,
              credentials=None):
     deadline, deadline_timespec = _deadline(timeout)
     state = _RPCState(_STREAM_STREAM_INITIAL_DUE, None, None, None, None)
     channel = self._channel.get_channel()
     call, drive_call = channel.managed_call(None, 0, self._method, None,
                                             deadline_timespec)
     if credentials is not None:
         call.set_credentials(credentials._credentials)
     event_handler = _event_handler(state, call,
                                    self._response_deserializer)
     with state.condition:
         call.start_client_batch(
             cygrpc.Operations(
                 (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),
                  )), event_handler)
         operations = (
             cygrpc.operation_send_initial_metadata(
                 _common.to_cygrpc_metadata(metadata), _EMPTY_FLAGS),
             cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
         )
         call_error = call.start_client_batch(cygrpc.Operations(operations),
                                              event_handler)
         if call_error != cygrpc.CallError.ok:
             _call_error_set_RPCstate(state, call_error, metadata)
             return _Rendezvous(state, None, None, deadline)
         drive_call()
         _consume_request_iterator(request_iterator, state, call,
                                   self._request_serializer)
     return _Rendezvous(state, call, self._response_deserializer, deadline)
Ejemplo n.º 8
0
 def _blocking(self, channel, request_iterator, timeout, metadata,
               credentials):
     deadline, deadline_timespec = _deadline(timeout)
     state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None)
     completion_queue = cygrpc.CompletionQueue()
     call = channel.create_call(None, 0, completion_queue, self._method,
                                None, deadline_timespec)
     if credentials is not None:
         call.set_credentials(credentials._credentials)
     with state.condition:
         call.start_client_batch(
             cygrpc.Operations(
                 (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),
                  )), None)
         operations = (
             cygrpc.operation_send_initial_metadata(
                 _common.to_cygrpc_metadata(metadata), _EMPTY_FLAGS),
             cygrpc.operation_receive_message(_EMPTY_FLAGS),
             cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
         )
         call_error = call.start_client_batch(cygrpc.Operations(operations),
                                              None)
         _check_call_error(call_error, metadata)
         _consume_request_iterator(request_iterator, state, call,
                                   self._request_serializer)
     while True:
         event = completion_queue.poll()
         with state.condition:
             _handle_event(event, state, self._response_deserializer)
             state.condition.notify_all()
             if not state.due:
                 break
     return state, call, deadline
Ejemplo n.º 9
0
    def _make_grpc_error(self, status_code):
        from grpc._channel import _RPCState
        from google.cloud.exceptions import GrpcRendezvous

        details = 'Some error details.'
        exc_state = _RPCState((), None, None, status_code, details)
        return GrpcRendezvous(exc_state, None, None, None)
Ejemplo n.º 10
0
    def test_commit_failure_cancelled(self):
        from grpc import StatusCode
        from grpc._channel import _Rendezvous
        from grpc._channel import _RPCState

        exc_state = _RPCState((), None, None, StatusCode.CANCELLED, None)
        exc = _Rendezvous(exc_state, None, None, None)
        self._commit_failure_helper(exc, _Rendezvous)
Ejemplo n.º 11
0
    def test_commit_failure_cancelled(self):
        from grpc import StatusCode
        from grpc._channel import _Rendezvous
        from grpc._channel import _RPCState

        exc_state = _RPCState((), None, None, StatusCode.CANCELLED, None)
        exc = _Rendezvous(exc_state, None, None, None)
        self._commit_failure_helper(exc, _Rendezvous)
Ejemplo n.º 12
0
    def test_commit_failure_cancelled(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import GrpcRendezvous

        exc_state = _RPCState((), None, None, StatusCode.CANCELLED, None)
        exc = GrpcRendezvous(exc_state, None, None, None)
        self._commit_failure_helper(exc, GrpcRendezvous)
Ejemplo n.º 13
0
    def test_commit_failure_cancelled(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import GrpcRendezvous

        exc_state = _RPCState((), None, None, StatusCode.CANCELLED, None)
        exc = GrpcRendezvous(exc_state, None, None, None)
        self._commit_failure_helper(exc, GrpcRendezvous)
Ejemplo n.º 14
0
    def _test_not_found(self):
        error = _Rendezvous(_RPCState((), '', '', StatusCode.NOT_FOUND, ""),
                            None, None, None)
        self.cdnskey_client.mock.side_effect = error

        response = self.client.get(
            reverse('webwhois:scan_results', kwargs={'handle': self.domain}))

        self.assertContains(response, 'not found', status_code=404)
Ejemplo n.º 15
0
    def test_commit_failure_aborted(self):
        from grpc import StatusCode
        from grpc._channel import _Rendezvous
        from grpc._channel import _RPCState
        from gcloud.exceptions import Conflict

        details = 'Bad things.'
        exc_state = _RPCState((), None, None, StatusCode.ABORTED, details)
        exc = _Rendezvous(exc_state, None, None, None)
        self._commit_failure_helper(exc, Conflict)
Ejemplo n.º 16
0
    def test_failure_cancelled(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import GrpcRendezvous

        exc_state = _RPCState((), None, None, StatusCode.CANCELLED, None)
        exc = GrpcRendezvous(exc_state, None, None, None)
        with self.assertRaises(GrpcRendezvous):
            with self._call_fut():
                self._fake_method(exc)
Ejemplo n.º 17
0
    def test_commit_failure_aborted(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import Conflict
        from google.cloud.exceptions import GrpcRendezvous

        details = 'Bad things.'
        exc_state = _RPCState((), None, None, StatusCode.ABORTED, details)
        exc = GrpcRendezvous(exc_state, None, None, None)
        self._commit_failure_helper(exc, Conflict)
Ejemplo n.º 18
0
    def test_with_stable(self):
        from grpc._channel import _Rendezvous
        from grpc._channel import _RPCState
        from grpc import StatusCode

        status_code = StatusCode.FAILED_PRECONDITION
        exc_state = _RPCState((), None, None, status_code, None)
        exc = _Rendezvous(exc_state, None, None, None)
        result = self._callFUT(exc)
        self.assertEqual(result, status_code)
Ejemplo n.º 19
0
    def test_failure_cancelled(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import GrpcRendezvous

        exc_state = _RPCState((), None, None, StatusCode.CANCELLED, None)
        exc = GrpcRendezvous(exc_state, None, None, None)
        with self.assertRaises(GrpcRendezvous):
            with self._call_fut():
                self._fake_method(exc)
Ejemplo n.º 20
0
    def test_with_stable(self):
        from grpc._channel import _Rendezvous
        from grpc._channel import _RPCState
        from grpc import StatusCode

        status_code = StatusCode.FAILED_PRECONDITION
        exc_state = _RPCState((), None, None, status_code, None)
        exc = _Rendezvous(exc_state, None, None, None)
        result = self._callFUT(exc)
        self.assertEqual(result, status_code)
Ejemplo n.º 21
0
    def _make_grpc_error(self, status_code=None):
        from grpc._channel import _RPCState
        from grpc import StatusCode
        from google.cloud.exceptions import GrpcRendezvous

        if status_code is None:
            status_code = StatusCode.UNKNOWN

        details = 'Some error details.'
        exc_state = _RPCState((), None, None, status_code, details)
        return GrpcRendezvous(exc_state, None, None, None)
Ejemplo n.º 22
0
    def test_commit_failure_invalid_argument(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import BadRequest
        from google.cloud.exceptions import GrpcRendezvous

        details = 'Too long content.'
        exc_state = _RPCState((), None, None, StatusCode.INVALID_ARGUMENT,
                              details)
        exc = GrpcRendezvous(exc_state, None, None, None)
        self._commit_failure_helper(exc, BadRequest)
Ejemplo n.º 23
0
    def test_run_query_invalid_argument(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import BadRequest
        from google.cloud.exceptions import GrpcRendezvous

        details = ('Cannot have inequality filters on multiple '
                   'properties: [created, priority]')
        exc_state = _RPCState((), None, None, StatusCode.INVALID_ARGUMENT,
                              details)
        exc = GrpcRendezvous(exc_state, None, None, None)
        self._run_query_failure_helper(exc, BadRequest)
Ejemplo n.º 24
0
    def test_run_query_invalid_argument(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import BadRequest
        from google.cloud.exceptions import GrpcRendezvous

        details = ('Cannot have inequality filters on multiple '
                   'properties: [created, priority]')
        exc_state = _RPCState((), None, None,
                              StatusCode.INVALID_ARGUMENT, details)
        exc = GrpcRendezvous(exc_state, None, None, None)
        self._run_query_failure_helper(exc, BadRequest)
Ejemplo n.º 25
0
    def test_failure_aborted(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import Conflict
        from google.cloud.exceptions import GrpcRendezvous

        details = 'Bad things.'
        exc_state = _RPCState((), None, None, StatusCode.ABORTED, details)
        exc = GrpcRendezvous(exc_state, None, None, None)
        with self.assertRaises(Conflict):
            with self._call_fut():
                self._fake_method(exc)
Ejemplo n.º 26
0
    def test_failure_aborted(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import Conflict
        from google.cloud.exceptions import GrpcRendezvous

        details = 'Bad things.'
        exc_state = _RPCState((), None, None, StatusCode.ABORTED, details)
        exc = GrpcRendezvous(exc_state, None, None, None)
        with self.assertRaises(Conflict):
            with self._call_fut():
                self._fake_method(exc)
Ejemplo n.º 27
0
    def test_failure_invalid_argument(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import BadRequest
        from google.cloud.exceptions import GrpcRendezvous

        details = ('Cannot have inequality filters on multiple '
                   'properties: [created, priority]')
        exc_state = _RPCState((), None, None, StatusCode.INVALID_ARGUMENT,
                              details)
        exc = GrpcRendezvous(exc_state, None, None, None)
        with self.assertRaises(BadRequest):
            with self._call_fut():
                self._fake_method(exc)
Ejemplo n.º 28
0
    def test_failure_invalid_argument(self):
        from grpc import StatusCode
        from grpc._channel import _RPCState
        from google.cloud.exceptions import BadRequest
        from google.cloud.exceptions import GrpcRendezvous

        details = ('Cannot have inequality filters on multiple '
                   'properties: [created, priority]')
        exc_state = _RPCState((), None, None,
                              StatusCode.INVALID_ARGUMENT, details)
        exc = GrpcRendezvous(exc_state, None, None, None)
        with self.assertRaises(BadRequest):
            with self._call_fut():
                self._fake_method(exc)
Ejemplo n.º 29
0
 def _prepare(self, request, timeout, metadata):
     deadline, deadline_timespec, serialized_request, rendezvous = (
         _start_unary_request(request, timeout, self._request_serializer))
     if serialized_request is None:
         return None, None, None, None, rendezvous
     else:
         state = _RPCState(_UNARY_UNARY_INITIAL_DUE, None, None, None, None)
         operations = (
             cygrpc.operation_send_initial_metadata(
                 _common.to_cygrpc_metadata(metadata), _EMPTY_FLAGS),
             cygrpc.operation_send_message(serialized_request,
                                           _EMPTY_FLAGS),
             cygrpc.operation_send_close_from_client(_EMPTY_FLAGS),
             cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),
             cygrpc.operation_receive_message(_EMPTY_FLAGS),
             cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),
         )
         return state, operations, deadline, deadline_timespec, None
    def _test_raw_scan_results_error(self, status: StatusCode,
                                     error_cls: Type[Exception],
                                     error_msg: str) -> None:
        domain = 'example.org'
        error = _Rendezvous(_RPCState((), '', '', status, ""), None, None,
                            None)
        self.client.mock.side_effect = error

        with self.assertRaisesRegex(error_cls, error_msg):
            self.client.raw_scan_results(domain)

        request = RawScanResultsRequest()
        request.domain_fqdn.value = domain
        self.assertEqual(self.client.mock.mock_calls, [
            call(request,
                 method='/CdnskeyProcessor.Api.Report.Report/raw_scan_results',
                 timeout=None)
        ])
Ejemplo n.º 31
0
    def __call__(self,
                 request,
                 timeout=None,
                 metadata=None,
                 credentials=None,
                 wait_for_ready=None,
                 compression=None):
        deadline, serialized_request, rendezvous = _start_unary_request(
            request, timeout, self._request_serializer)
        initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
            wait_for_ready)
        if serialized_request is None:
            raise rendezvous
        else:
            augmented_metadata = _compression.augment_metadata(
                metadata, compression)
            state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None,
                              None)
            operationses = (
                (
                    cygrpc.SendInitialMetadataOperation(
                        augmented_metadata, initial_metadata_flags),
                    cygrpc.SendMessageOperation(serialized_request,
                                                _EMPTY_FLAGS),
                    cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS),
                    cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),
                ),
                (cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS), ),
            )

            call = self._channel.managed_call(
                cygrpc.PropagationConstants.GRPC_PROPAGATE_DEFAULTS,
                self._method, None, _determine_deadline(deadline), metadata,
                None if credentials is None else credentials._credentials,
                operationses, _event_handler(state,
                                             self._response_deserializer),
                self._context)
            return _MultiThreadedRendezvous(state, call,
                                            self._response_deserializer,
                                            deadline)
Ejemplo n.º 32
0
 def _prepare(self, request, timeout, metadata, wait_for_ready,
              compression):
     deadline, serialized_request, rendezvous = _start_unary_request(
         request, timeout, self._request_serializer)
     initial_metadata_flags = _InitialMetadataFlags().with_wait_for_ready(
         wait_for_ready)
     augmented_metadata = _compression.augment_metadata(
         metadata, compression)
     if serialized_request is None:
         return None, None, None, rendezvous
     else:
         state = _RPCState(_UNARY_UNARY_INITIAL_DUE, None, None, None, None)
         operations = (
             cygrpc.SendInitialMetadataOperation(augmented_metadata,
                                                 initial_metadata_flags),
             cygrpc.SendMessageOperation(serialized_request, _EMPTY_FLAGS),
             cygrpc.SendCloseFromClientOperation(_EMPTY_FLAGS),
             cygrpc.ReceiveInitialMetadataOperation(_EMPTY_FLAGS),
             cygrpc.ReceiveMessageOperation(_EMPTY_FLAGS),
             cygrpc.ReceiveStatusOnClientOperation(_EMPTY_FLAGS),
         )
         return state, operations, deadline, None
Ejemplo n.º 33
0
def _make_rendezvous(status_code, details):
    from grpc import _channel
    from google.cloud import exceptions

    exc_state = _channel._RPCState((), None, None, status_code, details)
    return exceptions.GrpcRendezvous(exc_state, None, None, None)
Ejemplo n.º 34
0
    def _make_rendezvous(status_code, details):
        from grpc._channel import _RPCState
        from google.cloud.exceptions import GrpcRendezvous

        exc_state = _RPCState((), None, None, status_code, details)
        return GrpcRendezvous(exc_state, None, None, None)