def setUp(self):
    self.controller = TestStreamServiceController(
        EventsReader(expected_key=[('full', EXPECTED_KEY)]))
    self.controller.start()

    channel = grpc.insecure_channel(self.controller.endpoint)
    self.stub = beam_runner_api_pb2_grpc.TestStreamServiceStub(channel)
    def _stream_events_from_rpc(endpoint, output_tags, coder, channel,
                                is_alive):
        """Yields the events received from the given endpoint.

    This is the producer thread that reads events from the TestStreamService and
    puts them onto the shared queue. At the end of the stream, an _EndOfStream
    is placed on the channel to signify a successful end.
    """
        stub_channel = grpc.insecure_channel(endpoint)
        stub = beam_runner_api_pb2_grpc.TestStreamServiceStub(stub_channel)

        # Request the PCollections that we are looking for from the service.
        event_request = beam_runner_api_pb2.EventsRequest(
            output_ids=[str(tag) for tag in output_tags])

        event_stream = stub.Events(event_request)
        try:
            for e in event_stream:
                channel.put(_TestStream.test_stream_payload_to_events(
                    e, coder))
                if not is_alive():
                    return
        except grpc.RpcError as e:
            # Do not raise an exception in the non-error status codes. These can occur
            # when the Python interpreter shuts down or when in a notebook environment
            # when the kernel is interrupted.
            if e.code() in (grpc.StatusCode.CANCELLED,
                            grpc.StatusCode.UNAVAILABLE):
                return
            raise e
        finally:
            # Gracefully stop the job if there is an exception.
            channel.put(_EndOfStream())
Esempio n. 3
0
  def events_from_rpc(endpoint, output_tags, coder):
    """Yields the events received from the given endpoint.
    """
    stub_channel = grpc.insecure_channel(endpoint)
    stub = beam_runner_api_pb2_grpc.TestStreamServiceStub(stub_channel)

    # Request the PCollections that we are looking for from the service.
    event_request = beam_runner_api_pb2.EventsRequest(
        output_ids=[str(tag) for tag in output_tags])

    event_stream = stub.Events(event_request)
    for e in event_stream:
      yield _TestStream.test_stream_payload_to_events(e, coder)
    def _stream_events_from_rpc(endpoint, output_tags, coder, channel,
                                is_alive):
        """Yields the events received from the given endpoint.

    This is the producer thread that reads events from the TestStreamService and
    puts them onto the shared queue. At the end of the stream, an _EndOfStream
    is placed on the channel to signify a successful end.
    """
        stub_channel = grpc.insecure_channel(endpoint)
        stub = beam_runner_api_pb2_grpc.TestStreamServiceStub(stub_channel)

        # Request the PCollections that we are looking for from the service.
        event_request = beam_runner_api_pb2.EventsRequest(
            output_ids=[str(tag) for tag in output_tags])

        event_stream = stub.Events(event_request)
        for e in event_stream:
            channel.put(_TestStream.test_stream_payload_to_events(e, coder))
            if not is_alive():
                return
        channel.put(_EndOfStream())
Esempio n. 5
0
    def events_from_rpc(endpoint, output_tags, coder):
        """Yields the events received from the given endpoint.
    """
        stub_channel = grpc.insecure_channel(endpoint)
        stub = beam_runner_api_pb2_grpc.TestStreamServiceStub(stub_channel)

        # Request the PCollections that we are looking for from the service.
        event_request = beam_runner_api_pb2.EventsRequest(
            output_ids=[str(tag) for tag in output_tags])

        event_stream = stub.Events(event_request, timeout=30)
        try:
            while True:
                yield _TestStream.test_stream_payload_to_events(
                    next(event_stream), coder)
        except StopIteration:
            return
        except grpc.RpcError as e:
            if e.code() == grpc.StatusCode.DEADLINE_EXCEEDED:
                _LOGGER.warning(
                    'TestStream timed out waiting for new events from service.'
                    ' Stopping pipeline.')
                return
            raise e
    def setUp(self):
        self.controller = TestStreamServiceController(self.events())
        self.controller.start()

        channel = grpc.insecure_channel(self.controller.endpoint)
        self.stub = beam_runner_api_pb2_grpc.TestStreamServiceStub(channel)