Exemplo n.º 1
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
         )
    def test_modify_ack_deadline(self):
        channel = ChannelStub()
        client = subscriber_client.SubscriberClient(channel=channel)

        # Setup Request
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')
        ack_ids = []
        ack_deadline_seconds = 2135351438

        client.modify_ack_deadline(subscription, ack_ids, ack_deadline_seconds)

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.ModifyAckDeadlineRequest(
            subscription=subscription,
            ack_ids=ack_ids,
            ack_deadline_seconds=ack_deadline_seconds)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemplo n.º 3
0
    def test_modify_ack_deadline(self):
        channel = ChannelStub()
        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]')
        ack_ids = []
        ack_deadline_seconds = 2135351438

        client.modify_ack_deadline(subscription, ack_ids, ack_deadline_seconds)

        assert len(channel.requests) == 1
        expected_request = pubsub_pb2.ModifyAckDeadlineRequest(
            subscription=subscription,
            ack_ids=ack_ids,
            ack_deadline_seconds=ack_deadline_seconds)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request