예제 #1
0
    def test_pull(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = pubsub_pb2.PullResponse(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = subscriber_client.SubscriberClient()

        # Setup Request
        subscription = client.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
        max_messages = 496131527

        response = client.pull(subscription, max_messages)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.PullRequest(
            subscription=subscription, max_messages=max_messages
        )
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
예제 #2
0
 def StreamingPull(
     self,
     request_iterator: Iterator[pubsub_pb2.StreamingPullRequest],
     context: grpc.ServicerContext,
 ):  # noqa: D403
     """StreamingPull implementation."""
     for request in request_iterator:
         self.logger.debug("StreamingPull(%.100s)", LazyFormat(request))
         if request.ack_ids:
             self.Acknowledge(
                 pubsub_pb2.AcknowledgeRequest(
                     subscription=request.subscription, ack_ids=request.ack_ids
                 ),
                 context,
             )
         if request.modify_deadline_seconds:
             for ack_id, seconds in zip(
                 request.modify_deadline_ack_ids, request.modify_deadline_seconds
             ):
                 self.ModifyAckDeadline(
                     pubsub_pb2.ModifyAckDeadlineRequest(
                         subscription=request.subscription,
                         ack_ids=[ack_id],
                         seconds=seconds,
                     ),
                     context,
                 )
         yield pubsub_pb2.StreamingPullResponse(
             received_messages=self.Pull(
                 pubsub_pb2.PullRequest(
                     subscription=request.subscription, max_messages=100
                 ),
                 context,
             ).received_messages
         )
예제 #3
0
 def pull(self,
          batch_size) -> typing.Tuple[typing.List[dict], typing.List[str]]:
     request = pubsub_pb2.PullRequest(subscription=self.subscription,
                                      max_messages=batch_size,
                                      return_immediately=True)
     response = self.client.api._pull(request)
     return self._open_pull_envelope(response)
    def test_pull(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = pubsub_pb2.PullResponse(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = subscriber_client.SubscriberClient(channel=channel)

        # Setup Request
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')
        max_messages = 496131527

        response = client.pull(subscription, max_messages)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.PullRequest(subscription=subscription,
                                                  max_messages=max_messages)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request